From f72d350bfb6a2250cc7b8d54c8b412821426cdc5 Mon Sep 17 00:00:00 2001 From: Simon Pilgrim Date: Thu, 12 Nov 2020 16:56:40 +0000 Subject: [PATCH] [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. --- llvm/lib/Analysis/ValueTracking.cpp | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 8568a23..b369f26 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 KF) { + function_ref 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(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); -- 2.7.4