[llvm] [DemandedBits] Support non-constant shift amounts (PR #148880)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 2 11:34:15 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:

Of course. You don't need to create a new PR, just send me your commit hash.
The bad thing is that llvm-opt-benchmark doesn't support comparing diffs between two PRs, as the diff has been reduced to fit GitHub's limit. But we can compare them by the number of line changes and the statistics diff.


https://github.com/llvm/llvm-project/pull/148880


More information about the llvm-commits mailing list