1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=constraint-elimination -S %s | FileCheck %s
4 declare void @may_unwind()
6 define i1 @test_switch_in_block_with_assume(i8 %x) {
7 ; CHECK-LABEL: @test_switch_in_block_with_assume(
9 ; CHECK-NEXT: call void @may_unwind()
10 ; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[X:%.*]], 10
11 ; CHECK-NEXT: call void @llvm.assume(i1 [[C_1]])
12 ; CHECK-NEXT: switch i8 0, label [[EXIT_1:%.*]] [
13 ; CHECK-NEXT: i8 1, label [[EXIT_2:%.*]]
16 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[X]], 9
17 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 true, [[C_2]]
18 ; CHECK-NEXT: ret i1 [[RES_1]]
20 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[X]], 9
21 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, [[C_3]]
22 ; CHECK-NEXT: ret i1 [[RES_2]]
25 call void @may_unwind()
26 %c.1 = icmp ult i8 %x, 10
27 call void @llvm.assume(i1 %c.1)
28 switch i8 0, label %exit.1 [
33 %t.1 = icmp ult i8 %x, 10
34 %c.2 = icmp ult i8 %x, 9
35 %res.1 = xor i1 %t.1, %c.2
39 %t.2 = icmp ult i8 %x, 10
40 %c.3 = icmp ult i8 %x, 9
41 %res.2 = xor i1 %t.2, %c.3
45 declare void @llvm.assume(i1)
47 define i1 @simplify_based_on_switch(i8 %x) {
48 ; CHECK-LABEL: @simplify_based_on_switch(
50 ; CHECK-NEXT: switch i8 [[X:%.*]], label [[EXIT_1:%.*]] [
51 ; CHECK-NEXT: i8 6, label [[EXIT_2:%.*]]
52 ; CHECK-NEXT: i8 10, label [[EXIT_3:%.*]]
55 ; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[X]], 7
56 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[X]], 6
57 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_1]], [[C_2]]
58 ; CHECK-NEXT: ret i1 [[RES_1]]
60 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, false
61 ; CHECK-NEXT: ret i1 [[RES_2]]
63 ; CHECK-NEXT: [[RES_3:%.*]] = xor i1 true, false
64 ; CHECK-NEXT: ret i1 [[RES_3]]
67 switch i8 %x, label %exit.1 [
73 %c.1 = icmp ult i8 %x, 7
74 %c.2 = icmp ult i8 %x, 6
75 %res.1 = xor i1 %c.1, %c.2
79 %t.1 = icmp ult i8 %x, 7
80 %f.1 = icmp ult i8 %x, 6
81 %res.2 = xor i1 %t.1, %f.1
85 %t.2 = icmp ult i8 %x, 11
86 %f.2 = icmp ult i8 %x, 10
87 %res.3 = xor i1 %t.2, %f.2
91 define i1 @simplify_based_on_switch_successor_branches(i8 %x) {
92 ; CHECK-LABEL: @simplify_based_on_switch_successor_branches(
94 ; CHECK-NEXT: switch i8 [[X:%.*]], label [[EXIT_1:%.*]] [
95 ; CHECK-NEXT: i8 6, label [[EXIT_2:%.*]]
96 ; CHECK-NEXT: i8 10, label [[EXIT_3:%.*]]
99 ; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[X]], 7
100 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[X]], 6
101 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_1]], [[C_2]]
102 ; CHECK-NEXT: ret i1 [[RES_1]]
104 ; CHECK-NEXT: [[RES_2:%.*]] = xor i1 true, false
105 ; CHECK-NEXT: call void @use(i1 [[RES_2]])
106 ; CHECK-NEXT: br label [[EXIT_3]]
108 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[X]], 11
109 ; CHECK-NEXT: [[C_4:%.*]] = icmp ult i8 [[X]], 10
110 ; CHECK-NEXT: [[RES_3:%.*]] = xor i1 [[C_3]], [[C_4]]
111 ; CHECK-NEXT: ret i1 [[RES_3]]
114 switch i8 %x, label %exit.1 [
120 %c.1 = icmp ult i8 %x, 7
121 %c.2 = icmp ult i8 %x, 6
122 %res.1 = xor i1 %c.1, %c.2
126 %t.1 = icmp ult i8 %x, 7
127 %f.1 = icmp ult i8 %x, 6
128 %res.2 = xor i1 %t.1, %f.1
129 call void @use(i1 %res.2)
133 %c.3 = icmp ult i8 %x, 11
134 %c.4 = icmp ult i8 %x, 10
135 %res.3 = xor i1 %c.3, %c.4
139 define i1 @switch_same_destination_for_different_cases(i8 %x) {
140 ; CHECK-LABEL: @switch_same_destination_for_different_cases(
142 ; CHECK-NEXT: switch i8 [[X:%.*]], label [[EXIT_1:%.*]] [
143 ; CHECK-NEXT: i8 6, label [[EXIT_2:%.*]]
144 ; CHECK-NEXT: i8 10, label [[EXIT_2]]
147 ; CHECK-NEXT: [[C_1:%.*]] = icmp ult i8 [[X]], 7
148 ; CHECK-NEXT: [[C_2:%.*]] = icmp ult i8 [[X]], 6
149 ; CHECK-NEXT: [[RES_1:%.*]] = xor i1 [[C_1]], [[C_2]]
150 ; CHECK-NEXT: ret i1 [[RES_1]]
152 ; CHECK-NEXT: [[C_3:%.*]] = icmp ult i8 [[X]], 7
153 ; CHECK-NEXT: call void @use(i1 [[C_3]])
154 ; CHECK-NEXT: [[C_4:%.*]] = icmp ult i8 [[X]], 6
155 ; CHECK-NEXT: call void @use(i1 [[C_4]])
156 ; CHECK-NEXT: [[C_5:%.*]] = icmp ult i8 [[X]], 11
157 ; CHECK-NEXT: call void @use(i1 [[C_5]])
158 ; CHECK-NEXT: [[C_6:%.*]] = icmp ult i8 [[X]], 10
159 ; CHECK-NEXT: ret i1 [[C_6]]
162 switch i8 %x, label %exit.1 [
168 %c.1 = icmp ult i8 %x, 7
169 %c.2 = icmp ult i8 %x, 6
170 %res.1 = xor i1 %c.1, %c.2
174 %c.3 = icmp ult i8 %x, 7
175 call void @use(i1 %c.3)
176 %c.4 = icmp ult i8 %x, 6
177 call void @use(i1 %c.4)
178 %c.5 = icmp ult i8 %x, 11
179 call void @use(i1 %c.5)
180 %c.6 = icmp ult i8 %x, 10
184 declare void @use(i1)