1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; Vary legal integer types in data layout.
3 ; RUN: opt < %s -instcombine -S -data-layout=n32 | FileCheck %s --check-prefix=ALL --check-prefix=CHECK32
4 ; RUN: opt < %s -instcombine -S -data-layout=n32:64 | FileCheck %s --check-prefix=ALL --check-prefix=CHECK64
6 define i32 @positive1(i64 %a) {
7 ; ALL-LABEL: @positive1(
9 ; ALL-NEXT: i32 10, label %return
10 ; ALL-NEXT: i32 100, label %sw.bb1
11 ; ALL-NEXT: i32 1001, label %sw.bb2
15 %and = and i64 %a, 4294967295
16 switch i64 %and, label %sw.default [
18 i64 100, label %sw.bb1
19 i64 1001, label %sw.bb2
32 %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ]
36 define i32 @negative1(i64 %a) {
37 ; ALL-LABEL: @negative1(
39 ; ALL-NEXT: i32 -10, label %return
40 ; ALL-NEXT: i32 -100, label %sw.bb1
41 ; ALL-NEXT: i32 -1001, label %sw.bb2
45 %or = or i64 %a, -4294967296
46 switch i64 %or, label %sw.default [
47 i64 -10, label %return
48 i64 -100, label %sw.bb1
49 i64 -1001, label %sw.bb2
62 %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ]
66 ; Make sure truncating a constant int larger than 64-bit doesn't trigger an
69 define i32 @trunc72to68(i72 %a) {
70 ; ALL-LABEL: @trunc72to68(
72 ; ALL-NEXT: i68 10, label %return
73 ; ALL-NEXT: i68 100, label %sw.bb1
74 ; ALL-NEXT: i68 1001, label %sw.bb2
78 %and = and i72 %a, 295147905179352825855
79 switch i72 %and, label %sw.default [
81 i72 100, label %sw.bb1
82 i72 1001, label %sw.bb2
95 %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ]
99 ; Make sure to avoid assertion crashes and use the type before
100 ; truncation to generate the sub constant expressions that leads
101 ; to the recomputed condition.
102 ; We allow to truncate from i64 to i59 if in 32-bit mode,
103 ; because both are illegal.
105 define void @trunc64to59(i64 %a) {
106 ; ALL-LABEL: @trunc64to59(
107 ; ALL-CHECK32: switch i59
108 ; ALL-CHECK32-NEXT: i59 0, label %sw.bb1
109 ; ALL-CHECK32-NEXT: i59 18717182647723699, label %sw.bb2
110 ; ALL-CHECK32-NEXT: ]
111 ; ALL-CHECK64: switch i64
112 ; ALL-CHECK64-NEXT: i64 0, label %sw.bb1
113 ; ALL-CHECK64-NEXT: i64 18717182647723699, label %sw.bb2
114 ; ALL-CHECK64-NEXT: ]
117 %tmp0 = and i64 %a, 15
118 %tmp1 = mul i64 %tmp0, -6425668444178048401
119 %tmp2 = add i64 %tmp1, 5170979678563097242
120 %tmp3 = mul i64 %tmp2, 1627972535142754813
121 switch i64 %tmp3, label %sw.default [
122 i64 847514119312061490, label %sw.bb1
123 i64 866231301959785189, label %sw.bb2
136 ; https://llvm.org/bugs/show_bug.cgi?id=31260
138 define i8 @PR31260(i8 %x) {
139 ; ALL-LABEL: @PR31260(
141 ; ALL-NEXT: [[TMP0:%.*]] = trunc i8 %x to i2
142 ; ALL-NEXT: [[TRUNC:%.*]] = and i2 [[TMP0]], -2
143 ; ALL-NEXT: switch i2 [[TRUNC]], label %exit [
144 ; ALL-NEXT: i2 0, label %case126
145 ; ALL-NEXT: i2 -2, label %case124
156 %t5 = add nsw i8 %t4, -126
157 switch i8 %t5, label %exit [
158 i8 -126, label %case126
159 i8 -124, label %case124
170 ; Make sure the arithmetic evaluation of the switch
171 ; condition is evaluated on the original type
172 define i32 @trunc32to16(i32 %a0) #0 {
173 ; ALL-LABEL: @trunc32to16(
175 ; ALL-NEXT: i16 63, label %sw.bb
176 ; ALL-NEXT: i16 1, label %sw.bb1
177 ; ALL-NEXT: i16 100, label %sw.bb2
181 %retval = alloca i32, align 4
182 %xor = xor i32 %a0, 1034460917
183 %shr = lshr i32 %xor, 16
184 %add = add i32 %shr, -917677090
185 switch i32 %add, label %sw.epilog [
186 i32 -917677027, label %sw.bb
187 i32 -917677089, label %sw.bb1
188 i32 -917676990, label %sw.bb2
191 sw.bb: ; preds = %entry
192 store i32 90, i32* %retval, align 4
195 sw.bb1: ; preds = %entry
196 store i32 91, i32* %retval, align 4
199 sw.bb2: ; preds = %entry
200 store i32 92, i32* %retval, align 4
203 sw.epilog: ; preds = %entry
204 store i32 113, i32* %retval, align 4
207 return: ; preds = %sw.epilog, %sw.bb2,
208 %rval = load i32, i32* %retval, align 4
212 ; https://llvm.org/bugs/show_bug.cgi?id=29009
214 @a = global i32 0, align 4
215 @njob = global i32 0, align 4
219 ; Make sure we do not shrink to illegal types (i3 in this case)
220 ; if original type is legal (i32 in this case)
222 define void @PR29009() {
223 ; ALL-LABEL: @PR29009(
225 ; ALL-NEXT: i32 0, label
226 ; ALL-NEXT: i32 3, label
231 ; <label>:1: ; preds = %10, %0
232 %2 = load volatile i32, i32* @njob, align 4
233 %3 = icmp ne i32 %2, 0
234 br i1 %3, label %4, label %11
236 ; <label>:4: ; preds = %1
239 switch i32 %6, label %7 [
244 ; <label>:7: ; preds = %4
245 store i32 6, i32* @a, align 4
248 ; <label>:8: ; preds = %4
249 store i32 1, i32* @a, align 4
252 ; <label>:9: ; preds = %4
253 store i32 2, i32* @a, align 4
256 ; <label>:10: ; preds = %13, %12, %11, %10, %9, %8, %7
259 ; <label>:11: ; preds = %1