summaryrefslogtreecommitdiff
path: root/lib/Analysis
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@intel.com>2017-12-02 23:42:17 +0000
committerCraig Topper <craig.topper@intel.com>2017-12-02 23:42:17 +0000
commitaa18cf610f184dcfc10e86d98f5224c1e8702306 (patch)
tree755519e744fa5bed49d5ee0bf542d2e920d7d9ec /lib/Analysis
parentdcc00b1fac4cb2298c76322332c8fb94a174e30a (diff)
[ValueTracking] Pass only a single lambda to computeKnownBitsFromShiftOperator by using KnownBits struct instead of separate APInts. NFCI
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@319624 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis')
-rw-r--r--lib/Analysis/ValueTracking.cpp66
1 files changed, 29 insertions, 37 deletions
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index 106a4a71f93..8020afffd45 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -795,16 +795,14 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
static void computeKnownBitsFromShiftOperator(
const Operator *I, KnownBits &Known, KnownBits &Known2,
unsigned Depth, const Query &Q,
- function_ref<APInt(const APInt &, unsigned)> KZF,
- function_ref<APInt(const APInt &, unsigned)> KOF) {
+ function_ref<KnownBits(KnownBits, unsigned)> KBF) {
unsigned BitWidth = Known.getBitWidth();
if (auto *SA = dyn_cast<ConstantInt>(I->getOperand(1))) {
unsigned ShiftAmt = SA->getLimitedValue(BitWidth-1);
computeKnownBits(I->getOperand(0), Known, Depth + 1, Q);
- Known.Zero = KZF(Known.Zero, ShiftAmt);
- Known.One = KOF(Known.One, ShiftAmt);
+ Known = KBF(Known, ShiftAmt);
// If the known bits conflict, this must be an overflowing left shift, so
// the shift result is poison. We can return anything we want. Choose 0 for
// the best folding opportunity.
@@ -869,8 +867,9 @@ static void computeKnownBitsFromShiftOperator(
continue;
}
- Known.Zero &= KZF(Known2.Zero, ShiftAmt);
- Known.One &= KOF(Known2.One, ShiftAmt);
+ Known2 = KBF(Known2, ShiftAmt);
+ Known.Zero &= Known2.Zero;
+ Known.One &= Known2.One;
}
// If the known bits conflict, the result is poison. Return a 0 and hope the
@@ -1068,53 +1067,46 @@ static void computeKnownBitsFromOperator(const Operator *I, KnownBits &Known,
case Instruction::Shl: {
// (shl X, C1) & C2 == 0 iff (X & C2 >>u C1) == 0
bool NSW = cast<OverflowingBinaryOperator>(I)->hasNoSignedWrap();
- auto KZF = [NSW](const APInt &KnownZero, unsigned ShiftAmt) {
- APInt KZResult = KnownZero << ShiftAmt;
- KZResult.setLowBits(ShiftAmt); // Low bits known 0.
+ auto KBF = [NSW](const KnownBits &Known, unsigned ShiftAmt) {
+ KnownBits Result;
+ Result.Zero = Known.Zero << ShiftAmt;
+ Result.Zero.setLowBits(ShiftAmt); // Low bits known 0.
+ Result.One = Known.One << ShiftAmt;
// If this shift has "nsw" keyword, then the result is either a poison
// value or has the same sign bit as the first operand.
- if (NSW && KnownZero.isSignBitSet())
- KZResult.setSignBit();
- return KZResult;
- };
-
- auto KOF = [NSW](const APInt &KnownOne, unsigned ShiftAmt) {
- APInt KOResult = KnownOne << ShiftAmt;
- if (NSW && KnownOne.isSignBitSet())
- KOResult.setSignBit();
- return KOResult;
+ if (NSW && Known.isNonNegative())
+ Result.Zero.setSignBit();
+ if (NSW && Known.isNegative())
+ Result.One.setSignBit();
+ return Result;
};
- computeKnownBitsFromShiftOperator(I, Known, Known2, Depth, Q, KZF, KOF);
+ computeKnownBitsFromShiftOperator(I, Known, Known2, Depth, Q, KBF);
break;
}
case Instruction::LShr: {
// (lshr X, C1) & C2 == 0 iff (-1 >> C1) & C2 == 0
- auto KZF = [](const APInt &KnownZero, unsigned ShiftAmt) {
- APInt KZResult = KnownZero.lshr(ShiftAmt);
- // High bits known zero.
- KZResult.setHighBits(ShiftAmt);
- return KZResult;
+ auto KBF = [](const KnownBits &Known, unsigned ShiftAmt) {
+ KnownBits Result;
+ Result.Zero = Known.Zero.lshr(ShiftAmt);
+ Result.Zero.setHighBits(ShiftAmt); // High bits known zero.
+ Result.One = Known.One.lshr(ShiftAmt);
+ return Result;
};
- auto KOF = [](const APInt &KnownOne, unsigned ShiftAmt) {
- return KnownOne.lshr(ShiftAmt);
- };
-
- computeKnownBitsFromShiftOperator(I, Known, Known2, Depth, Q, KZF, KOF);
+ computeKnownBitsFromShiftOperator(I, Known, Known2, Depth, Q, KBF);
break;
}
case Instruction::AShr: {
// (ashr X, C1) & C2 == 0 iff (-1 >> C1) & C2 == 0
- auto KZF = [](const APInt &KnownZero, unsigned ShiftAmt) {
- return KnownZero.ashr(ShiftAmt);
- };
-
- auto KOF = [](const APInt &KnownOne, unsigned ShiftAmt) {
- return KnownOne.ashr(ShiftAmt);
+ auto KBF = [](const KnownBits &Known, unsigned ShiftAmt) {
+ KnownBits Result;
+ Result.Zero = Known.Zero.ashr(ShiftAmt);
+ Result.One = Known.One.ashr(ShiftAmt);
+ return Result;
};
- computeKnownBitsFromShiftOperator(I, Known, Known2, Depth, Q, KZF, KOF);
+ computeKnownBitsFromShiftOperator(I, Known, Known2, Depth, Q, KBF);
break;
}
case Instruction::Sub: {