[PATCH] D118539: [InstCombine] try to fold one-demanded-bit-of-multiply
Roman Lebedev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 4 07:31:05 PST 2022
lebedev.ri accepted this revision.
lebedev.ri added a comment.
This revision is now accepted and ready to land.
LGTM, thank you!
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp:548
+ case Instruction::Mul: {
+ // The LSB of X*Y is set only if (X & 1) == 1 and (Y & 1) == 1.
+ // If we demand exactly one bit N and we have "X * (C' << N)" where C' is
----------------
https://alive2.llvm.org/ce/z/f39Z6n
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp:549-550
+ // The LSB of X*Y is set only if (X & 1) == 1 and (Y & 1) == 1.
+ // If we demand exactly one bit N and we have "X * (C' << N)" where C' is
+ // odd (has LSB set), then the left-shifted low bit of X is the answer.
+ if (DemandedMask.isPowerOf2()) {
----------------
https://alive2.llvm.org/ce/z/RakJNM
================
Comment at: llvm/lib/Transforms/InstCombine/InstCombineSimplifyDemanded.cpp:551-560
+ if (DemandedMask.isPowerOf2()) {
+ unsigned CTZ = DemandedMask.countTrailingZeros();
+ const APInt *C;
+ if (match(I->getOperand(1), m_APInt(C)) &&
+ C->countTrailingZeros() == CTZ) {
+ Constant *ShiftC = ConstantInt::get(I->getType(), CTZ);
+ Instruction *Shl = BinaryOperator::CreateShl(I->getOperand(0), ShiftC);
----------------
https://alive2.llvm.org/ce/z/jgKaGK
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D118539/new/
https://reviews.llvm.org/D118539
More information about the llvm-commits
mailing list