1; RUN: opt < %s -instcombine -S | FileCheck %s
2
3target datalayout = "e-m:o-p:32:32-f64:32:64-v64:32:64-v128:32:128-a:0:32-n32-S32"
4
5; CHECK-LABEL: define i32 @positive1
6; CHECK: switch i32
7; CHECK: i32 10, label
8; CHECK: i32 100, label
9; CHECK: i32 1001, label
10
11define i32 @positive1(i64 %a) {
12entry:
13  %and = and i64 %a, 4294967295
14  switch i64 %and, label %sw.default [
15    i64 10, label %return
16    i64 100, label %sw.bb1
17    i64 1001, label %sw.bb2
18  ]
19
20sw.bb1:
21  br label %return
22
23sw.bb2:
24  br label %return
25
26sw.default:
27  br label %return
28
29return:
30  %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ]
31  ret i32 %retval.0
32}
33
34; CHECK-LABEL: define i32 @negative1
35; CHECK: switch i32
36; CHECK: i32 -10, label
37; CHECK: i32 -100, label
38; CHECK: i32 -1001, label
39
40define i32 @negative1(i64 %a) {
41entry:
42  %or = or i64 %a, -4294967296
43  switch i64 %or, label %sw.default [
44    i64 -10, label %return
45    i64 -100, label %sw.bb1
46    i64 -1001, label %sw.bb2
47  ]
48
49sw.bb1:
50  br label %return
51
52sw.bb2:
53  br label %return
54
55sw.default:
56  br label %return
57
58return:
59  %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ]
60  ret i32 %retval.0
61}
62
63; Make sure truncating a constant int larger than 64-bit doesn't trigger an
64; assertion.
65
66; CHECK-LABEL: define i32 @trunc72to68
67; CHECK: switch i68
68; CHECK: i68 10, label
69; CHECK: i68 100, label
70; CHECK: i68 1001, label
71
72define i32 @trunc72to68(i72 %a) {
73entry:
74  %and = and i72 %a, 295147905179352825855
75  switch i72 %and, label %sw.default [
76    i72 10, label %return
77    i72 100, label %sw.bb1
78    i72 1001, label %sw.bb2
79  ]
80
81sw.bb1:
82  br label %return
83
84sw.bb2:
85  br label %return
86
87sw.default:
88  br label %return
89
90return:
91  %retval.0 = phi i32 [ 24, %sw.default ], [ 123, %sw.bb2 ], [ 213, %sw.bb1 ], [ 231, %entry ]
92  ret i32 %retval.0
93}
94
95; Make sure to avoid assertion crashes and use the type before
96; truncation to generate the sub constant expressions that leads
97; to the recomputed condition.
98;
99; CHECK-LABEL: @trunc64to59
100; CHECK: switch i59
101; CHECK: i59 0, label
102; CHECK: i59 18717182647723699, label
103
104define void @trunc64to59(i64 %a) {
105entry:
106  %tmp0 = and i64 %a, 15
107  %tmp1 = mul i64 %tmp0, -6425668444178048401
108  %tmp2 = add i64 %tmp1, 5170979678563097242
109  %tmp3 = mul i64 %tmp2, 1627972535142754813
110  switch i64 %tmp3, label %sw.default [
111    i64 847514119312061490, label %sw.bb1
112    i64 866231301959785189, label %sw.bb2
113  ]
114
115sw.bb1:
116  br label %sw.default
117
118sw.bb2:
119  br label %sw.default
120
121sw.default:
122  ret void
123}
124