[llvm] [LLVM] Improve the DemandedBits Analysis (PR #148853)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 15 08:26:28 PDT 2025
================
@@ -246,6 +247,63 @@ void DemandedBits::determineLiveOperandBits(
else
AB &= ~(Known.One & ~Known2.One);
break;
+ case Instruction::UDiv:
+ case Instruction::URem:
+ case Instruction::SDiv:
+ case Instruction::SRem: {
+ auto Opc = UserI->getOpcode();
+ auto IsDiv = Opc == Instruction::UDiv || Opc == Instruction::SDiv;
+ bool IsSigned = Opc == Instruction::SDiv || Opc == Instruction::SRem;
+ if (OperandNo == 0) {
+ const APInt *DivAmnt;
+ if (match(UserI->getOperand(1), m_APInt(DivAmnt))) {
+ uint64_t D = DivAmnt->getZExtValue();
+ if (isPowerOf2_64(D)) {
+ unsigned Sh = Log2_64(D);
+ if (IsDiv) {
+ AB = AOut.shl(Sh);
+ } else {
+ AB = AOut & APInt::getLowBitsSet(BitWidth, Sh);
+ }
+ } else { // Non power of 2 constant div
+ /*
----------------
jayfoad wrote:
Use `//` comments
https://github.com/llvm/llvm-project/pull/148853
More information about the llvm-commits
mailing list