[llvm] [VPlan] Simplify pow-of-2 (mul|udiv) -> (shl|lshr) (PR #172477)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 5 22:46:35 PST 2026
================
@@ -1345,6 +1345,21 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
return Def->replaceAllUsesWith(
Def->getOperand(0) == A ? Def->getOperand(1) : Def->getOperand(0));
+ const APInt *APC;
+ if (match(Def, m_c_Mul(m_VPValue(), m_APInt(APC))) && APC->isPowerOf2())
+ return Def->replaceAllUsesWith(Builder.createNaryOp(
+ Instruction::Shl,
+ {Def->getOperand(0),
+ Plan->getConstantInt(APC->getBitWidth(), APC->exactLogBase2())},
+ *cast<VPRecipeWithIRFlags>(Def), Def->getDebugLoc()));
+
+ if (match(Def, m_UDiv(m_VPValue(), m_APInt(APC))) && APC->isPowerOf2())
+ return Def->replaceAllUsesWith(Builder.createNaryOp(
+ Instruction::LShr,
+ {Def->getOperand(0),
+ Plan->getConstantInt(APC->getBitWidth(), APC->exactLogBase2())},
+ *cast<VPRecipeWithIRFlags>(Def), Def->getDebugLoc()));
----------------
lukel97 wrote:
I don't think udiv flags are compatible with lshr, we can probably omit the copy?
```suggestion
{}, Def->getDebugLoc()));
```
https://github.com/llvm/llvm-project/pull/172477
More information about the llvm-commits
mailing list