[llvm] [LV] Add vplan folds for urem(X, PowerOf2) -> and(X, PowerOf2 - 1) (PR #212198)

Luke Lau via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 4 02:53:41 PDT 2026


================
@@ -1366,6 +1366,15 @@ 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();
----------------
lukel97 wrote:

> What I could do is change the order so that we do the least expensive first:
> 
> ```
>   if (CanCreateNewRecipe && match(Def, m_URem(m_VPValue(X), m_APInt(APC))) && APC->isPowerOf2()) {
>     // 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 (Preheader && Def->getParent() != Preheader) {
> ...
> ```

Yeah this looks a good fix, I'm happy if you want to go ahead and land that directly

https://github.com/llvm/llvm-project/pull/212198


More information about the llvm-commits mailing list