Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b0d95f0

Browse files
committed
[VPlan] Handle Mul/UDiv in getSCEVExprForVPValue (NFCI).
Support Mul/UDiv and AND-variant (https://alive2.llvm.org/ce/z/rBJVdg) in getSCEVExprForVPValue. This is used in code paths when computing SCEV expressions in the VPlan-based cost model, which should produce costs matching the legacy cost model.
1 parent 8b3b0b8 commit b0d95f0

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

llvm/lib/Transforms/Vectorize/VPlanUtils.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,22 @@ const SCEV *vputils::getSCEVExprForVPValue(const VPValue *V,
178178
return SE.getMinusSCEV(SE.getMinusOne(Ops[0]->getType()), Ops[0]);
179179
});
180180
}
181+
if (match(V, m_Mul(m_VPValue(LHSVal), m_VPValue(RHSVal))))
182+
return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<const SCEV *> Ops) {
183+
return SE.getMulExpr(Ops[0], Ops[1], SCEV::FlagAnyWrap, 0);
184+
});
185+
if (match(V,
186+
m_Binary<Instruction::UDiv>(m_VPValue(LHSVal), m_VPValue(RHSVal))))
187+
return CreateSCEV({LHSVal, RHSVal}, [&](ArrayRef<const SCEV *> Ops) {
188+
return SE.getUDivExpr(Ops[0], Ops[1]);
189+
});
190+
// Handle AND with constant mask: x & (2^n - 1) can be represented as x % 2^n.
191+
const APInt *Mask;
192+
if (match(V, m_c_BinaryAnd(m_VPValue(LHSVal), m_APInt(Mask))) &&
193+
(*Mask + 1).isPowerOf2())
194+
return CreateSCEV({LHSVal}, [&](ArrayRef<const SCEV *> Ops) {
195+
return SE.getURemExpr(Ops[0], SE.getConstant(*Mask + 1));
196+
});
181197
if (match(V, m_Trunc(m_VPValue(LHSVal)))) {
182198
const VPlan *Plan = V->getDefiningRecipe()->getParent()->getPlan();
183199
Type *DestTy = VPTypeAnalysis(*Plan).inferScalarType(V);

0 commit comments

Comments
 (0)