diff options
| author | Andrew Kaylor <andrew.kaylor@intel.com> | 2016-08-09 22:41:35 +0000 | 
|---|---|---|
| committer | Andrew Kaylor <andrew.kaylor@intel.com> | 2016-08-09 22:41:35 +0000 | 
| commit | 3c05edfd5ef56685c3429e44d2128f26b6198e54 (patch) | |
| tree | eb49559a25d25aef99ca9e27681e4e68e699aaf4 /llvm/lib/Analysis | |
| parent | 66641322ce93bbfad35bf4136da6ffd266a4f82f (diff) | |
| download | bcm5719-llvm-3c05edfd5ef56685c3429e44d2128f26b6198e54.tar.gz bcm5719-llvm-3c05edfd5ef56685c3429e44d2128f26b6198e54.zip | |
[ValueTracking] Improve ValueTracking on left shift with nsw flag
Patch by Li Huang
Differential Revison: https://reviews.llvm.org/D23296
llvm-svn: 278172
Diffstat (limited to 'llvm/lib/Analysis')
| -rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 17 | 
1 files changed, 13 insertions, 4 deletions
| diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index c3a5e6af62b..59c39e5da9f 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1069,13 +1069,22 @@ static void computeKnownBitsFromOperator(Operator *I, APInt &KnownZero,    }    case Instruction::Shl: {      // (shl X, C1) & C2 == 0   iff   (X & C2 >>u C1) == 0 -    auto KZF = [BitWidth](const APInt &KnownZero, unsigned ShiftAmt) { -      return (KnownZero << ShiftAmt) | +    bool NSW = cast<OverflowingBinaryOperator>(I)->hasNoSignedWrap(); +    auto KZF = [BitWidth, NSW](const APInt &KnownZero, unsigned ShiftAmt) { +      APInt KZResult = (KnownZero << ShiftAmt) |               APInt::getLowBitsSet(BitWidth, ShiftAmt); // Low bits known 0. +      // 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.isNegative()) +        KZResult.setBit(BitWidth - 1); +      return KZResult;      }; -    auto KOF = [BitWidth](const APInt &KnownOne, unsigned ShiftAmt) { -      return KnownOne << ShiftAmt; +    auto KOF = [BitWidth, NSW](const APInt &KnownOne, unsigned ShiftAmt) { +      APInt KOResult = KnownOne << ShiftAmt; +      if (NSW && KnownOne.isNegative()) +        KOResult.setBit(BitWidth - 1); +      return KOResult;      };      computeKnownBitsFromShiftOperator(I, KnownZero, KnownOne, | 

