[llvm] [LV] Add initial support for partial alias masking (PR #177599)

Benjamin Maxwell via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 26 03:15:20 PST 2026


================
@@ -156,25 +157,38 @@ VPValue *VPPredicator::createBlockInMask(VPBasicBlock *VPBB) {
   return BlockMask;
 }
 
-void VPPredicator::createHeaderMask(VPBasicBlock *HeaderVPBB, bool FoldTail) {
-  if (!FoldTail) {
+void VPPredicator::createHeaderMask(VPBasicBlock *HeaderVPBB, bool FoldTail,
+                                    bool MaskAliasing) {
+  if (!FoldTail && !MaskAliasing) {
     setBlockInMask(HeaderVPBB, nullptr);
     return;
   }
 
-  // Introduce the early-exit compare IV <= BTC to form header block mask.
-  // This is used instead of IV < TC because TC may wrap, unlike BTC. Start by
-  // constructing the desired canonical IV in the header block as its first
-  // non-phi instructions.
-
+  VPValue *BlockMask = nullptr;
   auto &Plan = *HeaderVPBB->getPlan();
-  auto *IV =
-      new VPWidenCanonicalIVRecipe(HeaderVPBB->getParent()->getCanonicalIV());
-  Builder.setInsertPoint(HeaderVPBB, HeaderVPBB->getFirstNonPhi());
-  Builder.insert(IV);
 
-  VPValue *BTC = Plan.getOrCreateBackedgeTakenCount();
-  VPValue *BlockMask = Builder.createICmp(CmpInst::ICMP_ULE, IV, BTC);
+  if (FoldTail) {
+    // Introduce the early-exit compare IV <= BTC to form header block mask.
+    // This is used instead of IV < TC because TC may wrap, unlike BTC. Start by
+    // constructing the desired canonical IV in the header block as its first
+    // non-phi instructions.
+
+    auto *IV =
+        new VPWidenCanonicalIVRecipe(HeaderVPBB->getParent()->getCanonicalIV());
+    Builder.setInsertPoint(HeaderVPBB, HeaderVPBB->getFirstNonPhi());
+    Builder.insert(IV);
+
+    VPValue *BTC = Plan.getOrCreateBackedgeTakenCount();
+    BlockMask = Builder.createICmp(CmpInst::ICMP_ULE, IV, BTC);
+  }
+
+  if (MaskAliasing) {
+    if (BlockMask)
+      BlockMask = Builder.createAnd(BlockMask, &Plan.getAliasMask());
+    else
+      BlockMask = &Plan.getAliasMask();
+  }
----------------
MacDue wrote:

There's nothing stopping them from being used at the same time. The `CHECK-TF` tests have both alias masking and tail folding enabled. 

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


More information about the llvm-commits mailing list