1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -simplifycfg-merge-cond-stores=true -simplifycfg-merge-cond-stores-aggressively=false -phi-node-folding-threshold=1 | FileCheck %s
4 target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
5 target triple = "armv7--linux-gnueabihf"
7 ; This is a bit reversal that has been run through the early optimizer (-mem2reg -passes=gvn -instcombine).
8 ; There should be no additional PHIs created at all. The store should be on its own in a predicated
9 ; block and there should be no PHIs.
11 define i32 @f(ptr %b) {
14 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[B:%.*]], align 4
15 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[TMP0]], 1
16 ; CHECK-NEXT: [[TOBOOL:%.*]] = icmp eq i32 [[AND]], 0
17 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP0]], -2147483648
18 ; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[TOBOOL]], i32 [[TMP0]], i32 [[OR]]
19 ; CHECK-NEXT: [[AND1:%.*]] = and i32 [[TMP1]], 2
20 ; CHECK-NEXT: [[TOBOOL2:%.*]] = icmp eq i32 [[AND1]], 0
21 ; CHECK-NEXT: [[OR4:%.*]] = or i32 [[TMP1]], 1073741824
22 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TOBOOL2]], i32 [[TMP1]], i32 [[OR4]]
23 ; CHECK-NEXT: [[TMP3:%.*]] = xor i1 [[TOBOOL]], true
24 ; CHECK-NEXT: [[TMP4:%.*]] = xor i1 [[TOBOOL2]], true
25 ; CHECK-NEXT: [[TMP5:%.*]] = or i1 [[TMP3]], [[TMP4]]
26 ; CHECK-NEXT: [[AND6:%.*]] = and i32 [[TMP2]], 4
27 ; CHECK-NEXT: [[TOBOOL7:%.*]] = icmp eq i32 [[AND6]], 0
28 ; CHECK-NEXT: [[OR9:%.*]] = or i32 [[TMP2]], 536870912
29 ; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[TOBOOL7]], i32 [[TMP2]], i32 [[OR9]]
30 ; CHECK-NEXT: [[TMP6:%.*]] = xor i1 [[TMP5]], true
31 ; CHECK-NEXT: [[TMP7:%.*]] = xor i1 [[TOBOOL7]], true
32 ; CHECK-NEXT: [[TMP8:%.*]] = xor i1 [[TMP6]], true
33 ; CHECK-NEXT: [[TMP9:%.*]] = or i1 [[TMP8]], [[TMP7]]
34 ; CHECK-NEXT: [[AND11:%.*]] = and i32 [[SPEC_SELECT]], 8
35 ; CHECK-NEXT: [[TOBOOL12:%.*]] = icmp eq i32 [[AND11]], 0
36 ; CHECK-NEXT: [[OR14:%.*]] = or i32 [[SPEC_SELECT]], 268435456
37 ; CHECK-NEXT: [[SPEC_SELECT1:%.*]] = select i1 [[TOBOOL12]], i32 [[SPEC_SELECT]], i32 [[OR14]]
38 ; CHECK-NEXT: [[TMP10:%.*]] = xor i1 [[TMP9]], true
39 ; CHECK-NEXT: [[TMP11:%.*]] = xor i1 [[TOBOOL12]], true
40 ; CHECK-NEXT: [[TMP12:%.*]] = xor i1 [[TMP10]], true
41 ; CHECK-NEXT: [[TMP13:%.*]] = or i1 [[TMP12]], [[TMP11]]
42 ; CHECK-NEXT: [[AND16:%.*]] = and i32 [[SPEC_SELECT1]], 16
43 ; CHECK-NEXT: [[TOBOOL17:%.*]] = icmp eq i32 [[AND16]], 0
44 ; CHECK-NEXT: [[OR19:%.*]] = or i32 [[SPEC_SELECT1]], 134217728
45 ; CHECK-NEXT: [[SPEC_SELECT2:%.*]] = select i1 [[TOBOOL17]], i32 [[SPEC_SELECT1]], i32 [[OR19]]
46 ; CHECK-NEXT: [[TMP14:%.*]] = xor i1 [[TMP13]], true
47 ; CHECK-NEXT: [[TMP15:%.*]] = xor i1 [[TOBOOL17]], true
48 ; CHECK-NEXT: [[TMP16:%.*]] = xor i1 [[TMP14]], true
49 ; CHECK-NEXT: [[TMP17:%.*]] = or i1 [[TMP16]], [[TMP15]]
50 ; CHECK-NEXT: [[AND21:%.*]] = and i32 [[SPEC_SELECT2]], 32
51 ; CHECK-NEXT: [[TOBOOL22:%.*]] = icmp eq i32 [[AND21]], 0
52 ; CHECK-NEXT: [[OR24:%.*]] = or i32 [[SPEC_SELECT2]], 67108864
53 ; CHECK-NEXT: [[SPEC_SELECT3:%.*]] = select i1 [[TOBOOL22]], i32 [[SPEC_SELECT2]], i32 [[OR24]]
54 ; CHECK-NEXT: [[TMP18:%.*]] = xor i1 [[TMP17]], true
55 ; CHECK-NEXT: [[TMP19:%.*]] = xor i1 [[TOBOOL22]], true
56 ; CHECK-NEXT: [[TMP20:%.*]] = xor i1 [[TMP18]], true
57 ; CHECK-NEXT: [[TMP21:%.*]] = or i1 [[TMP20]], [[TMP19]]
58 ; CHECK-NEXT: [[AND26:%.*]] = and i32 [[SPEC_SELECT3]], 64
59 ; CHECK-NEXT: [[TOBOOL27:%.*]] = icmp eq i32 [[AND26]], 0
60 ; CHECK-NEXT: [[OR29:%.*]] = or i32 [[SPEC_SELECT3]], 33554432
61 ; CHECK-NEXT: [[SPEC_SELECT4:%.*]] = select i1 [[TOBOOL27]], i32 [[SPEC_SELECT3]], i32 [[OR29]]
62 ; CHECK-NEXT: [[TMP22:%.*]] = xor i1 [[TMP21]], true
63 ; CHECK-NEXT: [[TMP23:%.*]] = xor i1 [[TOBOOL27]], true
64 ; CHECK-NEXT: [[TMP24:%.*]] = xor i1 [[TMP22]], true
65 ; CHECK-NEXT: [[TMP25:%.*]] = or i1 [[TMP24]], [[TMP23]]
66 ; CHECK-NEXT: [[AND31:%.*]] = and i32 [[SPEC_SELECT4]], 256
67 ; CHECK-NEXT: [[TOBOOL32:%.*]] = icmp eq i32 [[AND31]], 0
68 ; CHECK-NEXT: [[OR34:%.*]] = or i32 [[SPEC_SELECT4]], 8388608
69 ; CHECK-NEXT: [[SPEC_SELECT5:%.*]] = select i1 [[TOBOOL32]], i32 [[SPEC_SELECT4]], i32 [[OR34]]
70 ; CHECK-NEXT: [[TMP26:%.*]] = xor i1 [[TMP25]], true
71 ; CHECK-NEXT: [[TMP27:%.*]] = xor i1 [[TOBOOL32]], true
72 ; CHECK-NEXT: [[TMP28:%.*]] = xor i1 [[TMP26]], true
73 ; CHECK-NEXT: [[TMP29:%.*]] = or i1 [[TMP28]], [[TMP27]]
74 ; CHECK-NEXT: [[AND36:%.*]] = and i32 [[SPEC_SELECT5]], 512
75 ; CHECK-NEXT: [[TOBOOL37:%.*]] = icmp eq i32 [[AND36]], 0
76 ; CHECK-NEXT: [[OR39:%.*]] = or i32 [[SPEC_SELECT5]], 4194304
77 ; CHECK-NEXT: [[SPEC_SELECT6:%.*]] = select i1 [[TOBOOL37]], i32 [[SPEC_SELECT5]], i32 [[OR39]]
78 ; CHECK-NEXT: [[TMP30:%.*]] = xor i1 [[TMP29]], true
79 ; CHECK-NEXT: [[TMP31:%.*]] = xor i1 [[TOBOOL37]], true
80 ; CHECK-NEXT: [[TMP32:%.*]] = xor i1 [[TMP30]], true
81 ; CHECK-NEXT: [[TMP33:%.*]] = or i1 [[TMP32]], [[TMP31]]
82 ; CHECK-NEXT: [[AND41:%.*]] = and i32 [[SPEC_SELECT6]], 1024
83 ; CHECK-NEXT: [[TOBOOL42:%.*]] = icmp eq i32 [[AND41]], 0
84 ; CHECK-NEXT: [[OR44:%.*]] = or i32 [[SPEC_SELECT6]], 2097152
85 ; CHECK-NEXT: [[SPEC_SELECT7:%.*]] = select i1 [[TOBOOL42]], i32 [[SPEC_SELECT6]], i32 [[OR44]]
86 ; CHECK-NEXT: [[TMP34:%.*]] = xor i1 [[TMP33]], true
87 ; CHECK-NEXT: [[TMP35:%.*]] = xor i1 [[TOBOOL42]], true
88 ; CHECK-NEXT: [[TMP36:%.*]] = xor i1 [[TMP34]], true
89 ; CHECK-NEXT: [[TMP37:%.*]] = or i1 [[TMP36]], [[TMP35]]
90 ; CHECK-NEXT: [[AND46:%.*]] = and i32 [[SPEC_SELECT7]], 2048
91 ; CHECK-NEXT: [[TOBOOL47:%.*]] = icmp eq i32 [[AND46]], 0
92 ; CHECK-NEXT: [[OR49:%.*]] = or i32 [[SPEC_SELECT7]], 1048576
93 ; CHECK-NEXT: [[SPEC_SELECT8:%.*]] = select i1 [[TOBOOL47]], i32 [[SPEC_SELECT7]], i32 [[OR49]]
94 ; CHECK-NEXT: [[TMP38:%.*]] = xor i1 [[TMP37]], true
95 ; CHECK-NEXT: [[TMP39:%.*]] = xor i1 [[TOBOOL47]], true
96 ; CHECK-NEXT: [[TMP40:%.*]] = xor i1 [[TMP38]], true
97 ; CHECK-NEXT: [[TMP41:%.*]] = or i1 [[TMP40]], [[TMP39]]
98 ; CHECK-NEXT: [[AND51:%.*]] = and i32 [[SPEC_SELECT8]], 4096
99 ; CHECK-NEXT: [[TOBOOL52:%.*]] = icmp eq i32 [[AND51]], 0
100 ; CHECK-NEXT: [[OR54:%.*]] = or i32 [[SPEC_SELECT8]], 524288
101 ; CHECK-NEXT: [[SPEC_SELECT9:%.*]] = select i1 [[TOBOOL52]], i32 [[SPEC_SELECT8]], i32 [[OR54]]
102 ; CHECK-NEXT: [[TMP42:%.*]] = xor i1 [[TMP41]], true
103 ; CHECK-NEXT: [[TMP43:%.*]] = xor i1 [[TOBOOL52]], true
104 ; CHECK-NEXT: [[TMP44:%.*]] = xor i1 [[TMP42]], true
105 ; CHECK-NEXT: [[TMP45:%.*]] = or i1 [[TMP44]], [[TMP43]]
106 ; CHECK-NEXT: [[AND56:%.*]] = and i32 [[SPEC_SELECT9]], 8192
107 ; CHECK-NEXT: [[TOBOOL57:%.*]] = icmp eq i32 [[AND56]], 0
108 ; CHECK-NEXT: [[OR59:%.*]] = or i32 [[SPEC_SELECT9]], 262144
109 ; CHECK-NEXT: [[SPEC_SELECT10:%.*]] = select i1 [[TOBOOL57]], i32 [[SPEC_SELECT9]], i32 [[OR59]]
110 ; CHECK-NEXT: [[TMP46:%.*]] = xor i1 [[TMP45]], true
111 ; CHECK-NEXT: [[TMP47:%.*]] = xor i1 [[TOBOOL57]], true
112 ; CHECK-NEXT: [[TMP48:%.*]] = xor i1 [[TMP46]], true
113 ; CHECK-NEXT: [[TMP49:%.*]] = or i1 [[TMP48]], [[TMP47]]
114 ; CHECK-NEXT: [[AND61:%.*]] = and i32 [[SPEC_SELECT10]], 16384
115 ; CHECK-NEXT: [[TOBOOL62:%.*]] = icmp eq i32 [[AND61]], 0
116 ; CHECK-NEXT: [[OR64:%.*]] = or i32 [[SPEC_SELECT10]], 131072
117 ; CHECK-NEXT: [[SPEC_SELECT11:%.*]] = select i1 [[TOBOOL62]], i32 [[SPEC_SELECT10]], i32 [[OR64]]
118 ; CHECK-NEXT: [[TMP50:%.*]] = xor i1 [[TMP49]], true
119 ; CHECK-NEXT: [[TMP51:%.*]] = xor i1 [[TOBOOL62]], true
120 ; CHECK-NEXT: [[TMP52:%.*]] = xor i1 [[TMP50]], true
121 ; CHECK-NEXT: [[TMP53:%.*]] = or i1 [[TMP52]], [[TMP51]]
122 ; CHECK-NEXT: [[AND66:%.*]] = and i32 [[SPEC_SELECT11]], 32768
123 ; CHECK-NEXT: [[TOBOOL67:%.*]] = icmp eq i32 [[AND66]], 0
124 ; CHECK-NEXT: [[OR69:%.*]] = or i32 [[SPEC_SELECT11]], 65536
125 ; CHECK-NEXT: [[SPEC_SELECT12:%.*]] = select i1 [[TOBOOL67]], i32 [[SPEC_SELECT11]], i32 [[OR69]]
126 ; CHECK-NEXT: [[TMP54:%.*]] = xor i1 [[TMP53]], true
127 ; CHECK-NEXT: [[TMP55:%.*]] = xor i1 [[TOBOOL67]], true
128 ; CHECK-NEXT: [[TMP56:%.*]] = xor i1 [[TMP54]], true
129 ; CHECK-NEXT: [[TMP57:%.*]] = or i1 [[TMP56]], [[TMP55]]
130 ; CHECK-NEXT: [[AND71:%.*]] = and i32 [[SPEC_SELECT12]], 128
131 ; CHECK-NEXT: [[TOBOOL72:%.*]] = icmp eq i32 [[AND71]], 0
132 ; CHECK-NEXT: [[OR74:%.*]] = or i32 [[SPEC_SELECT12]], 16777216
133 ; CHECK-NEXT: [[SPEC_SELECT13:%.*]] = select i1 [[TOBOOL72]], i32 [[SPEC_SELECT12]], i32 [[OR74]]
134 ; CHECK-NEXT: [[TMP58:%.*]] = xor i1 [[TMP57]], true
135 ; CHECK-NEXT: [[TMP59:%.*]] = xor i1 [[TOBOOL72]], true
136 ; CHECK-NEXT: [[TMP60:%.*]] = xor i1 [[TMP58]], true
137 ; CHECK-NEXT: [[TMP61:%.*]] = or i1 [[TMP60]], [[TMP59]]
138 ; CHECK-NEXT: br i1 [[TMP61]], label [[TMP62:%.*]], label [[TMP63:%.*]]
140 ; CHECK-NEXT: store i32 [[SPEC_SELECT13]], ptr [[B]], align 4
141 ; CHECK-NEXT: br label [[TMP63]]
143 ; CHECK-NEXT: ret i32 0
146 %0 = load i32, ptr %b, align 4
148 %tobool = icmp eq i32 %and, 0
149 br i1 %tobool, label %if.end, label %if.then
151 if.then: ; preds = %entry
152 %or = or i32 %0, -2147483648
153 store i32 %or, ptr %b, align 4
156 if.end: ; preds = %entry, %if.then
157 %1 = phi i32 [ %0, %entry ], [ %or, %if.then ]
158 %and1 = and i32 %1, 2
159 %tobool2 = icmp eq i32 %and1, 0
160 br i1 %tobool2, label %if.end5, label %if.then3
162 if.then3: ; preds = %if.end
163 %or4 = or i32 %1, 1073741824
164 store i32 %or4, ptr %b, align 4
167 if.end5: ; preds = %if.end, %if.then3
168 %2 = phi i32 [ %1, %if.end ], [ %or4, %if.then3 ]
169 %and6 = and i32 %2, 4
170 %tobool7 = icmp eq i32 %and6, 0
171 br i1 %tobool7, label %if.end10, label %if.then8
173 if.then8: ; preds = %if.end5
174 %or9 = or i32 %2, 536870912
175 store i32 %or9, ptr %b, align 4
178 if.end10: ; preds = %if.end5, %if.then8
179 %3 = phi i32 [ %2, %if.end5 ], [ %or9, %if.then8 ]
180 %and11 = and i32 %3, 8
181 %tobool12 = icmp eq i32 %and11, 0
182 br i1 %tobool12, label %if.end15, label %if.then13
184 if.then13: ; preds = %if.end10
185 %or14 = or i32 %3, 268435456
186 store i32 %or14, ptr %b, align 4
189 if.end15: ; preds = %if.end10, %if.then13
190 %4 = phi i32 [ %3, %if.end10 ], [ %or14, %if.then13 ]
191 %and16 = and i32 %4, 16
192 %tobool17 = icmp eq i32 %and16, 0
193 br i1 %tobool17, label %if.end20, label %if.then18
195 if.then18: ; preds = %if.end15
196 %or19 = or i32 %4, 134217728
197 store i32 %or19, ptr %b, align 4
200 if.end20: ; preds = %if.end15, %if.then18
201 %5 = phi i32 [ %4, %if.end15 ], [ %or19, %if.then18 ]
202 %and21 = and i32 %5, 32
203 %tobool22 = icmp eq i32 %and21, 0
204 br i1 %tobool22, label %if.end25, label %if.then23
206 if.then23: ; preds = %if.end20
207 %or24 = or i32 %5, 67108864
208 store i32 %or24, ptr %b, align 4
211 if.end25: ; preds = %if.end20, %if.then23
212 %6 = phi i32 [ %5, %if.end20 ], [ %or24, %if.then23 ]
213 %and26 = and i32 %6, 64
214 %tobool27 = icmp eq i32 %and26, 0
215 br i1 %tobool27, label %if.end30, label %if.then28
217 if.then28: ; preds = %if.end25
218 %or29 = or i32 %6, 33554432
219 store i32 %or29, ptr %b, align 4
222 if.end30: ; preds = %if.end25, %if.then28
223 %7 = phi i32 [ %6, %if.end25 ], [ %or29, %if.then28 ]
224 %and31 = and i32 %7, 256
225 %tobool32 = icmp eq i32 %and31, 0
226 br i1 %tobool32, label %if.end35, label %if.then33
228 if.then33: ; preds = %if.end30
229 %or34 = or i32 %7, 8388608
230 store i32 %or34, ptr %b, align 4
233 if.end35: ; preds = %if.end30, %if.then33
234 %8 = phi i32 [ %7, %if.end30 ], [ %or34, %if.then33 ]
235 %and36 = and i32 %8, 512
236 %tobool37 = icmp eq i32 %and36, 0
237 br i1 %tobool37, label %if.end40, label %if.then38
239 if.then38: ; preds = %if.end35
240 %or39 = or i32 %8, 4194304
241 store i32 %or39, ptr %b, align 4
244 if.end40: ; preds = %if.end35, %if.then38
245 %9 = phi i32 [ %8, %if.end35 ], [ %or39, %if.then38 ]
246 %and41 = and i32 %9, 1024
247 %tobool42 = icmp eq i32 %and41, 0
248 br i1 %tobool42, label %if.end45, label %if.then43
250 if.then43: ; preds = %if.end40
251 %or44 = or i32 %9, 2097152
252 store i32 %or44, ptr %b, align 4
255 if.end45: ; preds = %if.end40, %if.then43
256 %10 = phi i32 [ %9, %if.end40 ], [ %or44, %if.then43 ]
257 %and46 = and i32 %10, 2048
258 %tobool47 = icmp eq i32 %and46, 0
259 br i1 %tobool47, label %if.end50, label %if.then48
261 if.then48: ; preds = %if.end45
262 %or49 = or i32 %10, 1048576
263 store i32 %or49, ptr %b, align 4
266 if.end50: ; preds = %if.end45, %if.then48
267 %11 = phi i32 [ %10, %if.end45 ], [ %or49, %if.then48 ]
268 %and51 = and i32 %11, 4096
269 %tobool52 = icmp eq i32 %and51, 0
270 br i1 %tobool52, label %if.end55, label %if.then53
272 if.then53: ; preds = %if.end50
273 %or54 = or i32 %11, 524288
274 store i32 %or54, ptr %b, align 4
277 if.end55: ; preds = %if.end50, %if.then53
278 %12 = phi i32 [ %11, %if.end50 ], [ %or54, %if.then53 ]
279 %and56 = and i32 %12, 8192
280 %tobool57 = icmp eq i32 %and56, 0
281 br i1 %tobool57, label %if.end60, label %if.then58
283 if.then58: ; preds = %if.end55
284 %or59 = or i32 %12, 262144
285 store i32 %or59, ptr %b, align 4
288 if.end60: ; preds = %if.end55, %if.then58
289 %13 = phi i32 [ %12, %if.end55 ], [ %or59, %if.then58 ]
290 %and61 = and i32 %13, 16384
291 %tobool62 = icmp eq i32 %and61, 0
292 br i1 %tobool62, label %if.end65, label %if.then63
294 if.then63: ; preds = %if.end60
295 %or64 = or i32 %13, 131072
296 store i32 %or64, ptr %b, align 4
299 if.end65: ; preds = %if.end60, %if.then63
300 %14 = phi i32 [ %13, %if.end60 ], [ %or64, %if.then63 ]
301 %and66 = and i32 %14, 32768
302 %tobool67 = icmp eq i32 %and66, 0
303 br i1 %tobool67, label %if.end70, label %if.then68
305 if.then68: ; preds = %if.end65
306 %or69 = or i32 %14, 65536
307 store i32 %or69, ptr %b, align 4
310 if.end70: ; preds = %if.end65, %if.then68
311 %15 = phi i32 [ %14, %if.end65 ], [ %or69, %if.then68 ]
312 %and71 = and i32 %15, 128
313 %tobool72 = icmp eq i32 %and71, 0
314 br i1 %tobool72, label %if.end75, label %if.then73
316 if.then73: ; preds = %if.end70
317 %or74 = or i32 %15, 16777216
318 store i32 %or74, ptr %b, align 4
321 if.end75: ; preds = %if.end70, %if.then73