[llvm] [DemandedBits] Support non-constant shift amounts (PR #148880)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 3 02:21:26 PDT 2025
================
@@ -183,6 +196,17 @@ void DemandedBits::determineLiveOperandBits(
AB |= APInt::getHighBitsSet(BitWidth, ShiftAmt+1);
else if (S->hasNoUnsignedWrap())
AB |= APInt::getHighBitsSet(BitWidth, ShiftAmt);
+ } else {
+ ComputeKnownBits(BitWidth, UserI->getOperand(1), nullptr);
+ uint64_t Min = Known.getMinValue().getLimitedValue(BitWidth - 1);
+ uint64_t Max = Known.getMaxValue().getLimitedValue(BitWidth - 1);
+ // similar to Lshr case
+ GetShiftedRange(Min, Max, /*ShiftLeft=*/false);
+ const auto *S = cast<ShlOperator>(UserI);
+ if (S->hasNoSignedWrap())
+ AB |= APInt::getHighBitsSet(BitWidth, Max + 1);
+ else if (S->hasNoUnsignedWrap())
+ AB |= APInt::getHighBitsSet(BitWidth, Max);
----------------
dtcxzyw wrote:
Before: https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2638
After: https://github.com/dtcxzyw/llvm-opt-benchmark/pull/2637
https://github.com/llvm/llvm-project/pull/148880
More information about the llvm-commits
mailing list