[llvm] [Analysis] Optimise mul(const, (udiv %n, const)) during SCEV expansion (PR #212769)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 30 03:13:46 PDT 2026
================
@@ -599,6 +599,26 @@ Value *SCEVExpander::visitAddExpr(SCEVUseT<const SCEVAddExpr *> S) {
Value *SCEVExpander::visitMulExpr(SCEVUseT<const SCEVMulExpr *> S) {
Type *Ty = S->getType();
+ // Specializations for 2-operand cases.
+ const SCEVConstant *MulC;
+ const SCEV *Op1;
+ if (match(S, m_scev_Mul(m_SCEVConstant(MulC), m_SCEV(Op1)))) {
+ // mul(PowerOf2C, (udiv X, PowerOf2C)) == (X >> C) << C
+ // -> X & (-1 << C)
+ const SCEV *Val;
+ if (MulC->getAPInt().isPowerOf2() &&
+ match(Op1, m_scev_UDiv(m_SCEV(Val), m_scev_Specific(MulC)))) {
----------------
paulwalker-arm wrote:
I was thinking something more like
```
if (match(S, m_scev_Mul(m_SCEVConstant(MulC),
m_scev_UDiv(m_SCEV(Val), m_scev_Specific(MulC)))) &&
MulC->getAPInt().isPowerOf2()) {
```
?
https://github.com/llvm/llvm-project/pull/212769
More information about the llvm-commits
mailing list