[llvm] f72d350 - [ValueTracking] Update computeKnownBitsFromShiftOperator callbacks to take KnownBits shift amount. NFCI.
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 12 08:57:43 PST 2020
Author: Simon Pilgrim
Date: 2020-11-12T16:56:55Z
New Revision: f72d350bfb6a2250cc7b8d54c8b412821426cdc5
URL: https://github.com/llvm/llvm-project/commit/f72d350bfb6a2250cc7b8d54c8b412821426cdc5
DIFF: https://github.com/llvm/llvm-project/commit/f72d350bfb6a2250cc7b8d54c8b412821426cdc5.diff
LOG: [ValueTracking] Update computeKnownBitsFromShiftOperator callbacks to take KnownBits shift amount. NFCI.
We were creating this internally, but will need to support general KnownBits amounts as part of D90479.
Added:
Modified:
llvm/lib/Analysis/ValueTracking.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index 8568a23f2f9a..b369f2697e5c 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -987,14 +987,14 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known,
static void computeKnownBitsFromShiftOperator(
const Operator *I, const APInt &DemandedElts, KnownBits &Known,
KnownBits &Known2, unsigned Depth, const Query &Q,
- function_ref<KnownBits(const KnownBits &, unsigned)> KF) {
+ function_ref<KnownBits(const KnownBits &, const KnownBits &)> KF) {
unsigned BitWidth = Known.getBitWidth();
computeKnownBits(I->getOperand(0), DemandedElts, Known2, Depth + 1, Q);
computeKnownBits(I->getOperand(1), DemandedElts, Known, Depth + 1, Q);
if (Known.isConstant()) {
unsigned ShiftAmt = Known.getConstant().getLimitedValue(BitWidth - 1);
- Known = KF(Known2, ShiftAmt);
+ Known = KF(Known2, KnownBits::makeConstant(APInt(32, 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
@@ -1058,7 +1058,8 @@ static void computeKnownBitsFromShiftOperator(
continue;
}
- Known = KnownBits::commonBits(Known, KF(Known2, ShiftAmt));
+ Known = KnownBits::commonBits(
+ Known, KF(Known2, KnownBits::makeConstant(APInt(32, ShiftAmt))));
}
// If the known bits conflict, the result is poison. Return a 0 and hope the
@@ -1222,15 +1223,14 @@ static void computeKnownBitsFromOperator(const Operator *I,
}
case Instruction::Shl: {
bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
- auto KF = [NSW](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
- KnownBits KnownShiftAmt = KnownBits::makeConstant(APInt(32, ShiftAmt));
- KnownBits Result = KnownBits::shl(KnownShiftVal, KnownShiftAmt);
+ auto KF = [NSW](const KnownBits &KnownVal, const KnownBits &KnownAmt) {
+ KnownBits Result = KnownBits::shl(KnownVal, KnownAmt);
// 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) {
- if (KnownShiftVal.Zero.isSignBitSet())
+ if (KnownVal.Zero.isSignBitSet())
Result.Zero.setSignBit();
- if (KnownShiftVal.One.isSignBitSet())
+ if (KnownVal.One.isSignBitSet())
Result.One.setSignBit();
}
return Result;
@@ -1240,18 +1240,16 @@ static void computeKnownBitsFromOperator(const Operator *I,
break;
}
case Instruction::LShr: {
- auto KF = [](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
- KnownBits KnownShiftAmt = KnownBits::makeConstant(APInt(32, ShiftAmt));
- return KnownBits::lshr(KnownShiftVal, KnownShiftAmt);
+ auto KF = [](const KnownBits &KnownVal, const KnownBits &KnownAmt) {
+ return KnownBits::lshr(KnownVal, KnownAmt);
};
computeKnownBitsFromShiftOperator(I, DemandedElts, Known, Known2, Depth, Q,
KF);
break;
}
case Instruction::AShr: {
- auto KF = [](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
- KnownBits KnownShiftAmt = KnownBits::makeConstant(APInt(32, ShiftAmt));
- return KnownBits::ashr(KnownShiftVal, KnownShiftAmt);
+ auto KF = [](const KnownBits &KnownVal, const KnownBits &KnownAmt) {
+ return KnownBits::ashr(KnownVal, KnownAmt);
};
computeKnownBitsFromShiftOperator(I, DemandedElts, Known, Known2, Depth, Q,
KF);
More information about the llvm-commits
mailing list