[llvm] [LV] Add support for partial alias masking with tail folding (PR #182457)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 12 10:02:16 PDT 2026


================
@@ -1382,6 +1388,48 @@ class LoopVectorizationCostModel {
     return getTailFoldingStyle() != TailFoldingStyle::None;
   }
 
+  void tryToEnablePartialAliasMasking() {
+    assert(!IsPartialAliasMaskingEnabled && "Alias masking already enabled!");
+    assert(foldTailByMasking() && "Expected tail folding to be enabled!");
+    assert(!foldTailWithEVL() &&
+           "Did not expect to enable alias masking with EVL!");
+    // Note: FixedOrderRecurrences are not supported yet as we cannot handle
+    // the required `splice.right` with the alias-mask.
+    if (!ForcePartialAliasingVectorization ||
+        !Legal->getFixedOrderRecurrences().empty())
+      return;
+
+    const RuntimePointerChecking *Checks = Legal->getRuntimePointerChecking();
+    if (!Checks)
+      return;
+
+    if (auto DiffChecks = Checks->getDiffChecks())
+      if (DiffChecks->empty())
+        return;
+
+    for (BasicBlock *BB : TheLoop->blocks()) {
+      for (Instruction &I : *BB) {
+        if (!isa<LoadInst, StoreInst>(I))
+          continue;
+
+        Type *ScalarTy = getLoadStoreType(&I);
+        Value *Ptr = getLoadStorePointerOperand(&I);
+
+        // Currently, we can't handle alias masking in reverse. Reversing the
+        // alias mask is not correct (or necessary). When combined with
+        // tail-folding the ALM should only be reversed where the alias-mask is
+        // true.
+        if (Legal->isConsecutivePtr(ScalarTy, Ptr) < 0)
----------------
MacDue wrote:

The only possible return types are:
```
0 - Stride is unknown or non-consecutive.
1 - Address is consecutive.
-1 - Address is consecutive, and decreasing.
```
So this could probably just check `!= 1` (but the main legality checks for load/stores are handled elsewhere, e.g. `isLegalMaskedLoad`).

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


More information about the llvm-commits mailing list