diff options
author | Simon Pilgrim <llvm-dev@redking.me.uk> | 2020-11-11 14:15:17 +0000 |
---|---|---|
committer | Simon Pilgrim <llvm-dev@redking.me.uk> | 2020-11-11 14:22:42 +0000 |
commit | f6a326adef4fa2b7654f0d12d8c9be32aecbd2e3 (patch) | |
tree | 8b59dc0a77e2e0bd5dafa06e2ae24da10826fb67 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 3109ce51d465b7c6e40f855bd88776654eaf08cc (diff) | |
download | llvm-f6a326adef4fa2b7654f0d12d8c9be32aecbd2e3.zip llvm-f6a326adef4fa2b7654f0d12d8c9be32aecbd2e3.tar.gz llvm-f6a326adef4fa2b7654f0d12d8c9be32aecbd2e3.tar.bz2 |
[ValueTracking] computeKnownBitsFromShiftOperator - merge zero/one callbacks to single KnownBits callback. NFCI.
Another cleanup for D90479 - handle the Known Ones/Zeros in a single callback, which will make it much easier to jump over to the KnownBits shift handling.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 80 |
1 files changed, 35 insertions, 45 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index c86fa81..b740b14 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -979,25 +979,22 @@ static void computeKnownBitsFromAssume(const Value *V, KnownBits &Known, /// Compute known bits from a shift operator, including those with a /// non-constant shift amount. Known is the output of this function. Known2 is a /// pre-allocated temporary with the same bit width as Known and on return -/// contains the known bit of the shift value source. KZF and KOF are -/// operator-specific functions that, given the known-zero or known-one bits -/// respectively, and a shift amount, compute the implied known-zero or -/// known-one bits of the shift operator's result respectively for that shift -/// amount. The results from calling KZF and KOF are conservatively combined for -/// all permitted shift amounts. +/// contains the known bit of the shift value source. KF is an +/// operator-specific function that, given the known-bits and a shift amount, +/// compute the implied known-bits of the shift operator's result respectively +/// for that shift amount. The results from calling KF are conservatively +/// combined for all permitted shift amounts. static void computeKnownBitsFromShiftOperator( const Operator *I, const APInt &DemandedElts, 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(const KnownBits &, unsigned)> 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.Zero = KZF(Known2.Zero, ShiftAmt); - Known.One = KOF(Known2.One, ShiftAmt); + Known = KF(Known2, 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 @@ -1061,8 +1058,7 @@ static void computeKnownBitsFromShiftOperator( continue; } - Known.Zero &= KZF(Known2.Zero, ShiftAmt); - Known.One &= KOF(Known2.One, ShiftAmt); + Known = KnownBits::commonBits(Known, KF(Known2, ShiftAmt)); } // If the known bits conflict, the result is poison. Return a 0 and hope the @@ -1227,56 +1223,50 @@ static void computeKnownBitsFromOperator(const Operator *I, case Instruction::Shl: { // (shl X, C1) & C2 == 0 iff (X & C2 >>u C1) == 0 bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I)); - auto KZF = [NSW](const APInt &KnownZero, unsigned ShiftAmt) { - APInt KZResult = KnownZero << ShiftAmt; - KZResult.setLowBits(ShiftAmt); // Low bits known 0. + auto KF = [NSW](const KnownBits &KnownShiftVal, unsigned ShiftAmt) { + KnownBits Result; + Result.Zero = KnownShiftVal.Zero << ShiftAmt; + Result.One = KnownShiftVal.One << ShiftAmt; + // Low bits known zero. + Result.Zero.setLowBits(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) { + if (KnownShiftVal.Zero.isSignBitSet()) + Result.Zero.setSignBit(); + if (KnownShiftVal.One.isSignBitSet()) + Result.One.setSignBit(); + } + return Result; }; - computeKnownBitsFromShiftOperator(I, DemandedElts, Known, Known2, Depth, Q, - KZF, KOF); + KF); 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); + auto KF = [](const KnownBits &KnownShiftVal, unsigned ShiftAmt) { + KnownBits Result; + Result.Zero = KnownShiftVal.Zero.lshr(ShiftAmt); + Result.One = KnownShiftVal.One.lshr(ShiftAmt); // High bits known zero. - KZResult.setHighBits(ShiftAmt); - return KZResult; - }; - - auto KOF = [](const APInt &KnownOne, unsigned ShiftAmt) { - return KnownOne.lshr(ShiftAmt); + Result.Zero.setHighBits(ShiftAmt); + return Result; }; - computeKnownBitsFromShiftOperator(I, DemandedElts, Known, Known2, Depth, Q, - KZF, KOF); + KF); 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 KF = [](const KnownBits &KnownShiftVal, unsigned ShiftAmt) { + KnownBits Result; + Result.Zero = KnownShiftVal.Zero.ashr(ShiftAmt); + Result.One = KnownShiftVal.One.ashr(ShiftAmt); + return Result; }; - - auto KOF = [](const APInt &KnownOne, unsigned ShiftAmt) { - return KnownOne.ashr(ShiftAmt); - }; - computeKnownBitsFromShiftOperator(I, DemandedElts, Known, Known2, Depth, Q, - KZF, KOF); + KF); break; } case Instruction::Sub: { |