blob: 13bbdfe83d079ae0ea1e6a617f8f7f704ec2c27d [file] [log] [blame]
Joerg Sonnenbergerfa736742017-03-26 06:44:08 +00001; RUN: opt < %s -latesimplifycfg -S | FileCheck %s
James Molloyb2e436d2016-08-01 07:45:11 +00002
3target datalayout = "e-n32"
4
5; CHECK-LABEL: @test1
Benjamin Kramer000a87d2016-08-05 14:58:34 +00006; CHECK: %[[SUB:.*]] = sub i32 %a, 97
7; CHECK: %[[LSHR:.*]] = lshr i32 %[[SUB]], 2
8; CHECK: %[[SHL:.*]] = shl i32 %[[SUB]], 30
9; CHECK: %[[OR:.*]] = or i32 %[[LSHR]], %[[SHL]]
10; CHECK: switch i32 %[[OR]], label %def [
James Molloyb2e436d2016-08-01 07:45:11 +000011; CHECK: i32 0, label %one
12; CHECK: i32 1, label %two
13; CHECK: i32 2, label %three
14; CHECK: ]
15define i32 @test1(i32 %a) {
16 switch i32 %a, label %def [
17 i32 97, label %one
18 i32 101, label %two
19 i32 105, label %three
20 i32 109, label %three
21 ]
22
23def:
24 ret i32 8867
25
26one:
27 ret i32 11984
28two:
29 ret i32 1143
30three:
31 ret i32 99783
32}
33
34; Optimization shouldn't trigger; bitwidth > 64
35; CHECK-LABEL: @test2
36; CHECK: switch i128 %a, label %def
37define i128 @test2(i128 %a) {
38 switch i128 %a, label %def [
39 i128 97, label %one
40 i128 101, label %two
41 i128 105, label %three
42 i128 109, label %three
43 ]
44
45def:
46 ret i128 8867
47
48one:
49 ret i128 11984
50two:
51 ret i128 1143
52three:
53 ret i128 99783
54}
55
56
57; Optimization shouldn't trigger; no holes present
58; CHECK-LABEL: @test3
59; CHECK: switch i32 %a, label %def
60define i32 @test3(i32 %a) {
61 switch i32 %a, label %def [
62 i32 97, label %one
63 i32 98, label %two
64 i32 99, label %three
65 ]
66
67def:
68 ret i32 8867
69
70one:
71 ret i32 11984
72two:
73 ret i32 1143
74three:
75 ret i32 99783
76}
77
78; Optimization shouldn't trigger; not an arithmetic progression
79; CHECK-LABEL: @test4
80; CHECK: switch i32 %a, label %def
81define i32 @test4(i32 %a) {
82 switch i32 %a, label %def [
83 i32 97, label %one
84 i32 102, label %two
85 i32 105, label %three
86 i32 109, label %three
87 ]
88
89def:
90 ret i32 8867
91
92one:
93 ret i32 11984
94two:
95 ret i32 1143
96three:
97 ret i32 99783
98}
99
100; Optimization shouldn't trigger; not a power of two
101; CHECK-LABEL: @test5
102; CHECK: switch i32 %a, label %def
103define i32 @test5(i32 %a) {
104 switch i32 %a, label %def [
105 i32 97, label %one
106 i32 102, label %two
107 i32 107, label %three
108 i32 112, label %three
109 ]
110
111def:
112 ret i32 8867
113
114one:
115 ret i32 11984
116two:
117 ret i32 1143
118three:
119 ret i32 99783
120}
121
122; CHECK-LABEL: @test6
Benjamin Kramer000a87d2016-08-05 14:58:34 +0000123; CHECK: %[[SUB:.*]] = sub i32 %a, -109
124; CHECK: %[[LSHR:.*]] = lshr i32 %[[SUB]], 2
125; CHECK: %[[SHL:.*]] = shl i32 %[[SUB]], 30
126; CHECK: %[[OR:.*]] = or i32 %[[LSHR]], %[[SHL]]
127; CHECK: switch i32 %[[OR]], label %def [
James Molloyb2e436d2016-08-01 07:45:11 +0000128define i32 @test6(i32 %a) optsize {
129 switch i32 %a, label %def [
130 i32 -97, label %one
131 i32 -101, label %two
132 i32 -105, label %three
133 i32 -109, label %three
134 ]
135
136def:
137 ret i32 8867
138
139one:
140 ret i32 11984
141two:
142 ret i32 1143
143three:
144 ret i32 99783
145}
146
147; CHECK-LABEL: @test7
Benjamin Kramer000a87d2016-08-05 14:58:34 +0000148; CHECK: %[[SUB:.*]] = sub i8 %a, -36
149; CHECK: %[[LSHR:.*]] = lshr i8 %[[SUB]], 2
150; CHECK: %[[SHL:.*]] = shl i8 %[[SUB]], 6
151; CHECK: %[[OR:.*]] = or i8 %[[LSHR]], %[[SHL]]
152; CHECK: switch.tableidx = {{.*}} %[[OR]]
James Molloyb2e436d2016-08-01 07:45:11 +0000153define i8 @test7(i8 %a) optsize {
154 switch i8 %a, label %def [
155 i8 220, label %one
156 i8 224, label %two
157 i8 228, label %three
158 i8 232, label %three
159 ]
160
161def:
162 ret i8 8867
163
164one:
165 ret i8 11984
166two:
167 ret i8 1143
168three:
169 ret i8 99783
170}
171
172; CHECK-LABEL: @test8
Benjamin Kramer000a87d2016-08-05 14:58:34 +0000173; CHECK: %[[SUB:.*]] = sub i32 %a, 97
174; CHECK: %[[LSHR:.*]] = lshr i32 %1, 2
175; CHECK: %[[SHL:.*]] = shl i32 %1, 30
176; CHECK: %[[OR:.*]] = or i32 %[[LSHR]], %[[SHL]]
177; CHECK: switch i32 %[[OR]], label %def [
James Molloyb2e436d2016-08-01 07:45:11 +0000178define i32 @test8(i32 %a) optsize {
179 switch i32 %a, label %def [
180 i32 97, label %one
181 i32 101, label %two
182 i32 105, label %three
183 i32 113, label %three
184 ]
185
186def:
187 ret i32 8867
188
189one:
190 ret i32 11984
191two:
192 ret i32 1143
193three:
194 ret i32 99783
James Molloybade86c2016-08-01 09:34:48 +0000195}
196
197; CHECK-LABEL: @test9
198; CHECK: switch
199; CHECK: i32 6
200; CHECK: i32 7
201; CHECK: i32 0
202; CHECK: i32 2
203define i32 @test9(i32 %a) {
204 switch i32 %a, label %def [
205 i32 18, label %one
206 i32 20, label %two
207 i32 6, label %three
208 i32 10, label %three
209 ]
210
211def:
212 ret i32 8867
213
214one:
215 ret i32 11984
216two:
217 ret i32 1143
218three:
219 ret i32 99783
220}
221