[llvm] [LV] Add vplan folds for urem(X, PowerOf2) -> and(X, PowerOf2 - 1) (PR #212198)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 27 02:48:47 PDT 2026
================
@@ -1372,6 +1323,17 @@ static void simplifyRecipe(VPSingleDefRecipe *Def) {
}
const APInt *APC;
+ // TODO: Enable optimizations in the vector preheader in a follow-up PR.
+ // This check currently means we only simplify before region dissolution.
+ VPBasicBlock *Preheader = Plan->getVectorPreheader();
+ if (CanCreateNewRecipe && Preheader && Def->getParent() != Preheader &&
+ match(Def, m_URem(m_VPValue(X), m_APInt(APC))) && APC->isPowerOf2()) {
+ APInt APC2(*APC);
+ APC2 -= 1;
+ return Def->replaceAllUsesWith(
+ Builder.createAnd(X, Plan->getConstantInt(APC2)));
----------------
david-arm wrote:
Unfortunately there is no easy way to get the name from a `VPSingleDefRecipe`, since it doesn't have one. Only certain recipes like VPInstruction seem to have a name.
https://github.com/llvm/llvm-project/pull/212198
More information about the llvm-commits
mailing list