[llvm] r319624 - [ValueTracking] Pass only a single lambda to computeKnownBitsFromShiftOperator by using KnownBits struct instead of separate APInts. NFCI

Yvan Roux via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 4 07:42:09 PST 2017


Hi,

On 4 December 2017 at 13:59, Sam McCall via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> Hi Craig,
>
> I reverted this commit because it seems to have caused a miscompile that
> causes a bootstrapped clang to fail tests.
>
> I don't know the code well enough to spot the problem, but the buildbots
> blame this revision:
>   - clang-ppc64be-linux-multistage: (r319622, r319624]
>   - clang-ppc64le-linux-multistage: (r319623, r319626]

The issue was also observed on aarch64 bot:

http://lab.llvm.org:8011/builders/clang-cmake-aarch64-full/builds/3363

only that part is related to this change:

FAIL: LLVM::basic-arm-instructions.s
FAIL: LLVM::ldr-pseudo-darwin.s
FAIL: LLVM::ldr-pseudo.s
FAIL: LLVM::basic-arm-instructions.txt

ldr-pseudo* failures are assert on invalid rotate amount in case it
helps to understand the issue.

Cheers,
Yvan

> Cheers, Sam
>
> On Sun, Dec 3, 2017 at 12:42 AM, Craig Topper via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>>
>> Author: ctopper
>> Date: Sat Dec  2 15:42:17 2017
>> New Revision: 319624
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=319624&view=rev
>> Log:
>> [ValueTracking] Pass only a single lambda to
>> computeKnownBitsFromShiftOperator by using KnownBits struct instead of
>> separate APInts. NFCI
>>
>> Modified:
>>     llvm/trunk/lib/Analysis/ValueTracking.cpp
>>
>> Modified: llvm/trunk/lib/Analysis/ValueTracking.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ValueTracking.cpp?rev=319624&r1=319623&r2=319624&view=diff
>>
>> ==============================================================================
>> --- llvm/trunk/lib/Analysis/ValueTracking.cpp (original)
>> +++ llvm/trunk/lib/Analysis/ValueTracking.cpp Sat Dec  2 15:42:17 2017
>> @@ -795,16 +795,14 @@ static void computeKnownBitsFromAssume(c
>>  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 computeKnownBitsFromShiftOpe
>>          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
>>    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: {
>>
>>
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>


More information about the llvm-commits mailing list