[llvm] r279072 - [InstCombine] use APInt in isSignTest instead of ConstantInt; NFC

Sanjay Patel via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 07:59:14 PDT 2016


Author: spatel
Date: Thu Aug 18 09:59:14 2016
New Revision: 279072

URL: http://llvm.org/viewvc/llvm-project?rev=279072&view=rev
Log:
[InstCombine] use APInt in isSignTest instead of ConstantInt; NFC

This will enable vector splat folding, but NFC until the callers
have their ConstantInt restrictions removed.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp?rev=279072&r1=279071&r2=279072&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCompares.cpp Thu Aug 18 09:59:14 2016
@@ -154,19 +154,20 @@ static bool isSignBitCheck(ICmpInst::Pre
 /// Returns true if the exploded icmp can be expressed as a signed comparison
 /// to zero and updates the predicate accordingly.
 /// The signedness of the comparison is preserved.
-static bool isSignTest(ICmpInst::Predicate &Pred, const ConstantInt *RHS) {
+/// TODO: Refactor with decomposeBitTestICmp()?
+static bool isSignTest(ICmpInst::Predicate &Pred, const APInt &C) {
   if (!ICmpInst::isSigned(Pred))
     return false;
 
-  if (RHS->isZero())
+  if (C == 0)
     return ICmpInst::isRelational(Pred);
 
-  if (RHS->isOne()) {
+  if (C == 1) {
     if (Pred == ICmpInst::ICMP_SLT) {
       Pred = ICmpInst::ICMP_SLE;
       return true;
     }
-  } else if (RHS->isAllOnesValue()) {
+  } else if (C.isAllOnesValue()) {
     if (Pred == ICmpInst::ICMP_SGT) {
       Pred = ICmpInst::ICMP_SGE;
       return true;
@@ -1919,7 +1920,7 @@ Instruction *InstCombiner::foldICmpMulCo
   // If this is a signed comparison to 0 and the mul is sign preserving,
   // use the mul LHS operand instead.
   ICmpInst::Predicate pred = ICI.getPredicate();
-  if (isSignTest(pred, RHS) && !Val->isZero() &&
+  if (isSignTest(pred, *RHSV) && !Val->isZero() &&
       cast<BinaryOperator>(LHSI)->hasNoSignedWrap())
     return new ICmpInst(Val->isNegative() ?
                         ICmpInst::getSwappedPredicate(pred) : pred,
@@ -2045,7 +2046,7 @@ Instruction *InstCombiner::foldICmpShlCo
   // If this is a signed comparison to 0 and the shift is sign preserving,
   // use the shift LHS operand instead.
   ICmpInst::Predicate pred = ICI.getPredicate();
-  if (isSignTest(pred, RHS) && cast<BinaryOperator>(LHSI)->hasNoSignedWrap())
+  if (isSignTest(pred, *RHSV) && cast<BinaryOperator>(LHSI)->hasNoSignedWrap())
     return new ICmpInst(pred, LHSI->getOperand(0),
                         Constant::getNullValue(RHS->getType()));
 




More information about the llvm-commits mailing list