[llvm] [LV] Use wide lane masks as the canonical form when tail-folding & interleaving (PR #209484)

Kerry McLaughlin via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 11 05:31:11 PDT 2026


================
@@ -514,4 +514,46 @@ TEST_F(VPIRVerifierTest, BranchOnTwoCondsLatchHeaderVerification) {
 #endif
 }
 
+TEST_F(VPIRVerifierTest, testVerifyLastActiveWideActiveLaneMask) {
+  const char *ModuleString =
+      "define i32 @f(ptr %A, i64 %N) {\n"
+      "entry:\n"
+      "  br label %loop\n"
+      "loop:\n"
+      "  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]\n"
+      "  %gep = getelementptr i32, ptr %A, i64 %iv\n"
+      "  %ld = load i32, ptr %gep \n"
+      "  %iv.next = add i64 %iv, 1\n"
+      "  %exitcond = icmp eq i64 %iv.next, %N\n"
+      "  br i1 %exitcond, label %exit, label %loop\n"
+      "exit:\n"
+      "  ret i32 %ld\n"
+      "}\n";
+
+  Module &M = parseModule(ModuleString);
+
+  Function *F = M.getFunction("f");
+  BasicBlock *LoopHeader = F->getEntryBlock().getSingleSuccessor();
+  auto Plan = buildVPlan(LoopHeader);
+
+  VPValue *Start = Plan->getConstantInt(64, 0);
+  VPValue *TC = Plan->getTripCount();
+  VPValue *One = Plan->getConstantInt(64, 1);
+  Type *MaskTy = FixedVectorType::get(Type::getInt1Ty(*Ctx), 4);
+  Type *IndexTy = Plan->getDataLayout().getIndexType(Plan->getContext(), 0);
+
+  auto *WideALM =
+      new VPInstruction(VPInstruction::WideActiveLaneMask, {Start, TC, One}, {},
+                        {}, DebugLoc(), "", MaskTy);
+  auto *Preheader = Plan->getVectorPreheader();
+  WideALM->insertBefore(*Preheader, Preheader->end());
+
+  auto *LastActiveLane =
+      new VPInstruction(VPInstruction::LastActiveLane, {WideALM}, {}, {},
----------------
kmclaughlin-arm wrote:

I took another look at this and I think the changes I added to VPlanVerifier.cpp are incorrect.

LastActiveLane is created using HeaderMask, which is later replaced by `materializeHeaderMask`. When the tail-folding style is `Data`, this becomes an ActiveLaneMask. For `DataAndControlFlow`, the HeaderMask is replaced by the VPActiveLaneMaskPHIRecipe returned by `addVPLaneMaskPhiAndUpdateExitBranch`. This hasn't been changed by this PR, and  I don't think it would be possible to come across the pattern I added in the verifier.

I've reverted the verifier change and removed this test, adding a new test with a use outside of the loop to `sve-wide-lane-mask.ll`.

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


More information about the llvm-commits mailing list