llvm.org GIT mirror llvm / e392e54
[InstCombine] cttz(-x) -> cttz(x) Summary: Signedness does not change number of trailing zeros. Reviewers: spatel, lebedev.ri, nikic Reviewed By: spatel Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63534 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363951 91177308-0d34-0410-b5e6-96231b3b80d8 David Bolvansky 28 days ago
2 changed file(s) with 32 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
11911191 Intrinsic::ID ID = IsTZ ? Intrinsic::ctlz : Intrinsic::cttz;
11921192 Function *F = Intrinsic::getDeclaration(II.getModule(), ID, II.getType());
11931193 return CallInst::Create(F, {X, II.getArgOperand(1)});
1194 }
1195
1196 // cttz(-x) -> cttz(x)
1197 if (IsTZ && match(Op0, m_Neg(m_Value(X)))) {
1198 II.setOperand(0, X);
1199 return ⅈ
11941200 }
11951201
11961202 KnownBits Known = IC.computeKnownBits(Op0, 0, &II);
22
33 define i32 @cttz_neg_value(i32 %x) {
44 ; CHECK-LABEL: @cttz_neg_value(
5 ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 0, [[X:%.*]]
6 ; CHECK-NEXT: [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[A]], i1 false), !range !0
5 ; CHECK-NEXT: [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false), !range !0
76 ; CHECK-NEXT: ret i32 [[B]]
87 ;
9 %a = sub nsw i32 0, %x
8 %a = sub i32 0, %x
9 %b = tail call i32 @llvm.cttz.i32(i32 %a)
10 ret i32 %b
11 }
12
13 define i32 @cttz_neg_value_multiuse(i32 %x) {
14 ; CHECK-LABEL: @cttz_neg_value_multiuse(
15 ; CHECK-NEXT: [[A:%.*]] = sub i32 0, [[X:%.*]]
16 ; CHECK-NEXT: call void @use(i32 [[A]])
17 ; CHECK-NEXT: [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[X]], i1 false), !range !0
18 ; CHECK-NEXT: ret i32 [[B]]
19 ;
20 %a = sub i32 0, %x
21 call void @use(i32 %a)
1022 %b = tail call i32 @llvm.cttz.i32(i32 %a)
1123 ret i32 %b
1224 }
1325
1426 define i64 @cttz_neg_value_64(i64 %x) {
1527 ; CHECK-LABEL: @cttz_neg_value_64(
16 ; CHECK-NEXT: [[A:%.*]] = sub nsw i64 0, [[X:%.*]]
17 ; CHECK-NEXT: [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[A]], i1 true), !range !1
28 ; CHECK-NEXT: [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X:%.*]], i1 true), !range !1
1829 ; CHECK-NEXT: ret i64 [[B]]
1930 ;
20 %a = sub nsw i64 0, %x
31 %a = sub i64 0, %x
2132 %b = tail call i64 @llvm.cttz.i64(i64 %a, i1 true)
2233 ret i64 %b
2334 }
2435
2536 define i64 @cttz_neg_value2_64(i64 %x) {
2637 ; CHECK-LABEL: @cttz_neg_value2_64(
27 ; CHECK-NEXT: [[A:%.*]] = sub nsw i64 0, [[X:%.*]]
28 ; CHECK-NEXT: [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[A]], i1 false), !range !1
38 ; CHECK-NEXT: [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X:%.*]], i1 false), !range !1
2939 ; CHECK-NEXT: ret i64 [[B]]
3040 ;
31 %a = sub nsw i64 0, %x
41 %a = sub i64 0, %x
3242 %b = tail call i64 @llvm.cttz.i64(i64 %a, i1 false)
3343 ret i64 %b
3444 }
3545
3646 define <2 x i64> @cttz_neg_value_vec(<2 x i64> %x) {
3747 ; CHECK-LABEL: @cttz_neg_value_vec(
38 ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i64> zeroinitializer, [[X:%.*]]
39 ; CHECK-NEXT: [[B:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[A]], i1 false)
48 ; CHECK-NEXT: [[B:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[X:%.*]], i1 false)
4049 ; CHECK-NEXT: ret <2 x i64> [[B]]
4150 ;
42 %a = sub nsw <2 x i64> zeroinitializer, %x
51 %a = sub <2 x i64> zeroinitializer, %x
4352 %b = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %a)
4453 ret <2 x i64> %b
4554 }
4857
4958 define i32 @cttz_nonneg_value(i32 %x) {
5059 ; CHECK-LABEL: @cttz_nonneg_value(
51 ; CHECK-NEXT: [[A:%.*]] = sub nsw i32 1, [[X:%.*]]
60 ; CHECK-NEXT: [[A:%.*]] = sub i32 1, [[X:%.*]]
5261 ; CHECK-NEXT: [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[A]], i1 false), !range !0
5362 ; CHECK-NEXT: ret i32 [[B]]
5463 ;
55 %a = sub nsw i32 1, %x
64 %a = sub i32 1, %x
5665 %b = tail call i32 @llvm.cttz.i32(i32 %a)
5766 ret i32 %b
5867 }
5968
6069 define <2 x i64> @cttz_nonneg_value_vec(<2 x i64> %x) {
6170 ; CHECK-LABEL: @cttz_nonneg_value_vec(
62 ; CHECK-NEXT: [[A:%.*]] = sub nsw <2 x i64> , [[X:%.*]]
71 ; CHECK-NEXT: [[A:%.*]] = sub <2 x i64> , [[X:%.*]]
6372 ; CHECK-NEXT: [[B:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[A]], i1 false)
6473 ; CHECK-NEXT: ret <2 x i64> [[B]]
6574 ;
66 %a = sub nsw <2 x i64> , %x
75 %a = sub <2 x i64> , %x
6776 %b = tail call <2 x i64> @llvm.cttz.v2i64(<2 x i64> %a)
6877 ret <2 x i64> %b
6978 }
7079
80 declare void @use(i32 %a)
7181 declare i32 @llvm.cttz.i32(i32)
7282 declare i64 @llvm.cttz.i64(i64, i1)
7383 declare <2 x i64> @llvm.cttz.v2i64(<2 x i64>)