diff options
author | Yingwei Zheng <dtcxzyw2333@gmail.com> | 2024-07-25 21:29:18 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-25 21:29:18 +0800 |
commit | ca00cec997c2a22dd6603cddb8bab789e1b01d34 (patch) | |
tree | dd7e5584f5c340ddca5df7bb153d2c639ca26306 /llvm/lib/IR/ConstantRange.cpp | |
parent | fd17064dfa08c252c12b71167bc588f57e6a082c (diff) | |
download | llvm-ca00cec997c2a22dd6603cddb8bab789e1b01d34.zip llvm-ca00cec997c2a22dd6603cddb8bab789e1b01d34.tar.gz llvm-ca00cec997c2a22dd6603cddb8bab789e1b01d34.tar.bz2 |
[ConstantRange] Infer nonnegative for mul nuw nsw (#100554)
Alive2: https://alive2.llvm.org/ce/z/byzmsV
Diffstat (limited to 'llvm/lib/IR/ConstantRange.cpp')
-rw-r--r-- | llvm/lib/IR/ConstantRange.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/llvm/lib/IR/ConstantRange.cpp b/llvm/lib/IR/ConstantRange.cpp index 0ead677..6068540 100644 --- a/llvm/lib/IR/ConstantRange.cpp +++ b/llvm/lib/IR/ConstantRange.cpp @@ -1242,6 +1242,17 @@ ConstantRange::multiplyWithNoWrap(const ConstantRange &Other, if (NoWrapKind & OverflowingBinaryOperator::NoUnsignedWrap) Result = Result.intersectWith(umul_sat(Other), RangeType); + // mul nsw nuw X, Y s>= 0 if X s> 1 or Y s> 1 + if ((NoWrapKind == (OverflowingBinaryOperator::NoSignedWrap | + OverflowingBinaryOperator::NoUnsignedWrap)) && + !Result.isAllNonNegative()) { + if (getSignedMin().sgt(1) || Other.getSignedMin().sgt(1)) + Result = Result.intersectWith( + getNonEmpty(APInt::getZero(getBitWidth()), + APInt::getSignedMinValue(getBitWidth())), + RangeType); + } + return Result; } |