[PATCH] D63534: [InstCombine] cttz(-x) -> cttz(x)

Dávid Bolvanský via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 19 06:47:51 PDT 2019


xbolva00 updated this revision to Diff 205573.
xbolva00 added a comment.

Uploaded correct patch.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63534/new/

https://reviews.llvm.org/D63534

Files:
  lib/Transforms/InstCombine/InstCombineCalls.cpp
  test/Transforms/InstCombine/cttz-negative.ll


Index: test/Transforms/InstCombine/cttz-negative.ll
===================================================================
--- test/Transforms/InstCombine/cttz-negative.ll
+++ test/Transforms/InstCombine/cttz-negative.ll
@@ -3,8 +3,7 @@
 
 define i32 @cttz_neg_value(i32 %x) {
 ; CHECK-LABEL: @cttz_neg_value(
-; CHECK-NEXT:    [[A:%.*]] = sub nsw i32 0, [[X:%.*]]
-; CHECK-NEXT:    [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[A]], i1 false), !range !0
+; CHECK-NEXT:    [[B:%.*]] = call i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false), !range !0
 ; CHECK-NEXT:    ret i32 [[B]]
 ;
   %a = sub nsw i32 0, %x
@@ -14,8 +13,7 @@
 
 define i64 @cttz_neg_value_64(i64 %x) {
 ; CHECK-LABEL: @cttz_neg_value_64(
-; CHECK-NEXT:    [[A:%.*]] = sub nsw i64 0, [[X:%.*]]
-; CHECK-NEXT:    [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[A]], i1 true), !range !1
+; CHECK-NEXT:    [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X:%.*]], i1 true), !range !1
 ; CHECK-NEXT:    ret i64 [[B]]
 ;
   %a = sub nsw i64 0, %x
@@ -25,8 +23,7 @@
 
 define i64 @cttz_neg_value2_64(i64 %x) {
 ; CHECK-LABEL: @cttz_neg_value2_64(
-; CHECK-NEXT:    [[A:%.*]] = sub nsw i64 0, [[X:%.*]]
-; CHECK-NEXT:    [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[A]], i1 false), !range !1
+; CHECK-NEXT:    [[B:%.*]] = tail call i64 @llvm.cttz.i64(i64 [[X:%.*]], i1 false), !range !1
 ; CHECK-NEXT:    ret i64 [[B]]
 ;
   %a = sub nsw i64 0, %x
@@ -36,8 +33,7 @@
 
 define <2 x i64> @cttz_neg_value_vec(<2 x i64> %x) {
 ; CHECK-LABEL: @cttz_neg_value_vec(
-; CHECK-NEXT:    [[A:%.*]] = sub nsw <2 x i64> zeroinitializer, [[X:%.*]]
-; CHECK-NEXT:    [[B:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[A]], i1 false)
+; CHECK-NEXT:    [[B:%.*]] = call <2 x i64> @llvm.cttz.v2i64(<2 x i64> [[X:%.*]], i1 false)
 ; CHECK-NEXT:    ret <2 x i64> [[B]]
 ;
   %a = sub nsw  <2 x i64> zeroinitializer, %x
Index: lib/Transforms/InstCombine/InstCombineCalls.cpp
===================================================================
--- lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1194,6 +1194,12 @@
     return CallInst::Create(F, {X, II.getArgOperand(1)});
   }
 
+  // cttz(-x) -> cttz(x)
+  if (IsTZ && match(Op0, m_Neg(m_Value(X)))) {
+    II.setOperand(0, X);
+    return &II;
+  }
+
   KnownBits Known = IC.computeKnownBits(Op0, 0, &II);
 
   // Create a mask for bits above (ctlz) or below (cttz) the first known one.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63534.205573.patch
Type: text/x-patch
Size: 2429 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190619/7dd503c3/attachment.bin>


More information about the llvm-commits mailing list