[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
Tue Aug 4 02:42:13 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();
----------------
david-arm 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) {
...
```

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


More information about the llvm-commits mailing list