[llvm] r301338 - [APInt] Use isSubsetOf, intersects, and bit counting methods to reduce temporary APInts
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 25 10:46:30 PDT 2017
Author: ctopper
Date: Tue Apr 25 12:46:30 2017
New Revision: 301338
URL: http://llvm.org/viewvc/llvm-project?rev=301338&view=rev
Log:
[APInt] Use isSubsetOf, intersects, and bit counting methods to reduce temporary APInts
This patch uses various APInt methods to reduce temporary APInt creation.
This should be all of the unrelated cleanups that got buried in D32376(creating a KnownBits struct) as well as some pointed out by Simon during the review of that. Plus a few improvements to use counting instead of masking.
I've left out any places where we do something like (KnownZero & KnownOne) != 0 as I plan to add a helper method to KnownBits to ask that question and didn't want to thrash that code an additional time.
Differential Revision: https://reviews.llvm.org/D32495
Modified:
llvm/trunk/lib/Analysis/InstructionSimplify.cpp
llvm/trunk/lib/Analysis/ValueTracking.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
Modified: llvm/trunk/lib/Analysis/InstructionSimplify.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/InstructionSimplify.cpp?rev=301338&r1=301337&r2=301338&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/InstructionSimplify.cpp (original)
+++ llvm/trunk/lib/Analysis/InstructionSimplify.cpp Tue Apr 25 12:46:30 2017
@@ -1376,8 +1376,7 @@ static Value *SimplifyShift(Instruction:
// If all valid bits in the shift amount are known zero, the first operand is
// unchanged.
unsigned NumValidShiftBits = Log2_32_Ceil(BitWidth);
- APInt ShiftAmountMask = APInt::getLowBitsSet(BitWidth, NumValidShiftBits);
- if ((KnownZero & ShiftAmountMask) == ShiftAmountMask)
+ if (KnownZero.countTrailingOnes() >= NumValidShiftBits)
return Op0;
return nullptr;
@@ -3372,7 +3371,7 @@ static Value *SimplifyICmpInst(unsigned
APInt LHSKnownOne(BitWidth, 0);
computeKnownBits(LHS, LHSKnownZero, LHSKnownOne, Q.DL, /*Depth=*/0, Q.AC,
Q.CxtI, Q.DT);
- if (((LHSKnownZero & *RHSVal) != 0) || ((LHSKnownOne & ~(*RHSVal)) != 0))
+ if (LHSKnownZero.intersects(*RHSVal) || !LHSKnownOne.isSubsetOf(*RHSVal))
return Pred == ICmpInst::ICMP_EQ ? ConstantInt::getFalse(ITy)
: ConstantInt::getTrue(ITy);
}
Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=301338&r1=301337&r2=301338&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp Tue Apr 25 12:46:30 2017
@@ -1934,12 +1934,12 @@ bool isKnownNonZero(const Value *V, unsi
// The sign bit of X is set. If some other bit is set then X is not equal
// to INT_MIN.
computeKnownBits(X, KnownZero, KnownOne, Depth, Q);
- if ((KnownOne & Mask) != 0)
+ if (KnownOne.intersects(Mask))
return true;
// The sign bit of Y is set. If some other bit is set then Y is not equal
// to INT_MIN.
computeKnownBits(Y, KnownZero, KnownOne, Depth, Q);
- if ((KnownOne & Mask) != 0)
+ if (KnownOne.intersects(Mask))
return true;
}
@@ -2056,7 +2056,7 @@ bool MaskedValueIsZero(const Value *V, c
const Query &Q) {
APInt KnownZero(Mask.getBitWidth(), 0), KnownOne(Mask.getBitWidth(), 0);
computeKnownBits(V, KnownZero, KnownOne, Depth, Q);
- return (KnownZero & Mask) == Mask;
+ return Mask.isSubsetOf(KnownZero);
}
/// For vector constants, loop over the elements and find the constant with the
@@ -4289,7 +4289,7 @@ static bool isTruePredicate(CmpInst::Pre
APInt KnownZero(BitWidth, 0), KnownOne(BitWidth, 0);
computeKnownBits(X, KnownZero, KnownOne, DL, Depth + 1, AC, CxtI, DT);
- if ((KnownZero & *CA) == *CA && (KnownZero & *CB) == *CB)
+ if (CA->isSubsetOf(KnownZero) && CB->isSubsetOf(KnownZero))
return true;
}
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp?rev=301338&r1=301337&r2=301338&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineCalls.cpp Tue Apr 25 12:46:30 2017
@@ -1393,7 +1393,7 @@ static Instruction *foldCttzCtlz(Intrins
// zero, this value is constant.
// FIXME: This should be in InstSimplify because we're replacing an
// instruction with a constant.
- if ((Mask & KnownZero) == Mask) {
+ if (Mask.isSubsetOf(KnownZero)) {
auto *C = ConstantInt::get(IT, APInt(BitWidth, NumMaskBits));
return IC.replaceInstUsesWith(II, C);
}
Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp?rev=301338&r1=301337&r2=301338&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp Tue Apr 25 12:46:30 2017
@@ -453,11 +453,11 @@ Value *InstCombiner::SimplifyDemandedUse
// If we are known to be adding/subtracting zeros to every bit below
// the highest demanded bit, we just return the other side.
- if ((DemandedFromOps & RHSKnownZero) == DemandedFromOps)
+ if (DemandedFromOps.isSubsetOf(RHSKnownZero))
return I->getOperand(0);
// We can't do this with the LHS for subtraction.
if (I->getOpcode() == Instruction::Add &&
- (DemandedFromOps & LHSKnownZero) == DemandedFromOps)
+ DemandedFromOps.isSubsetOf(LHSKnownZero))
return I->getOperand(1);
}
Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=301338&r1=301337&r2=301338&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Tue Apr 25 12:46:30 2017
@@ -4380,7 +4380,7 @@ static bool EliminateDeadSwitchCases(Swi
SmallVector<ConstantInt *, 8> DeadCases;
for (auto &Case : SI->cases()) {
APInt CaseVal = Case.getCaseValue()->getValue();
- if ((CaseVal & KnownZero) != 0 || (CaseVal & KnownOne) != KnownOne ||
+ if (KnownZero.intersects(CaseVal) || !KnownOne.isSubsetOf(CaseVal) ||
(CaseVal.getMinSignedBits() > MaxSignificantBitsInCond)) {
DeadCases.push_back(Case.getCaseValue());
DEBUG(dbgs() << "SimplifyCFG: switch case " << CaseVal << " is dead.\n");
Modified: llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp?rev=301338&r1=301337&r2=301338&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp (original)
+++ llvm/trunk/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp Tue Apr 25 12:46:30 2017
@@ -331,8 +331,7 @@ bool Vectorizer::isConsecutiveAccess(Val
APInt KnownZero(BitWidth, 0);
APInt KnownOne(BitWidth, 0);
computeKnownBits(OpA, KnownZero, KnownOne, DL, 0, nullptr, OpA, &DT);
- KnownZero &= ~APInt::getHighBitsSet(BitWidth, 1);
- if (KnownZero != 0)
+ if (KnownZero.countTrailingZeros() < (BitWidth - 1))
Safe = true;
}
More information about the llvm-commits
mailing list