[llvm] [LLVM] Improve the DemandedBits Analysis (PR #148880)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 15 10:47:03 PDT 2025
================
@@ -197,6 +209,19 @@ void DemandedBits::determineLiveOperandBits(
// (they must be zero).
if (cast<LShrOperator>(UserI)->isExact())
AB |= APInt::getLowBitsSet(BitWidth, ShiftAmt);
+ } else {
+ ComputeKnownBits(BitWidth, UserI->getOperand(1), nullptr);
+ unsigned Min = Known.getMinValue().getLimitedValue(BitWidth - 1);
+ unsigned Max = Known.getMaxValue().getLimitedValue(BitWidth - 1);
+ // Suppose AOut == 0b0000 0011
+ // [min, max] = [1, 3]
+ // shift by 1 we get 0b0000 0110
+ // shift by 2 we get 0b0000 1100
+ // shift by 3 we get 0b0001 1000
+ // we take the or here because need to cover all the above possibilities
+ AB = (AOut.shl(Min) | AOut.shl(Max));
----------------
topperc wrote:
Doesn't this need to be the OR of all possible shift amounts between Min and Max? Not just the end points.
https://github.com/llvm/llvm-project/pull/148880
More information about the llvm-commits
mailing list