[llvm] [VPlan] Simplify (sdiv/srem lhs, (select header, rhs, 1)) -> (sdiv/srem lhs, rhs) (PR #174547)
Shih-Po Hung via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 6 02:28:58 PST 2026
================
@@ -1434,6 +1434,49 @@ static void simplifyRecipe(VPSingleDefRecipe *Def, VPTypeAnalysis &TypeInfo) {
return;
}
+ // Drop header mask if LHS/RHS range is safe.
+ // (sdiv lhs, (select header, rhs, 1)) -> (sdiv lhs, rhs)
+ // (srem lhs, (select header, rhs, 1)) -> (srem lhs, rhs)
+ VPValue *LHS, *WSel, *RHS, *Mask;
+ if (match(Def, m_CombineOr(m_VPWidenRecipe<Instruction::SDiv>(
+ m_VPValue(LHS), m_VPValue(WSel)),
+ m_VPWidenRecipe<Instruction::SRem>(
+ m_VPValue(LHS), m_VPValue(WSel)))) &&
+ match(WSel, m_Select(m_VPValue(Mask), m_VPValue(RHS), m_One())) &&
+ Plan->getVectorLoopRegion() && vputils::isHeaderMask(Mask, *Plan)) {
+ auto InductionWithoutN = [](VPValue *Recipe, APInt N) {
+ auto *IV = dyn_cast<VPWidenIntOrFpInductionRecipe>(Recipe);
----------------
arcbbb wrote:
> The induction could wrap and be poison on wrapping, depending on the flags it has. So we may need to drop the flags in those cases (would be good to test
@fhahn I don’t fully follow. If the induction would wrap, then we need to bail out of the simplification since the masked-off lanes have poisons,?
https://github.com/llvm/llvm-project/pull/174547
More information about the llvm-commits
mailing list