[SimplifyLibCalls] Turn memchr(const, C, const) into a bitfield check.
[oota-llvm.git] / test / Transforms / InstCombine / assume2.ll
1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3 target triple = "x86_64-unknown-linux-gnu"
4
5 ; Function Attrs: nounwind
6 declare void @llvm.assume(i1) #1
7
8 ; Function Attrs: nounwind uwtable
9 define i32 @test1(i32 %a) #0 {
10 entry:
11 ; CHECK-LABEL: @test1
12 ; CHECK: call void @llvm.assume
13 ; CHECK: ret i32 5
14
15   %and = and i32 %a, 15
16   %cmp = icmp eq i32 %and, 5
17   tail call void @llvm.assume(i1 %cmp)
18
19   %and1 = and i32 %a, 7
20   ret i32 %and1
21 }
22
23 ; Function Attrs: nounwind uwtable
24 define i32 @test2(i32 %a) #0 {
25 entry:
26 ; CHECK-LABEL: @test2
27 ; CHECK: call void @llvm.assume
28 ; CHECK: ret i32 2
29
30   %and = and i32 %a, 15
31   %nand = xor i32 %and, -1
32   %cmp = icmp eq i32 %nand, 4294967285
33   tail call void @llvm.assume(i1 %cmp)
34
35   %and1 = and i32 %a, 7
36   ret i32 %and1
37 }
38
39 ; Function Attrs: nounwind uwtable
40 define i32 @test3(i32 %a) #0 {
41 entry:
42 ; CHECK-LABEL: @test3
43 ; CHECK: call void @llvm.assume
44 ; CHECK: ret i32 5
45
46   %v = or i32 %a, 4294967280
47   %cmp = icmp eq i32 %v, 4294967285
48   tail call void @llvm.assume(i1 %cmp)
49
50   %and1 = and i32 %a, 7
51   ret i32 %and1
52 }
53
54 ; Function Attrs: nounwind uwtable
55 define i32 @test4(i32 %a) #0 {
56 entry:
57 ; CHECK-LABEL: @test4
58 ; CHECK: call void @llvm.assume
59 ; CHECK: ret i32 2
60
61   %v = or i32 %a, 4294967280
62   %nv = xor i32 %v, -1
63   %cmp = icmp eq i32 %nv, 5
64   tail call void @llvm.assume(i1 %cmp)
65
66   %and1 = and i32 %a, 7
67   ret i32 %and1
68 }
69
70 ; Function Attrs: nounwind uwtable
71 define i32 @test5(i32 %a) #0 {
72 entry:
73 ; CHECK-LABEL: @test5
74 ; CHECK: call void @llvm.assume
75 ; CHECK: ret i32 4
76
77   %v = xor i32 %a, 1
78   %cmp = icmp eq i32 %v, 5
79   tail call void @llvm.assume(i1 %cmp)
80
81   %and1 = and i32 %a, 7
82   ret i32 %and1
83 }
84
85 ; Function Attrs: nounwind uwtable
86 define i32 @test6(i32 %a) #0 {
87 entry:
88 ; CHECK-LABEL: @test6
89 ; CHECK: call void @llvm.assume
90 ; CHECK: ret i32 5
91
92   %v = shl i32 %a, 2
93   %cmp = icmp eq i32 %v, 20
94   tail call void @llvm.assume(i1 %cmp)
95
96   %and1 = and i32 %a, 63
97   ret i32 %and1
98 }
99
100 ; Function Attrs: nounwind uwtable
101 define i32 @test7(i32 %a) #0 {
102 entry:
103 ; CHECK-LABEL: @test7
104 ; CHECK: call void @llvm.assume
105 ; CHECK: ret i32 20
106
107   %v = lshr i32 %a, 2
108   %cmp = icmp eq i32 %v, 5
109   tail call void @llvm.assume(i1 %cmp)
110
111   %and1 = and i32 %a, 252
112   ret i32 %and1
113 }
114
115 ; Function Attrs: nounwind uwtable
116 define i32 @test8(i32 %a) #0 {
117 entry:
118 ; CHECK-LABEL: @test8
119 ; CHECK: call void @llvm.assume
120 ; CHECK: ret i32 20
121
122   %v = lshr i32 %a, 2
123   %cmp = icmp eq i32 %v, 5
124   tail call void @llvm.assume(i1 %cmp)
125
126   %and1 = and i32 %a, 252
127   ret i32 %and1
128 }
129
130 ; Function Attrs: nounwind uwtable
131 define i32 @test9(i32 %a) #0 {
132 entry:
133 ; CHECK-LABEL: @test9
134 ; CHECK: call void @llvm.assume
135 ; CHECK: ret i32 0
136
137   %cmp = icmp sgt i32 %a, 5
138   tail call void @llvm.assume(i1 %cmp)
139
140   %and1 = and i32 %a, 2147483648
141   ret i32 %and1
142 }
143
144 ; Function Attrs: nounwind uwtable
145 define i32 @test10(i32 %a) #0 {
146 entry:
147 ; CHECK-LABEL: @test10
148 ; CHECK: call void @llvm.assume
149 ; CHECK: ret i32 -2147483648
150
151   %cmp = icmp sle i32 %a, -2
152   tail call void @llvm.assume(i1 %cmp)
153
154   %and1 = and i32 %a, 2147483648
155   ret i32 %and1
156 }
157
158 ; Function Attrs: nounwind uwtable
159 define i32 @test11(i32 %a) #0 {
160 entry:
161 ; CHECK-LABEL: @test11
162 ; CHECK: call void @llvm.assume
163 ; CHECK: ret i32 0
164
165   %cmp = icmp ule i32 %a, 256
166   tail call void @llvm.assume(i1 %cmp)
167
168   %and1 = and i32 %a, 3072
169   ret i32 %and1
170 }
171
172 attributes #0 = { nounwind uwtable }
173 attributes #1 = { nounwind }
174