[llvm] a1fe6be - [InstCombine] remove one-use check for ctpop -> cttz

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 23 11:09:36 PDT 2020


Author: Sanjay Patel
Date: 2020-03-23T13:59:57-04:00
New Revision: a1fe6beb1ec3903e9c9351ae58c6747545189a58

URL: https://github.com/llvm/llvm-project/commit/a1fe6beb1ec3903e9c9351ae58c6747545189a58
DIFF: https://github.com/llvm/llvm-project/commit/a1fe6beb1ec3903e9c9351ae58c6747545189a58.diff

LOG: [InstCombine] remove one-use check for ctpop -> cttz

Two one-use checks were added with rGfdcb27105537,
but only the first one is necessary to limit an
increase in instruction count. The second transform
only creates one instruction, so it is always a
reasonable canonicalization/optimization.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/test/Transforms/InstCombine/ctpop-cttz.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index a234779ba24f..b28da9464933 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -1343,8 +1343,7 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombiner &IC) {
   }
 
   // ctpop(~x & (x - 1)) -> cttz(x, false)
-  if (Op0->hasOneUse() &&
-      match(Op0,
+  if (match(Op0,
             m_c_And(m_Not(m_Value(X)), m_Add(m_Deferred(X), m_AllOnes())))) {
     Function *F =
         Intrinsic::getDeclaration(II.getModule(), Intrinsic::cttz, Ty);

diff  --git a/llvm/test/Transforms/InstCombine/ctpop-cttz.ll b/llvm/test/Transforms/InstCombine/ctpop-cttz.ll
index f1fe9384e3fe..6ac3cfe36bbc 100644
--- a/llvm/test/Transforms/InstCombine/ctpop-cttz.ll
+++ b/llvm/test/Transforms/InstCombine/ctpop-cttz.ll
@@ -78,7 +78,7 @@ define i32 @ctpop2_multiuse(i32 %0) {
 ; CHECK-NEXT:    [[TMP2:%.*]] = xor i32 [[TMP0:%.*]], -1
 ; CHECK-NEXT:    [[TMP3:%.*]] = add i32 [[TMP0]], -1
 ; CHECK-NEXT:    [[TMP4:%.*]] = and i32 [[TMP3]], [[TMP2]]
-; CHECK-NEXT:    [[TMP5:%.*]] = tail call i32 @llvm.ctpop.i32(i32 [[TMP4]]), !range !0
+; CHECK-NEXT:    [[TMP5:%.*]] = call i32 @llvm.cttz.i32(i32 [[TMP0]], i1 false), !range !0
 ; CHECK-NEXT:    [[TMP6:%.*]] = add i32 [[TMP5]], [[TMP4]]
 ; CHECK-NEXT:    ret i32 [[TMP6]]
 ;


        


More information about the llvm-commits mailing list