[llvm] [DemandedBits] Support non-constant shift amounts (PR #148880)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 24 20:03:32 PDT 2025
================
@@ -76,6 +76,15 @@ void DemandedBits::determineLiveOperandBits(
computeKnownBits(V2, Known2, DL, &AC, UserI, &DT);
}
};
+ auto GetShiftedRange = [&](unsigned Min, unsigned Max, bool ShiftLeft) {
+ using ShiftFn = APInt (APInt::*)(unsigned) const;
+ auto Shift = ShiftLeft ? static_cast<ShiftFn>(&APInt::shl)
+ : static_cast<ShiftFn>(&APInt::lshr);
+ AB = APInt::getZero(BitWidth);
+ for (unsigned ShiftAmount = Min; ShiftAmount <= Max; ++ShiftAmount) {
----------------
dtcxzyw wrote:
We should convert it into an O(LlogL) algorithm with the [Exponentiation by squaring](https://en.wikipedia.org/wiki/Exponentiation_by_squaring) trick. In the current implementation, we may need 128 shifts + 128 ors for i128.
https://github.com/llvm/llvm-project/pull/148880
More information about the llvm-commits
mailing list