diff options
author | Nikita Popov <npopov@redhat.com> | 2023-05-22 14:21:56 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-05-25 10:17:10 +0200 |
commit | d2502eb091fabc36463e491b066bb002b47ba521 (patch) | |
tree | ceabf3f122d50440c9bf7d18d14d344d0a2665c8 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 660b3c85c8ea74909de0116bd1dae1b83342cffa (diff) | |
download | llvm-d2502eb091fabc36463e491b066bb002b47ba521.zip llvm-d2502eb091fabc36463e491b066bb002b47ba521.tar.gz llvm-d2502eb091fabc36463e491b066bb002b47ba521.tar.bz2 |
[KnownBits] Add support for nuw/nsw on shifts
Implement precise nuw/nsw support in the KnownBits implementation,
replacing the rather crude handling in ValueTracking.
Differential Revision: https://reviews.llvm.org/D151208
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 16 |
1 files changed, 3 insertions, 13 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 90dbfcb..7ec34cd 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -1353,20 +1353,10 @@ static void computeKnownBitsFromOperator(const Operator *I, break; } case Instruction::Shl: { + bool NUW = Q.IIQ.hasNoUnsignedWrap(cast<OverflowingBinaryOperator>(I)); bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I)); - 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 (KnownVal.Zero.isSignBitSet()) - Result.Zero.setSignBit(); - if (KnownVal.One.isSignBitSet()) - Result.One.setSignBit(); - if (Result.hasConflict()) - Result.setAllZero(); - } - return Result; + auto KF = [NUW, NSW](const KnownBits &KnownVal, const KnownBits &KnownAmt) { + return KnownBits::shl(KnownVal, KnownAmt, NUW, NSW); }; computeKnownBitsFromShiftOperator(I, DemandedElts, Known, Known2, Depth, Q, KF); |