[llvm] 198b79c - [InstCombine] move bitmanipulation-of-select folds

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 21 08:32:28 PDT 2021


Author: Sanjay Patel
Date: 2021-06-21T11:32:16-04:00
New Revision: 198b79caae4ff01f146e311d2db14bfe13f098ad

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

LOG: [InstCombine] move bitmanipulation-of-select folds

This is no outwardly-visible-difference-intended,
but it is obviously better to have all transforms
for an intrinsic housed together since we already
have helper functions in place.

It is also potentially more efficient to zap a
simple pattern match before trying to do expensive
computeKnownBits() calls.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 556550b7c22b..13d20b882150 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -454,6 +454,11 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombinerImpl &IC) {
     return IC.replaceInstUsesWith(II, ConstantInt::getNullValue(II.getType()));
   }
 
+  // If the operand is a select with constant arm(s), try to hoist ctlz/cttz.
+  if (auto *Sel = dyn_cast<SelectInst>(Op0))
+    if (Instruction *R = IC.FoldOpIntoSelect(II, Sel))
+      return R;
+
   if (IsTZ) {
     // cttz(-x) -> cttz(x)
     if (match(Op0, m_Neg(m_Value(X))))
@@ -573,6 +578,11 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombinerImpl &IC) {
     return CastInst::Create(Instruction::ZExt, NarrowPop, Ty);
   }
 
+  // If the operand is a select with constant arm(s), try to hoist ctpop.
+  if (auto *Sel = dyn_cast<SelectInst>(Op0))
+    if (Instruction *R = IC.FoldOpIntoSelect(II, Sel))
+      return R;
+
   KnownBits Known(BitWidth);
   IC.computeKnownBits(Op0, Known, 0, &II);
 
@@ -1080,21 +1090,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
   case Intrinsic::ctlz:
     if (auto *I = foldCttzCtlz(*II, *this))
       return I;
-
-    // If the operand is a select with constant arm(s), try to hoist ctlz/cttz.
-    if (auto *Sel = dyn_cast<SelectInst>(II->getArgOperand(0)))
-      if (Instruction *R = FoldOpIntoSelect(*II, Sel))
-        return R;
     break;
 
   case Intrinsic::ctpop:
     if (auto *I = foldCtpop(*II, *this))
       return I;
-
-    // If the operand is a select with constant arm(s), try to hoist ctpop.
-    if (auto *Sel = dyn_cast<SelectInst>(II->getArgOperand(0)))
-      if (Instruction *R = FoldOpIntoSelect(*II, Sel))
-        return R;
     break;
 
   case Intrinsic::fshl:


        


More information about the llvm-commits mailing list