1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
2 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S | FileCheck %s
4 define void @hoist_range(i1 %c, ptr %p) {
5 ; CHECK-LABEL: @hoist_range(
7 ; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1, !range [[RNG0:![0-9]+]]
11 br i1 %c, label %then, label %else
13 %t = load i8, ptr %p, !range !0
16 %e = load i8, ptr %p, !range !1
22 define void @hoist_range_switch(i64 %i, ptr %p) {
23 ; CHECK-LABEL: @hoist_range_switch(
25 ; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1, !range [[RNG1:![0-9]+]]
26 ; CHECK-NEXT: ret void
28 switch i64 %i, label %bb0 [
33 %t = load i8, ptr %p, !range !0
36 %e = load i8, ptr %p, !range !1
39 %f = load i8, ptr %p, !range !3
45 define void @hoist_both_noundef(i1 %c, ptr %p) {
46 ; CHECK-LABEL: @hoist_both_noundef(
48 ; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1, !noundef [[META2:![0-9]+]]
49 ; CHECK-NEXT: ret void
52 br i1 %c, label %then, label %else
55 %t = load i8, ptr %p, !noundef !2
59 %e = load i8, ptr %p, !noundef !2
67 define void @hoist_both_noundef_switch(i64 %i, ptr %p) {
68 ; CHECK-LABEL: @hoist_both_noundef_switch(
70 ; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1, !noundef [[META2]]
71 ; CHECK-NEXT: ret void
73 switch i64 %i, label %bb0 [
78 %t = load i8, ptr %p, !noundef !2
81 %e = load i8, ptr %p, !noundef !2
84 %f = load i8, ptr %p, !noundef !2
90 define void @hoist_one_noundef(i1 %c, ptr %p) {
91 ; CHECK-LABEL: @hoist_one_noundef(
93 ; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1
94 ; CHECK-NEXT: ret void
97 br i1 %c, label %then, label %else
100 %t = load i8, ptr %p, !noundef !2
111 define void @hoist_one_noundef_switch(i64 %i, ptr %p) {
112 ; CHECK-LABEL: @hoist_one_noundef_switch(
114 ; CHECK-NEXT: [[T:%.*]] = load i8, ptr [[P:%.*]], align 1
115 ; CHECK-NEXT: ret void
117 switch i64 %i, label %bb0 [
122 %t = load i8, ptr %p, !noundef !2
128 %f = load i8, ptr %p, !noundef !2
134 define void @hoist_dereferenceable(i1 %c, ptr %p) {
135 ; CHECK-LABEL: @hoist_dereferenceable(
137 ; CHECK-NEXT: [[T:%.*]] = load ptr, ptr [[P:%.*]], align 8, !dereferenceable [[META3:![0-9]+]]
138 ; CHECK-NEXT: ret void
141 br i1 %c, label %then, label %else
143 %t = load ptr, ptr %p, !dereferenceable !{i64 10}
146 %e = load ptr, ptr %p, !dereferenceable !{i64 20}
152 define void @hoist_dereferenceable_switch(i64 %i, ptr %p) {
153 ; CHECK-LABEL: @hoist_dereferenceable_switch(
155 ; CHECK-NEXT: [[T:%.*]] = load ptr, ptr [[P:%.*]], align 8, !dereferenceable [[META3]]
156 ; CHECK-NEXT: ret void
158 switch i64 %i, label %bb0 [
163 %t = load ptr, ptr %p, !dereferenceable !{i64 10}
166 %e = load ptr, ptr %p, !dereferenceable !{i64 20}
169 %f = load ptr, ptr %p, !dereferenceable !{i64 30}
175 define void @hoist_dereferenceable_or_null(i1 %c, ptr %p) {
176 ; CHECK-LABEL: @hoist_dereferenceable_or_null(
178 ; CHECK-NEXT: [[T:%.*]] = load ptr, ptr [[P:%.*]], align 8, !dereferenceable_or_null [[META3]]
179 ; CHECK-NEXT: ret void
182 br i1 %c, label %then, label %else
184 %t = load ptr, ptr %p, !dereferenceable_or_null !{i64 20}
187 %e = load ptr, ptr %p, !dereferenceable_or_null !{i64 10}
193 define void @hoist_dereferenceable_or_null_switch(i64 %i, ptr %p) {
194 ; CHECK-LABEL: @hoist_dereferenceable_or_null_switch(
196 ; CHECK-NEXT: [[T:%.*]] = load ptr, ptr [[P:%.*]], align 8, !dereferenceable_or_null [[META3]]
197 ; CHECK-NEXT: ret void
199 switch i64 %i, label %bb0 [
204 %t = load ptr, ptr %p, !dereferenceable_or_null !{i64 20}
207 %e = load ptr, ptr %p, !dereferenceable_or_null !{i64 10}
210 %f = load ptr, ptr %p, !dereferenceable_or_null !{i64 30}
216 ; !range violation only returns poison, and is thus safe to speculate.
217 define i32 @speculate_range(i1 %c, ptr dereferenceable(8) align 8 %p) {
218 ; CHECK-LABEL: @speculate_range(
220 ; CHECK-NEXT: [[V:%.*]] = load i32, ptr [[P:%.*]], align 4, !range [[RNG4:![0-9]+]]
221 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[C:%.*]], i32 [[V]], i32 0
222 ; CHECK-NEXT: ret i32 [[SPEC_SELECT]]
225 br i1 %c, label %if, label %join
228 %v = load i32, ptr %p, !range !{i32 0, i32 10}
232 %phi = phi i32 [ %v, %if ], [ 0, %entry ]
236 ; !nonnull is safe to speculate, but !noundef is not, as the latter causes
237 ; immediate undefined behavior.
238 define ptr @speculate_nonnull(i1 %c, ptr dereferenceable(8) align 8 %p) {
239 ; CHECK-LABEL: @speculate_nonnull(
241 ; CHECK-NEXT: [[V:%.*]] = load ptr, ptr [[P:%.*]], align 8, !nonnull [[META2]]
242 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[C:%.*]], ptr [[V]], ptr null
243 ; CHECK-NEXT: ret ptr [[SPEC_SELECT]]
246 br i1 %c, label %if, label %join
249 %v = load ptr, ptr %p, !nonnull !{}, !noundef !{}
253 %phi = phi ptr [ %v, %if ], [ null, %entry ]
257 ; !align is safe to speculate, but !dereferenceable is not, as the latter causes
258 ; immediate undefined behavior.
259 define ptr @speculate_align(i1 %c, ptr dereferenceable(8) align 8 %p) {
260 ; CHECK-LABEL: @speculate_align(
262 ; CHECK-NEXT: [[V:%.*]] = load ptr, ptr [[P:%.*]], align 8, !align [[META5:![0-9]+]]
263 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[C:%.*]], ptr [[V]], ptr null
264 ; CHECK-NEXT: ret ptr [[SPEC_SELECT]]
267 br i1 %c, label %if, label %join
270 %v = load ptr, ptr %p, !align !{i64 4}, !dereferenceable !{i64 4}
274 %phi = phi ptr [ %v, %if ], [ null, %entry ]
278 define void @hoist_fpmath(i1 %c, double %x) {
279 ; CHECK-LABEL: @hoist_fpmath(
281 ; CHECK-NEXT: [[T:%.*]] = fadd double [[X:%.*]], 1.000000e+00, !fpmath [[META6:![0-9]+]]
282 ; CHECK-NEXT: ret void
285 br i1 %c, label %then, label %else
287 %t = fadd double %x, 1.0, !fpmath !{ float 2.5 }
290 %e = fadd double %x, 1.0, !fpmath !{ float 5.0 }
296 define void @hoist_fpmath_switch(i64 %i, double %x) {
297 ; CHECK-LABEL: @hoist_fpmath_switch(
299 ; CHECK-NEXT: [[T:%.*]] = fadd double [[X:%.*]], 1.000000e+00, !fpmath [[META6]]
300 ; CHECK-NEXT: ret void
302 switch i64 %i, label %bb0 [
307 %t = fadd double %x, 1.0, !fpmath !{ float 2.5 }
310 %e = fadd double %x, 1.0, !fpmath !{ float 5.0 }
313 %f = fadd double %x, 1.0, !fpmath !{ float 7.5 }
324 ; CHECK: [[RNG0]] = !{i8 0, i8 1, i8 3, i8 5}
325 ; CHECK: [[RNG1]] = !{i8 0, i8 1, i8 3, i8 5, i8 7, i8 9}
326 ; CHECK: [[META2]] = !{}
327 ; CHECK: [[META3]] = !{i64 10}
328 ; CHECK: [[RNG4]] = !{i32 0, i32 10}
329 ; CHECK: [[META5]] = !{i64 4}
330 ; CHECK: [[META6]] = !{float 2.500000e+00}