1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=simplifycfg -hoist-common-insts=true -S | FileCheck %s
3 ; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -hoist-common-insts=true -S | FileCheck %s
5 define void @foo(i1 %C, ptr %P) {
7 ; CHECK-NEXT: common.ret:
8 ; CHECK-NEXT: store i32 7, ptr [[P:%.*]], align 4
11 br i1 %C, label %T, label %F
20 define void @foo_switch(i64 %C, ptr %P) {
21 ; CHECK-LABEL: @foo_switch(
22 ; CHECK-NEXT: common.ret:
23 ; CHECK-NEXT: store i32 7, ptr [[P:%.*]], align 4
24 ; CHECK-NEXT: ret void
26 switch i64 %C, label %bb0 [
41 define float @PR39535min(float %x) {
42 ; CHECK-LABEL: @PR39535min(
44 ; CHECK-NEXT: [[TOBOOL:%.*]] = fcmp une float [[X:%.*]], 0.000000e+00
45 ; CHECK-NEXT: [[DOTX:%.*]] = select fast i1 [[TOBOOL]], float 0.000000e+00, float [[X]]
46 ; CHECK-NEXT: ret float [[DOTX]]
49 %tobool = fcmp une float %x, 0.0
50 br i1 %tobool, label %cond.true, label %cond.false
59 %cond = phi fast float [ 0.0, %cond.true ], [ %x, %cond.false ]
63 define float @PR39535min_switch(i64 %i, float %x) {
64 ; CHECK-LABEL: @PR39535min_switch(
66 ; CHECK-NEXT: switch i64 [[I:%.*]], label [[END:%.*]] [
67 ; CHECK-NEXT: i64 1, label [[BB1:%.*]]
68 ; CHECK-NEXT: i64 2, label [[BB2:%.*]]
71 ; CHECK-NEXT: br label [[END]]
73 ; CHECK-NEXT: br label [[END]]
75 ; CHECK-NEXT: [[COND:%.*]] = phi fast float [ [[X:%.*]], [[BB1]] ], [ [[X]], [[BB2]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
76 ; CHECK-NEXT: ret float [[COND]]
79 switch i64 %i, label %bb0 [
94 %cond = phi fast float [ 0.0, %bb0 ], [ %x, %bb1 ], [ %x, %bb2 ]
98 define i32 @hoist_zext_flags_preserve(i1 %C, i8 %x) {
99 ; CHECK-LABEL: @hoist_zext_flags_preserve(
100 ; CHECK-NEXT: common.ret:
101 ; CHECK-NEXT: [[Z1:%.*]] = zext nneg i8 [[X:%.*]] to i32
102 ; CHECK-NEXT: ret i32 [[Z1]]
104 br i1 %C, label %T, label %F
106 %z1 = zext nneg i8 %x to i32
109 %z2 = zext nneg i8 %x to i32
113 define i32 @hoist_zext_flags_drop(i1 %C, i8 %x) {
114 ; CHECK-LABEL: @hoist_zext_flags_drop(
115 ; CHECK-NEXT: common.ret:
116 ; CHECK-NEXT: [[Z1:%.*]] = zext i8 [[X:%.*]] to i32
117 ; CHECK-NEXT: ret i32 [[Z1]]
119 br i1 %C, label %T, label %F
121 %z1 = zext nneg i8 %x to i32
124 %z2 = zext i8 %x to i32
129 define float @hoist_uitofp_flags_preserve(i1 %C, i8 %x) {
130 ; CHECK-LABEL: @hoist_uitofp_flags_preserve(
131 ; CHECK-NEXT: common.ret:
132 ; CHECK-NEXT: [[Z1:%.*]] = uitofp nneg i8 [[X:%.*]] to float
133 ; CHECK-NEXT: ret float [[Z1]]
135 br i1 %C, label %T, label %F
137 %z1 = uitofp nneg i8 %x to float
140 %z2 = uitofp nneg i8 %x to float
144 define float @hoist_uitofp_flags_drop(i1 %C, i8 %x) {
145 ; CHECK-LABEL: @hoist_uitofp_flags_drop(
146 ; CHECK-NEXT: common.ret:
147 ; CHECK-NEXT: [[Z1:%.*]] = uitofp i8 [[X:%.*]] to float
148 ; CHECK-NEXT: ret float [[Z1]]
150 br i1 %C, label %T, label %F
152 %z1 = uitofp nneg i8 %x to float
155 %z2 = uitofp i8 %x to float
159 define i32 @hoist_or_flags_preserve(i1 %C, i32 %x, i32 %y) {
160 ; CHECK-LABEL: @hoist_or_flags_preserve(
161 ; CHECK-NEXT: common.ret:
162 ; CHECK-NEXT: [[Z1:%.*]] = or disjoint i32 [[X:%.*]], [[Y:%.*]]
163 ; CHECK-NEXT: ret i32 [[Z1]]
165 br i1 %C, label %T, label %F
167 %z1 = or disjoint i32 %x, %y
170 %z2 = or disjoint i32 %x, %y
174 define i32 @hoist_or_flags_drop(i1 %C, i32 %x, i32 %y) {
175 ; CHECK-LABEL: @hoist_or_flags_drop(
176 ; CHECK-NEXT: common.ret:
177 ; CHECK-NEXT: [[Z1:%.*]] = or i32 [[X:%.*]], [[Y:%.*]]
178 ; CHECK-NEXT: ret i32 [[Z1]]
180 br i1 %C, label %T, label %F
185 %z2 = or disjoint i32 %x, %y
189 define i16 @hoist_trunc_flags_preserve(i1 %C, i32 %x) {
190 ; CHECK-LABEL: @hoist_trunc_flags_preserve(
191 ; CHECK-NEXT: common.ret:
192 ; CHECK-NEXT: [[Z1:%.*]] = trunc nuw nsw i32 [[X:%.*]] to i16
193 ; CHECK-NEXT: ret i16 [[Z1]]
195 br i1 %C, label %T, label %F
197 %z1 = trunc nsw nuw i32 %x to i16
200 %z2 = trunc nsw nuw i32 %x to i16
204 define i16 @hoist_trunc_flags_drop(i1 %C, i32 %x) {
205 ; CHECK-LABEL: @hoist_trunc_flags_drop(
206 ; CHECK-NEXT: common.ret:
207 ; CHECK-NEXT: [[Z1:%.*]] = trunc i32 [[X:%.*]] to i16
208 ; CHECK-NEXT: ret i16 [[Z1]]
210 br i1 %C, label %T, label %F
212 %z1 = trunc i32 %x to i16
215 %z2 = trunc nsw nuw i32 %x to i16
219 define ptr @hoist_gep_flags_both_nuw(i1 %C, ptr %p) {
220 ; CHECK-LABEL: @hoist_gep_flags_both_nuw(
221 ; CHECK-NEXT: common.ret:
222 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr nuw i8, ptr [[P:%.*]], i64 1
223 ; CHECK-NEXT: ret ptr [[GEP1]]
225 br i1 %C, label %T, label %F
227 %gep1 = getelementptr nuw i8, ptr %p, i64 1
230 %gep2 = getelementptr nuw i8, ptr %p, i64 1
234 define ptr @hoist_gep_flags_both_nusw(i1 %C, ptr %p) {
235 ; CHECK-LABEL: @hoist_gep_flags_both_nusw(
236 ; CHECK-NEXT: common.ret:
237 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr nusw i8, ptr [[P:%.*]], i64 1
238 ; CHECK-NEXT: ret ptr [[GEP1]]
240 br i1 %C, label %T, label %F
242 %gep1 = getelementptr nusw i8, ptr %p, i64 1
245 %gep2 = getelementptr nusw i8, ptr %p, i64 1
249 define ptr @hoist_gep_flags_intersect1(i1 %C, ptr %p) {
250 ; CHECK-LABEL: @hoist_gep_flags_intersect1(
251 ; CHECK-NEXT: common.ret:
252 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr nusw i8, ptr [[P:%.*]], i64 1
253 ; CHECK-NEXT: ret ptr [[GEP1]]
255 br i1 %C, label %T, label %F
257 %gep1 = getelementptr inbounds nuw i8, ptr %p, i64 1
260 %gep2 = getelementptr nusw i8, ptr %p, i64 1
264 define ptr @hoist_gep_flags_intersect2(i1 %C, ptr %p) {
265 ; CHECK-LABEL: @hoist_gep_flags_intersect2(
266 ; CHECK-NEXT: common.ret:
267 ; CHECK-NEXT: [[GEP1:%.*]] = getelementptr i8, ptr [[P:%.*]], i64 1
268 ; CHECK-NEXT: ret ptr [[GEP1]]
270 br i1 %C, label %T, label %F
272 %gep1 = getelementptr inbounds i8, ptr %p, i64 1
275 %gep2 = getelementptr nuw i8, ptr %p, i64 1