1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
6 declare i32 @llvm.ctpop.i32(i32)
7 declare i32 @llvm.ctlz.i32(i32, i1)
8 declare i32 @llvm.cttz.i32(i32, i1)
10 define i64 @test1(i32 %x) {
11 ; CHECK-LABEL: @test1(
12 ; CHECK-NEXT: [[T:%.*]] = call i32 @llvm.ctpop.i32(i32 %x)
13 ; CHECK-NEXT: [[S1:%.*]] = zext i32 [[T]] to i64
14 ; CHECK-NEXT: ret i64 [[S1]]
16 %t = call i32 @llvm.ctpop.i32(i32 %x)
17 %s = sext i32 %t to i64
21 define i64 @test2(i32 %x) {
22 ; CHECK-LABEL: @test2(
23 ; CHECK-NEXT: [[T:%.*]] = call i32 @llvm.ctlz.i32(i32 %x, i1 true)
24 ; CHECK-NEXT: [[S1:%.*]] = zext i32 [[T]] to i64
25 ; CHECK-NEXT: ret i64 [[S1]]
27 %t = call i32 @llvm.ctlz.i32(i32 %x, i1 true)
28 %s = sext i32 %t to i64
32 define i64 @test3(i32 %x) {
33 ; CHECK-LABEL: @test3(
34 ; CHECK-NEXT: [[T:%.*]] = call i32 @llvm.cttz.i32(i32 %x, i1 true)
35 ; CHECK-NEXT: [[S1:%.*]] = zext i32 [[T]] to i64
36 ; CHECK-NEXT: ret i64 [[S1]]
38 %t = call i32 @llvm.cttz.i32(i32 %x, i1 true)
39 %s = sext i32 %t to i64
43 define i64 @test4(i32 %x) {
44 ; CHECK-LABEL: @test4(
45 ; CHECK-NEXT: [[T:%.*]] = udiv i32 %x, 3
46 ; CHECK-NEXT: [[S1:%.*]] = zext i32 [[T]] to i64
47 ; CHECK-NEXT: ret i64 [[S1]]
50 %s = sext i32 %t to i64
54 define i64 @test5(i32 %x) {
55 ; CHECK-LABEL: @test5(
56 ; CHECK-NEXT: [[T:%.*]] = urem i32 %x, 30000
57 ; CHECK-NEXT: [[S1:%.*]] = zext i32 [[T]] to i64
58 ; CHECK-NEXT: ret i64 [[S1]]
60 %t = urem i32 %x, 30000
61 %s = sext i32 %t to i64
65 define i64 @test6(i32 %x) {
66 ; CHECK-LABEL: @test6(
67 ; CHECK-NEXT: [[U:%.*]] = lshr i32 %x, 3
68 ; CHECK-NEXT: [[T:%.*]] = mul nuw nsw i32 [[U]], 3
69 ; CHECK-NEXT: [[S1:%.*]] = zext i32 [[T]] to i64
70 ; CHECK-NEXT: ret i64 [[S1]]
74 %s = sext i32 %t to i64
78 define i64 @test7(i32 %x) {
79 ; CHECK-LABEL: @test7(
80 ; CHECK-NEXT: [[T:%.*]] = and i32 %x, 511
81 ; CHECK-NEXT: [[U:%.*]] = sub nuw nsw i32 20000, [[T]]
82 ; CHECK-NEXT: [[S1:%.*]] = zext i32 [[U]] to i64
83 ; CHECK-NEXT: ret i64 [[S1]]
86 %u = sub i32 20000, %t
87 %s = sext i32 %u to i64
91 define i32 @test8(i8 %a, i32 %f, i1 %p, i32* %z) {
92 ; CHECK-LABEL: @test8(
93 ; CHECK-NEXT: [[D:%.*]] = lshr i32 %f, 24
94 ; CHECK-NEXT: [[N:%.*]] = select i1 %p, i32 [[D]], i32 0
95 ; CHECK-NEXT: ret i32 [[N]]
98 %e = select i1 %p, i32 %d, i32 0
99 %s = trunc i32 %e to i16
100 %n = sext i16 %s to i32
105 define i16 @test9(i16 %t, i1 %cond) {
106 ; CHECK-LABEL: @test9(
108 ; CHECK-NEXT: br i1 %cond, label %T, label %F
110 ; CHECK-NEXT: br label %F
112 ; CHECK-NEXT: [[V_OFF0:%.*]] = phi i16 [ %t, %T ], [ 42, %entry ]
113 ; CHECK-NEXT: ret i16 [[V_OFF0]]
116 br i1 %cond, label %T, label %F
118 %t2 = sext i16 %t to i32
122 %V = phi i32 [%t2, %T], [42, %entry]
123 %W = trunc i32 %V to i16
128 define i32 @test10(i32 %i) {
129 ; CHECK-LABEL: @test10(
130 ; CHECK-NEXT: [[B1:%.*]] = shl i32 %i, 30
131 ; CHECK-NEXT: [[B:%.*]] = ashr exact i32 [[B1]], 30
132 ; CHECK-NEXT: ret i32 [[B]]
134 %tmp12 = trunc i32 %i to i8
135 %tmp16 = shl i8 %tmp12, 6
136 %a = ashr i8 %tmp16, 6
137 %b = sext i8 %a to i32
141 define void @test11(<2 x i16> %srcA, <2 x i16> %srcB, <2 x i16>* %dst) {
142 ; CHECK-LABEL: @test11(
143 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq <2 x i16> %srcB, %srcA
144 ; CHECK-NEXT: [[SEXT:%.*]] = sext <2 x i1> [[CMP]] to <2 x i16>
145 ; CHECK-NEXT: store <2 x i16> [[SEXT]], <2 x i16>* %dst, align 4
146 ; CHECK-NEXT: ret void
148 %cmp = icmp eq <2 x i16> %srcB, %srcA
149 %sext = sext <2 x i1> %cmp to <2 x i16>
150 %tmask = ashr <2 x i16> %sext, <i16 15, i16 15>
151 store <2 x i16> %tmask, <2 x i16>* %dst
155 define i64 @test12(i32 %x) {
156 ; CHECK-LABEL: @test12(
157 ; CHECK-NEXT: [[SHR:%.*]] = lshr i32 %x, 1
158 ; CHECK-NEXT: [[SUB:%.*]] = sub nsw i32 0, [[SHR]]
159 ; CHECK-NEXT: [[CONV:%.*]] = sext i32 [[SUB]] to i64
160 ; CHECK-NEXT: ret i64 [[CONV]]
162 %shr = lshr i32 %x, 1
163 %sub = sub nsw i32 0, %shr
164 %conv = sext i32 %sub to i64
168 define i32 @test13(i32 %x) {
169 ; CHECK-LABEL: @test13(
170 ; CHECK-NEXT: [[AND:%.*]] = lshr i32 %x, 3
171 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[AND]], 1
172 ; CHECK-NEXT: [[SEXT:%.*]] = add nsw i32 [[TMP1]], -1
173 ; CHECK-NEXT: ret i32 [[SEXT]]
176 %cmp = icmp eq i32 %and, 0
177 %ext = sext i1 %cmp to i32
181 define i32 @test14(i16 %x) {
182 ; CHECK-LABEL: @test14(
183 ; CHECK-NEXT: [[AND:%.*]] = lshr i16 %x, 4
184 ; CHECK-NEXT: [[TMP1:%.*]] = and i16 [[AND]], 1
185 ; CHECK-NEXT: [[SEXT:%.*]] = add nsw i16 [[TMP1]], -1
186 ; CHECK-NEXT: [[EXT:%.*]] = sext i16 [[SEXT]] to i32
187 ; CHECK-NEXT: ret i32 [[EXT]]
189 %and = and i16 %x, 16
190 %cmp = icmp ne i16 %and, 16
191 %ext = sext i1 %cmp to i32
195 define i32 @test15(i32 %x) {
196 ; CHECK-LABEL: @test15(
197 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 %x, 27
198 ; CHECK-NEXT: [[SEXT:%.*]] = ashr i32 [[TMP1]], 31
199 ; CHECK-NEXT: ret i32 [[SEXT]]
201 %and = and i32 %x, 16
202 %cmp = icmp ne i32 %and, 0
203 %ext = sext i1 %cmp to i32
207 define i32 @test16(i16 %x) {
208 ; CHECK-LABEL: @test16(
209 ; CHECK-NEXT: [[TMP1:%.*]] = shl i16 %x, 12
210 ; CHECK-NEXT: [[SEXT:%.*]] = ashr i16 [[TMP1]], 15
211 ; CHECK-NEXT: [[EXT:%.*]] = sext i16 [[SEXT]] to i32
212 ; CHECK-NEXT: ret i32 [[EXT]]
215 %cmp = icmp eq i16 %and, 8
216 %ext = sext i1 %cmp to i32
220 define i32 @test17(i1 %x) {
221 ; CHECK-LABEL: @test17(
222 ; CHECK-NEXT: [[C2:%.*]] = zext i1 %x to i32
223 ; CHECK-NEXT: ret i32 [[C2]]
225 %c1 = sext i1 %x to i32
230 define i32 @test18(i16 %x) {
231 ; CHECK-LABEL: @test18(
232 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i16 %x, 0
233 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[TMP1]], i16 %x, i16 0
234 ; CHECK-NEXT: [[TMP2:%.*]] = zext i16 [[SEL]] to i32
235 ; CHECK-NEXT: ret i32 [[TMP2]]
237 %cmp = icmp slt i16 %x, 0
238 %sel = select i1 %cmp, i16 0, i16 %x
239 %ext = sext i16 %sel to i32