1 ; RUN: opt -flattencfg -S < %s -enable-new-pm=0 | FileCheck %s
4 ; This test checks whether the pass completes without a crash.
5 ; The code is not transformed in any way
7 ; CHECK-LABEL: @test_not_crash
8 define void @test_not_crash(i32 %in_a) #0 {
10 %cmp0 = icmp eq i32 %in_a, -1
11 %cmp1 = icmp ne i32 %in_a, 0
12 %cond0 = and i1 %cmp0, %cmp1
13 br i1 %cond0, label %b0, label %b1
16 %cmp2 = icmp eq i32 %in_a, 0
17 %cmp3 = icmp ne i32 %in_a, 1
18 %cond1 = or i1 %cmp2, %cmp3
19 br i1 %cond1, label %exit, label %b1
21 b1: ; preds = %entry, %b0
24 exit: ; preds = %entry, %b0, %b1
28 ; CHECK-LABEL: @test_not_crash2
30 ; CHECK-NEXT: %0 = fcmp ult float %a
31 ; CHECK-NEXT: %1 = fcmp ult float %b
32 ; CHECK-NEXT: [[COND:%[a-z0-9]+]] = and i1 %0, %1
33 ; CHECK-NEXT: br i1 [[COND]], label %bb4, label %bb3
35 ; CHECK-NEXT: br label %bb4
37 ; CHECK-NEXT: ret void
38 define void @test_not_crash2(float %a, float %b) #0 {
40 %0 = fcmp ult float %a, 1.000000e+00
41 br i1 %0, label %bb0, label %bb1
46 bb4: ; preds = %bb0, %bb3
52 bb0: ; preds = %bb1, %entry
53 %1 = fcmp ult float %b, 1.000000e+00
54 br i1 %1, label %bb4, label %bb3
57 ; CHECK-LABEL: @test_not_crash3
59 ; CHECK-NEXT: %a_eq_0 = icmp eq i32 %a, 0
60 ; CHECK-NEXT: %a_eq_1 = icmp eq i32 %a, 1
61 ; CHECK-NEXT: [[COND:%[a-z0-9]+]] = or i1 %a_eq_0, %a_eq_1
62 ; CHECK-NEXT: br i1 [[COND]], label %bb2, label %bb3
64 ; CHECK-NEXT: br label %bb3
66 ; CHECK-NEXT: %check_badref = phi i32 [ 17, %entry ], [ 11, %bb2 ]
67 ; CHECK-NEXT: ret void
68 define void @test_not_crash3(i32 %a) #0 {
70 %a_eq_0 = icmp eq i32 %a, 0
71 br i1 %a_eq_0, label %bb0, label %bb1
76 bb1: ; preds = %bb0, %entry
77 %a_eq_1 = icmp eq i32 %a, 1
78 br i1 %a_eq_1, label %bb2, label %bb3
83 bb3: ; preds = %bb2, %bb1
84 %check_badref = phi i32 [ 17, %bb1 ], [ 11, %bb2 ]
89 @g = global i32 0, align 4
91 ; CHECK-LABEL: @test_then
92 ; CHECK-NEXT: entry.x:
93 ; CHECK-NEXT: %cmp.x = icmp ne i32 %x, 0
94 ; CHECK-NEXT: %cmp.y = icmp ne i32 %y, 0
95 ; CHECK-NEXT: [[COND:%[a-z0-9]+]] = or i1 %cmp.x, %cmp.y
96 ; CHECK-NEXT: br i1 [[COND]], label %if.then.y, label %exit
98 ; CHECK-NEXT: store i32 %z, i32* @g, align 4
99 ; CHECK-NEXT: br label %exit
101 ; CHECK-NEXT: ret void
102 define void @test_then(i32 %x, i32 %y, i32 %z) {
104 %cmp.x = icmp ne i32 %x, 0
105 br i1 %cmp.x, label %if.then.x, label %entry.y
108 store i32 %z, i32* @g, align 4
112 %cmp.y = icmp ne i32 %y, 0
113 br i1 %cmp.y, label %if.then.y, label %exit
116 store i32 %z, i32* @g, align 4
123 ; CHECK-LABEL: @test_else
124 ; CHECK-NEXT: entry.x:
125 ; CHECK-NEXT: %cmp.x = icmp eq i32 %x, 0
126 ; CHECK-NEXT: %cmp.y = icmp eq i32 %y, 0
127 ; CHECK-NEXT: [[COND:%[a-z0-9]+]] = and i1 %cmp.x, %cmp.y
128 ; CHECK-NEXT: br i1 [[COND]], label %exit, label %if.else.y
130 ; CHECK-NEXT: store i32 %z, i32* @g, align 4
131 ; CHECK-NEXT: br label %exit
133 ; CHECK-NEXT: ret void
134 define void @test_else(i32 %x, i32 %y, i32 %z) {
136 %cmp.x = icmp eq i32 %x, 0
137 br i1 %cmp.x, label %entry.y, label %if.else.x
140 store i32 %z, i32* @g, align 4
144 %cmp.y = icmp eq i32 %y, 0
145 br i1 %cmp.y, label %exit, label %if.else.y
148 store i32 %z, i32* @g, align 4
155 ; CHECK-LABEL: @test_combine_and
156 ; CHECK-NEXT: entry.x:
157 ; CHECK-NEXT: %cmp.x = icmp eq i32 %x, 0
158 ; CHECK-NEXT: %cmp.y = icmp eq i32 %y, 0
159 ; CHECK-NEXT: [[COND:%[a-z0-9]+]] = and i1 %cmp.x, %cmp.y
160 ; CHECK-NEXT: br i1 [[COND]], label %exit, label %if.then.y
162 ; CHECK-NEXT: store i32 %z, i32* @g, align 4
163 ; CHECK-NEXT: br label %exit
165 ; CHECK-NEXT: ret void
166 define void @test_combine_and(i32 %x, i32 %y, i32 %z) {
168 %cmp.x = icmp eq i32 %x, 0
169 br i1 %cmp.x, label %entry.y, label %if.else.x
172 store i32 %z, i32* @g, align 4
176 %cmp.y = icmp ne i32 %y, 0
177 br i1 %cmp.y, label %if.then.y, label %exit
180 store i32 %z, i32* @g, align 4
187 ; CHECK-LABEL: @test_combine_or
188 ; CHECK-NEXT: entry.x:
189 ; CHECK-NEXT: %cmp.x = icmp ne i32 %x, 0
190 ; CHECK-NEXT: %cmp.y = icmp ne i32 %y, 0
191 ; CHECK-NEXT: [[COND:%[a-z0-9]+]] = or i1 %cmp.x, %cmp.y
192 ; CHECK-NEXT: br i1 [[COND]], label %if.else.y, label %exit
194 ; CHECK-NEXT: store i32 %z, i32* @g, align 4
195 ; CHECK-NEXT: br label %exit
197 ; CHECK-NEXT: ret void
198 define void @test_combine_or(i32 %x, i32 %y, i32 %z) {
200 %cmp.x = icmp ne i32 %x, 0
201 br i1 %cmp.x, label %if.then.x, label %entry.y
204 store i32 %z, i32* @g, align 4
208 %cmp.y = icmp eq i32 %y, 0
209 br i1 %cmp.y, label %exit, label %if.else.y
212 store i32 %z, i32* @g, align 4