1 ; RUN: opt -simplifycfg -instcombine < %s -simplifycfg-merge-cond-stores=true -simplifycfg-merge-cond-stores-aggressively=false -phi-node-folding-threshold=2 -S | FileCheck %s
3 ; CHECK-LABEL: @test_simple
4 ; This test should succeed and end up if-converted.
5 ; CHECK: %[[A:.*]] = or i32 %a, %b
6 ; CHECK-NEXT: %[[x:.*]] = icmp eq i32 %[[A]], 0
7 ; CHECK-NEXT: br i1 %[[x]]
11 define void @test_simple(i32* %p, i32 %a, i32 %b) {
13 %x1 = icmp eq i32 %a, 0
14 br i1 %x1, label %fallthrough, label %yes1
21 %x2 = icmp eq i32 %b, 0
22 br i1 %x2, label %end, label %yes2
32 ; CHECK-LABEL: @test_recursive
33 ; This test should entirely fold away, leaving one large basic block.
37 define void @test_recursive(i32* %p, i32 %a, i32 %b, i32 %c, i32 %d) {
39 %x1 = icmp eq i32 %a, 0
40 br i1 %x1, label %fallthrough, label %yes1
47 %x2 = icmp eq i32 %b, 0
48 br i1 %x2, label %next, label %yes2
55 %x3 = icmp eq i32 %c, 0
56 br i1 %x3, label %fallthrough2, label %yes3
60 br label %fallthrough2
63 %x4 = icmp eq i32 %d, 0
64 br i1 %x4, label %end, label %yes4
75 ; CHECK-LABEL: @test_not_ifconverted
76 ; The code in each diamond is too large - it won't be if-converted so our
77 ; heuristics should say no.
81 define void @test_not_ifconverted(i32* %p, i32 %a, i32 %b) {
83 %x1 = icmp eq i32 %a, 0
84 br i1 %x1, label %fallthrough, label %yes1
90 store i32 %y3, i32* %p
94 %x2 = icmp eq i32 %b, 0
95 br i1 %x2, label %end, label %yes2
100 %z3 = and i32 %z2, 67
101 store i32 %z3, i32* %p
108 ; CHECK-LABEL: @test_aliasing1
109 ; The store to %p clobbers the previous store, so if-converting this would
114 define void @test_aliasing1(i32* %p, i32 %a, i32 %b) {
116 %x1 = icmp eq i32 %a, 0
117 br i1 %x1, label %fallthrough, label %yes1
121 br label %fallthrough
124 %y1 = load i32, i32* %p
125 %x2 = icmp eq i32 %y1, 0
126 br i1 %x2, label %end, label %yes2
136 ; CHECK-LABEL: @test_aliasing2
137 ; The load from %q aliases with %p, so if-converting this would be illegal.
141 define void @test_aliasing2(i32* %p, i32* %q, i32 %a, i32 %b) {
143 %x1 = icmp eq i32 %a, 0
144 br i1 %x1, label %fallthrough, label %yes1
148 br label %fallthrough
151 %y1 = load i32, i32* %q
152 %x2 = icmp eq i32 %y1, 0
153 br i1 %x2, label %end, label %yes2
165 ; CHECK-LABEL: @test_diamond_simple
166 ; This should get if-converted.
170 define i32 @test_diamond_simple(i32* %p, i32* %q, i32 %a, i32 %b) {
172 %x1 = icmp eq i32 %a, 0
173 br i1 %x1, label %no1, label %yes1
177 br label %fallthrough
181 br label %fallthrough
184 %z2 = phi i32 [ %z1, %no1 ], [ 0, %yes1 ]
185 %x2 = icmp eq i32 %b, 0
186 br i1 %x2, label %no2, label %yes2
193 %z3 = sub i32 %z2, %b
197 %z4 = phi i32 [ %z3, %no2 ], [ 3, %yes2 ]
201 ; CHECK-LABEL: @test_diamond_alias3
202 ; Now there is a call to f() in the bottom branch. The store in the first
203 ; branch would now be reordered with respect to the call if we if-converted,
208 define i32 @test_diamond_alias3(i32* %p, i32* %q, i32 %a, i32 %b) {
210 %x1 = icmp eq i32 %a, 0
211 br i1 %x1, label %no1, label %yes1
215 br label %fallthrough
220 br label %fallthrough
223 %z2 = phi i32 [ %z1, %no1 ], [ 0, %yes1 ]
224 %x2 = icmp eq i32 %b, 0
225 br i1 %x2, label %no2, label %yes2
233 %z3 = sub i32 %z2, %b
237 %z4 = phi i32 [ %z3, %no2 ], [ 3, %yes2 ]