[llvm] [ConstantRange] Improve `shlWithNoWrap` (PR #101800)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 4 08:47:30 PDT 2024
================
@@ -1624,12 +1624,44 @@ ConstantRange ConstantRange::shlWithNoWrap(const ConstantRange &Other,
return getEmpty();
ConstantRange Result = shl(Other);
+ if (!NoWrapKind)
+ return Result;
- if (NoWrapKind & OverflowingBinaryOperator::NoSignedWrap)
- Result = Result.intersectWith(sshl_sat(Other), RangeType);
+ if (NoWrapKind & OverflowingBinaryOperator::NoSignedWrap) {
+ std::optional<unsigned> ShAmtBound;
+ if (isAllNonNegative())
+ ShAmtBound = getSignedMin().countLeadingZeros();
+ else if (isAllNegative())
+ ShAmtBound = getSignedMax().countLeadingOnes();
+ ConstantRange ShAmtRange = Other;
+ if (ShAmtBound)
+ ShAmtRange = ShAmtRange.intersectWith(
+ ConstantRange(APInt(getBitWidth(), 0),
+ APInt(getBitWidth(), *ShAmtBound)),
+ Unsigned);
+ Result = Result.intersectWith(sshl_sat(ShAmtRange), RangeType);
+ }
- if (NoWrapKind & OverflowingBinaryOperator::NoUnsignedWrap)
- Result = Result.intersectWith(ushl_sat(Other), RangeType);
+ if (NoWrapKind & OverflowingBinaryOperator::NoUnsignedWrap) {
----------------
dtcxzyw wrote:
Done.
https://github.com/llvm/llvm-project/pull/101800
More information about the llvm-commits
mailing list