llvm.org GIT mirror llvm / f52646d
[ConstantFolding] Consolidate and extend bitcount intrinsic tests; NFC Move constant folding tests into ConstantFolding/bitcount.ll and drop various tests in other places. Add coverage for undefs. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@349806 91177308-0d34-0410-b5e6-96231b3b80d8 Nikita Popov 9 months ago
4 changed file(s) with 187 addition(s) and 57 deletion(s). Raw diff Collapse all Expand all
0 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
1 ; RUN: opt < %s -constprop -S | FileCheck %s
2
3 declare i31 @llvm.ctpop.i31(i31 %val)
4 declare i32 @llvm.cttz.i32(i32 %val, i1)
5 declare i33 @llvm.ctlz.i33(i33 %val, i1)
6 declare <2 x i31> @llvm.ctpop.v2i31(<2 x i31> %val)
7 declare <2 x i32> @llvm.cttz.v2i32(<2 x i32> %val, i1)
8 declare <2 x i33> @llvm.ctlz.v2i33(<2 x i33> %val, i1)
9
10 define i31 @ctpop_const() {
11 ; CHECK-LABEL: @ctpop_const(
12 ; CHECK-NEXT: ret i31 12
13 ;
14 %x = call i31 @llvm.ctpop.i31(i31 12415124)
15 ret i31 %x
16 }
17
18 define i32 @cttz_const() {
19 ; CHECK-LABEL: @cttz_const(
20 ; CHECK-NEXT: ret i32 1
21 ;
22 %x = call i32 @llvm.cttz.i32(i32 87359874, i1 true)
23 ret i32 %x
24 }
25
26 define i33 @ctlz_const() {
27 ; CHECK-LABEL: @ctlz_const(
28 ; CHECK-NEXT: ret i33 6
29 ;
30 %x = call i33 @llvm.ctlz.i33(i33 87359874, i1 true)
31 ret i33 %x
32 }
33
34 define i31 @ctpop_zero() {
35 ; CHECK-LABEL: @ctpop_zero(
36 ; CHECK-NEXT: ret i31 0
37 ;
38 %x = call i31 @llvm.ctpop.i31(i31 0)
39 ret i31 %x
40 }
41
42 define i32 @cttz_zero_defined() {
43 ; CHECK-LABEL: @cttz_zero_defined(
44 ; CHECK-NEXT: ret i32 32
45 ;
46 %x = call i32 @llvm.cttz.i32(i32 0, i1 false)
47 ret i32 %x
48 }
49
50 define i32 @cttz_zero_undefined() {
51 ; CHECK-LABEL: @cttz_zero_undefined(
52 ; CHECK-NEXT: ret i32 undef
53 ;
54 %x = call i32 @llvm.cttz.i32(i32 0, i1 true)
55 ret i32 %x
56 }
57
58 define i33 @ctlz_zero_defined() {
59 ; CHECK-LABEL: @ctlz_zero_defined(
60 ; CHECK-NEXT: ret i33 33
61 ;
62 %x = call i33 @llvm.ctlz.i33(i33 0, i1 false)
63 ret i33 %x
64 }
65
66 define i33 @ctlz_zero_undefined() {
67 ; CHECK-LABEL: @ctlz_zero_undefined(
68 ; CHECK-NEXT: ret i33 undef
69 ;
70 %x = call i33 @llvm.ctlz.i33(i33 0, i1 true)
71 ret i33 %x
72 }
73
74 define i31 @ctpop_undef() {
75 ; CHECK-LABEL: @ctpop_undef(
76 ; CHECK-NEXT: [[X:%.*]] = call i31 @llvm.ctpop.i31(i31 undef)
77 ; CHECK-NEXT: ret i31 [[X]]
78 ;
79 %x = call i31 @llvm.ctpop.i31(i31 undef)
80 ret i31 %x
81 }
82
83 define i32 @cttz_undef_defined() {
84 ; CHECK-LABEL: @cttz_undef_defined(
85 ; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.cttz.i32(i32 undef, i1 false)
86 ; CHECK-NEXT: ret i32 [[X]]
87 ;
88 %x = call i32 @llvm.cttz.i32(i32 undef, i1 false)
89 ret i32 %x
90 }
91
92 define i32 @cttz_undef_undefined() {
93 ; CHECK-LABEL: @cttz_undef_undefined(
94 ; CHECK-NEXT: [[X:%.*]] = call i32 @llvm.cttz.i32(i32 undef, i1 true)
95 ; CHECK-NEXT: ret i32 [[X]]
96 ;
97 %x = call i32 @llvm.cttz.i32(i32 undef, i1 true)
98 ret i32 %x
99 }
100
101 define i33 @ctlz_undef_defined() {
102 ; CHECK-LABEL: @ctlz_undef_defined(
103 ; CHECK-NEXT: [[X:%.*]] = call i33 @llvm.ctlz.i33(i33 undef, i1 false)
104 ; CHECK-NEXT: ret i33 [[X]]
105 ;
106 %x = call i33 @llvm.ctlz.i33(i33 undef, i1 false)
107 ret i33 %x
108 }
109
110 define i33 @ctlz_undef_undefined() {
111 ; CHECK-LABEL: @ctlz_undef_undefined(
112 ; CHECK-NEXT: [[X:%.*]] = call i33 @llvm.ctlz.i33(i33 undef, i1 true)
113 ; CHECK-NEXT: ret i33 [[X]]
114 ;
115 %x = call i33 @llvm.ctlz.i33(i33 undef, i1 true)
116 ret i33 %x
117 }
118
119 define <2 x i31> @ctpop_vector() {
120 ; CHECK-LABEL: @ctpop_vector(
121 ; CHECK-NEXT: ret <2 x i31>
122 ;
123 %x = call <2 x i31> @llvm.ctpop.v2i31(<2 x i31> )
124 ret <2 x i31> %x
125 }
126
127 define <2 x i31> @ctpop_vector_undef() {
128 ; CHECK-LABEL: @ctpop_vector_undef(
129 ; CHECK-NEXT: [[X:%.*]] = call <2 x i31> @llvm.ctpop.v2i31(<2 x i31> )
130 ; CHECK-NEXT: ret <2 x i31> [[X]]
131 ;
132 %x = call <2 x i31> @llvm.ctpop.v2i31(<2 x i31> )
133 ret <2 x i31> %x
134 }
135
136 define <2 x i32> @cttz_vector() {
137 ; CHECK-LABEL: @cttz_vector(
138 ; CHECK-NEXT: ret <2 x i32>
139 ;
140 %x = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> , i1 true)
141 ret <2 x i32> %x
142 }
143
144 define <2 x i32> @cttz_vector_undef_defined() {
145 ; CHECK-LABEL: @cttz_vector_undef_defined(
146 ; CHECK-NEXT: [[X:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> , i1 false)
147 ; CHECK-NEXT: ret <2 x i32> [[X]]
148 ;
149 %x = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> , i1 false)
150 ret <2 x i32> %x
151 }
152
153 define <2 x i32> @cttz_vector_undef_undefined() {
154 ; CHECK-LABEL: @cttz_vector_undef_undefined(
155 ; CHECK-NEXT: [[X:%.*]] = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> , i1 true)
156 ; CHECK-NEXT: ret <2 x i32> [[X]]
157 ;
158 %x = call <2 x i32> @llvm.cttz.v2i32(<2 x i32> , i1 true)
159 ret <2 x i32> %x
160 }
161
162 define <2 x i33> @ctlz_vector() {
163 ; CHECK-LABEL: @ctlz_vector(
164 ; CHECK-NEXT: ret <2 x i33>
165 ;
166 %x = call <2 x i33> @llvm.ctlz.v2i33(<2 x i33> , i1 true)
167 ret <2 x i33> %x
168 }
169
170 define <2 x i33> @ctlz_vector_undef_defined() {
171 ; CHECK-LABEL: @ctlz_vector_undef_defined(
172 ; CHECK-NEXT: [[X:%.*]] = call <2 x i33> @llvm.ctlz.v2i33(<2 x i33> , i1 false)
173 ; CHECK-NEXT: ret <2 x i33> [[X]]
174 ;
175 %x = call <2 x i33> @llvm.ctlz.v2i33(<2 x i33> , i1 false)
176 ret <2 x i33> %x
177 }
178
179 define <2 x i33> @ctlz_vector_undef_undefined() {
180 ; CHECK-LABEL: @ctlz_vector_undef_undefined(
181 ; CHECK-NEXT: [[X:%.*]] = call <2 x i33> @llvm.ctlz.v2i33(<2 x i33> , i1 true)
182 ; CHECK-NEXT: ret <2 x i33> [[X]]
183 ;
184 %x = call <2 x i33> @llvm.ctlz.v2i33(<2 x i33> , i1 true)
185 ret <2 x i33> %x
186 }
+0
-8
test/Transforms/ConstProp/2007-11-23-cttz.ll less more
None ; RUN: opt < %s -constprop -S | grep "ret i13 13"
1 ; PR1816
2 declare i13 @llvm.cttz.i13(i13, i1)
3
4 define i13 @test() {
5 %X = call i13 @llvm.cttz.i13(i13 0, i1 false)
6 ret i13 %X
7 }
+0
-19
test/Transforms/InstCombine/bitcount.ll less more
None ; Tests to make sure bit counts of constants are folded
1 ; RUN: opt < %s -instcombine -S | grep "ret i32 19"
2 ; RUN: opt < %s -instcombine -S | \
3 ; RUN: grep -v declare | not grep llvm.ct
4
5 declare i31 @llvm.ctpop.i31(i31 %val)
6 declare i32 @llvm.cttz.i32(i32 %val, i1)
7 declare i33 @llvm.ctlz.i33(i33 %val, i1)
8
9 define i32 @test(i32 %A) {
10 %c1 = call i31 @llvm.ctpop.i31(i31 12415124)
11 %c2 = call i32 @llvm.cttz.i32(i32 87359874, i1 true)
12 %c3 = call i33 @llvm.ctlz.i33(i33 87359874, i1 true)
13 %t1 = zext i31 %c1 to i32
14 %t3 = trunc i33 %c3 to i32
15 %r1 = add i32 %t1, %c2
16 %r2 = add i32 %r1, %t3
17 ret i32 %r2
18 }
186186 ;
187187 %x = call {i8, i1} @llvm.smul.with.overflow.i8(i8 undef, i8 %V)
188188 ret {i8, i1} %x
189 }
190
191 declare i256 @llvm.cttz.i256(i256 %src, i1 %is_zero_undef)
192
193 define i256 @test_cttz() {
194 ; CHECK-LABEL: @test_cttz(
195 ; CHECK-NEXT: ret i256 1
196 ;
197 %x = call i256 @llvm.cttz.i256(i256 10, i1 false)
198 ret i256 %x
199 }
200
201 declare <2 x i256> @llvm.cttz.v2i256(<2 x i256> %src, i1 %is_zero_undef)
202
203 define <2 x i256> @test_cttz_vec() {
204 ; CHECK-LABEL: @test_cttz_vec(
205 ; CHECK-NEXT: ret <2 x i256>
206 ;
207 %x = call <2 x i256> @llvm.cttz.v2i256(<2 x i256> , i1 false)
208 ret <2 x i256> %x
209 }
210
211 declare i256 @llvm.ctpop.i256(i256 %src)
212
213 define i256 @test_ctpop() {
214 ; CHECK-LABEL: @test_ctpop(
215 ; CHECK-NEXT: ret i256 2
216 ;
217 %x = call i256 @llvm.ctpop.i256(i256 10)
218 ret i256 %x
219189 }
220190
221191 ; Test a non-intrinsic that we know about as a library call.