[llvm] [VPlan] Add VPlan-dump-based test for predication (PR #180794)

Andrei Elovikov via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 11 08:36:42 PST 2026


https://github.com/eas updated https://github.com/llvm/llvm-project/pull/180794

>From 3cc13ab6ee4ab5397d343d4b69c0ce74e8d11e60 Mon Sep 17 00:00:00 2001
From: Andrei Elovikov <andrei.elovikov at sifive.com>
Date: Tue, 27 Jan 2026 16:59:55 -0800
Subject: [PATCH 1/5] [VPlan] Print function name in `-vplan-print-after*`

---
 .../Transforms/Vectorize/VPlanTransforms.h    |  6 +-
 .../LoopVectorize/vplan-print-after-all.ll    | 78 +++++++++----------
 .../LoopVectorize/vplan-print-after.ll        |  8 +-
 3 files changed, 48 insertions(+), 44 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index 07ad08aef471f..c4dcf740d6b07 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -59,7 +59,11 @@ struct VPlanTransforms {
            any_of(VPlanPrintAfterPasses, [PassName](StringRef Entry) {
              return Regex(Entry).match(PassName);
            }))) {
-        dbgs() << "VPlan after " << PassName << '\n';
+
+        dbgs()
+            << "VPlan for loop in '"
+            << Plan.getScalarHeader()->getIRBasicBlock()->getParent()->getName()
+            << "' after " << PassName << '\n';
         dbgs() << Plan << '\n';
       }
 #endif
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-print-after-all.ll b/llvm/test/Transforms/LoopVectorize/vplan-print-after-all.ll
index 5b68887f0f7da..ae09cb1b1002e 100644
--- a/llvm/test/Transforms/LoopVectorize/vplan-print-after-all.ll
+++ b/llvm/test/Transforms/LoopVectorize/vplan-print-after-all.ll
@@ -1,55 +1,55 @@
-; RUN: opt -passes=loop-vectorize -disable-output -vplan-print-after-all -force-vector-width=4 -vplan-verify-each < %s 2>&1 | FileCheck %s --implicit-check-not "VPlan after"
+; RUN: opt -passes=loop-vectorize -disable-output -vplan-print-after-all -force-vector-width=4 -vplan-verify-each < %s 2>&1 | FileCheck %s --implicit-check-not "VPlan for loop in 'foo' after"
 ; RUN: opt -passes=loop-vectorize -disable-output -vplan-print-after-all -force-vector-width=4 -vplan-verify-each < %s 2>&1 | FileCheck %s --check-prefix CHECK-DUMP
 ; REQUIRES: asserts
 
 ; Verify that `-vplan-print-after-all` option works.
 
-; CHECK: VPlan after printAfterInitialConstruction
-; CHECK: VPlan after VPlanTransforms::clearReductionWrapFlags
-; CHECK: VPlan after VPlanTransforms::optimizeFindIVReductions
-; CHECK: VPlan after VPlanTransforms::handleMultiUseReductions
-; CHECK: VPlan after VPlanTransforms::handleMaxMinNumReductions
-; CHECK: VPlan after VPlanTransforms::handleFindLastReductions
-; CHECK: VPlan after VPlanTransforms::createPartialReductions
-; CHECK: VPlan after VPlanTransforms::convertToAbstractRecipes
-; CHECK: VPlan after VPlanTransforms::createInterleaveGroups
-; CHECK: VPlan after VPlanTransforms::replaceSymbolicStrides
-; CHECK: VPlan after VPlanTransforms::dropPoisonGeneratingRecipes
-; CHECK: VPlan after VPlanTransforms::adjustFixedOrderRecurrences
-; CHECK: VPlan after VPlanTransforms::truncateToMinimalBitwidths
-; CHECK: VPlan after removeRedundantCanonicalIVs
-; CHECK: VPlan after removeRedundantInductionCasts
-; CHECK: VPlan after simplifyRecipes
-; CHECK: VPlan after removeDeadRecipes
-; CHECK: VPlan after simplifyBlends
-; CHECK: VPlan after legalizeAndOptimizeInductions
-; CHECK: VPlan after narrowToSingleScalarRecipes
-; CHECK: VPlan after removeRedundantExpandSCEVRecipes
-; CHECK: VPlan after simplifyRecipes
-; CHECK: VPlan after removeBranchOnConst
-; CHECK: VPlan after removeDeadRecipes
-; CHECK: VPlan after createAndOptimizeReplicateRegions
-; CHECK: VPlan after hoistInvariantLoads
-; CHECK: VPlan after mergeBlocksIntoPredecessors
-; CHECK: VPlan after licm
-; CHECK: VPlan after VPlanTransforms::optimize
-; CHECK: VPlan after VPlanTransforms::materializeConstantVectorTripCount
-; CHECK: VPlan after VPlanTransforms::unrollByUF
-; CHECK: VPlan after VPlanTransforms::materializePacksAndUnpacks
-; CHECK: VPlan after VPlanTransforms::materializeBroadcasts
-; CHECK: VPlan after VPlanTransforms::replicateByVF
-; CHECK: VPlan after printFinalVPlan
+; CHECK: VPlan for loop in 'foo' after printAfterInitialConstruction
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::clearReductionWrapFlags
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::optimizeFindIVReductions
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::handleMultiUseReductions
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::handleMaxMinNumReductions
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::handleFindLastReductions
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::createPartialReductions
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::convertToAbstractRecipes
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::createInterleaveGroups
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::replaceSymbolicStrides
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::dropPoisonGeneratingRecipes
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::adjustFixedOrderRecurrences
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::truncateToMinimalBitwidths
+; CHECK: VPlan for loop in 'foo' after removeRedundantCanonicalIVs
+; CHECK: VPlan for loop in 'foo' after removeRedundantInductionCasts
+; CHECK: VPlan for loop in 'foo' after simplifyRecipes
+; CHECK: VPlan for loop in 'foo' after removeDeadRecipes
+; CHECK: VPlan for loop in 'foo' after simplifyBlends
+; CHECK: VPlan for loop in 'foo' after legalizeAndOptimizeInductions
+; CHECK: VPlan for loop in 'foo' after narrowToSingleScalarRecipes
+; CHECK: VPlan for loop in 'foo' after removeRedundantExpandSCEVRecipes
+; CHECK: VPlan for loop in 'foo' after simplifyRecipes
+; CHECK: VPlan for loop in 'foo' after removeBranchOnConst
+; CHECK: VPlan for loop in 'foo' after removeDeadRecipes
+; CHECK: VPlan for loop in 'foo' after createAndOptimizeReplicateRegions
+; CHECK: VPlan for loop in 'foo' after hoistInvariantLoads
+; CHECK: VPlan for loop in 'foo' after mergeBlocksIntoPredecessors
+; CHECK: VPlan for loop in 'foo' after licm
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::optimize
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::materializeConstantVectorTripCount
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::unrollByUF
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::materializePacksAndUnpacks
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::materializeBroadcasts
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::replicateByVF
+; CHECK: VPlan for loop in 'foo' after printFinalVPlan
 
 ; Also verify that VPlans are actually printed (we aren't interested in the
 ; exact dump content, just that it's performed):
 
-; CHECK-DUMP:      VPlan after printAfterInitialConstruction
+; CHECK-DUMP:      VPlan for loop in 'foo' after printAfterInitialConstruction
 ; CHECK-DUMP-NEXT: VPlan ' for UF>=1' {
 ;
-; CHECK-DUMP:      VPlan after VPlanTransforms::optimize{{$}}
+; CHECK-DUMP:      VPlan for loop in 'foo' after VPlanTransforms::optimize{{$}}
 ; CHECK-DUMP-NEXT: VPlan 'Initial VPlan for VF={4},UF>=1' {
 ;
-; CHECK-DUMP:      VPlan after printFinalVPlan
+; CHECK-DUMP:      VPlan for loop in 'foo' after printFinalVPlan
 ; CHECK-DUMP-NEXT: VPlan 'Final VPlan for VF={4},UF={1}' {
 
 define void @foo(ptr %ptr, i64 %n) {
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-print-after.ll b/llvm/test/Transforms/LoopVectorize/vplan-print-after.ll
index 8014a4e480d65..56a2ad83007a8 100644
--- a/llvm/test/Transforms/LoopVectorize/vplan-print-after.ll
+++ b/llvm/test/Transforms/LoopVectorize/vplan-print-after.ll
@@ -3,13 +3,13 @@
 ; RUN:   2>&1 | FileCheck %s --implicit-check-not "VPlan after"
 ; REQUIRES: asserts
 
-; CHECK:      VPlan after simplifyRecipes
+; CHECK:      VPlan for loop in 'foo' after simplifyRecipes
 ; CHECK-NEXT: VPlan 'Initial VPlan for VF={4},UF>=1' {
-; CHECK:      VPlan after simplifyBlends
+; CHECK:      VPlan for loop in 'foo' after simplifyBlends
 ; CHECK-NEXT: VPlan 'Initial VPlan for VF={4},UF>=1' {
-; CHECK:      VPlan after simplifyRecipes
+; CHECK:      VPlan for loop in 'foo' after simplifyRecipes
 ; CHECK-NEXT: VPlan 'Initial VPlan for VF={4},UF>=1' {
-; CHECK:      VPlan after printFinalVPlan
+; CHECK:      VPlan for loop in 'foo' after printFinalVPlan
 ; CHECK-NEXT: VPlan 'Final VPlan for VF={4},UF={1}' {
 
 define void @foo(ptr %ptr, i64 %n) {

>From e46f57bf5f7ddab430b7b871ce1573f4ab184d9d Mon Sep 17 00:00:00 2001
From: Andrei Elovikov <andrei.elovikov at sifive.com>
Date: Fri, 6 Feb 2026 12:20:43 -0800
Subject: [PATCH 2/5] Update VPlan UTC to use `-vplan-print-after=`

---
 .../first-order-recurrence-chains-vplan.ll    |  2 +-
 ...-order-recurrence-sink-replicate-region.ll |  2 +-
 .../LoopVectorize/vplan-printing-metadata.ll  |  2 +-
 .../vplan-printing-reductions.ll              |  2 +-
 .../LoopVectorize/vplan-printing.ll           |  2 +-
 .../vplan-sink-scalars-and-merge-vf1.ll       |  2 +-
 .../Inputs/vplan.ll                           |  4 +-
 .../Inputs/vplan.ll.expected                  |  4 +-
 llvm/utils/UpdateTestChecks/common.py         |  4 ++
 llvm/utils/update_analyze_test_checks.py      | 44 +++----------------
 10 files changed, 20 insertions(+), 48 deletions(-)

diff --git a/llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains-vplan.ll b/llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains-vplan.ll
index 9ab2557387877..648ea5297f042 100644
--- a/llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains-vplan.ll
+++ b/llvm/test/Transforms/LoopVectorize/first-order-recurrence-chains-vplan.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
 ; REQUIRES: asserts
 
-; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -debug-only=loop-vectorize -disable-output -S %s 2>&1 | FileCheck %s
+; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -vplan-print-after="optimize$" -disable-output -S %s 2>&1 | FileCheck %s
 
 define void @test_chained_first_order_recurrences_1(ptr %ptr) {
 ; CHECK-LABEL: 'test_chained_first_order_recurrences_1'
diff --git a/llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll b/llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
index 6992a441f9444..b398a96662f47 100644
--- a/llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
+++ b/llvm/test/Transforms/LoopVectorize/first-order-recurrence-sink-replicate-region.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
 ; REQUIRES: asserts
-; RUN: opt < %s -passes=loop-vectorize -force-vector-width=2 -force-vector-interleave=1 -force-widen-divrem-via-safe-divisor=0 -disable-output -debug-only=loop-vectorize 2>&1 | FileCheck %s
+; RUN: opt < %s -passes=loop-vectorize -force-vector-width=2 -force-vector-interleave=1 -force-widen-divrem-via-safe-divisor=0 -disable-output -vplan-print-after="optimize$" 2>&1 | FileCheck %s
 
 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
 
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-printing-metadata.ll b/llvm/test/Transforms/LoopVectorize/vplan-printing-metadata.ll
index 027bfe859c828..d780a799c9d49 100644
--- a/llvm/test/Transforms/LoopVectorize/vplan-printing-metadata.ll
+++ b/llvm/test/Transforms/LoopVectorize/vplan-printing-metadata.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
 ; REQUIRES: asserts
 
-; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -disable-output %s 2>&1 | FileCheck %s
+; RUN: opt -passes=loop-vectorize -vplan-print-after="optimize$" -force-vector-interleave=1 -force-vector-width=4 -disable-output %s 2>&1 | FileCheck %s
 
 define void @test_widen_metadata(ptr noalias %A, ptr noalias %B, i32 %n) {
 ; CHECK-LABEL: 'test_widen_metadata'
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-printing-reductions.ll b/llvm/test/Transforms/LoopVectorize/vplan-printing-reductions.ll
index b282a9079c996..46f6e872ab2e9 100644
--- a/llvm/test/Transforms/LoopVectorize/vplan-printing-reductions.ll
+++ b/llvm/test/Transforms/LoopVectorize/vplan-printing-reductions.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
 ; REQUIRES: asserts
 
-; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -prefer-inloop-reductions -disable-output %s 2>&1 | FileCheck %s
+; RUN: opt -passes=loop-vectorize -vplan-print-after="optimize$" -force-vector-interleave=1 -force-vector-width=4 -prefer-inloop-reductions -disable-output %s 2>&1 | FileCheck %s
 
 ; Tests for printing VPlans with reductions.
 
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-printing.ll b/llvm/test/Transforms/LoopVectorize/vplan-printing.ll
index 1d5d71b0a64c0..c9a186cb3f1f8 100644
--- a/llvm/test/Transforms/LoopVectorize/vplan-printing.ll
+++ b/llvm/test/Transforms/LoopVectorize/vplan-printing.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
 ; REQUIRES: asserts
 
-; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -enable-interleaved-mem-accesses=true -enable-masked-interleaved-mem-accesses -force-widen-divrem-via-safe-divisor=0 -disable-output %s 2>&1 | FileCheck --strict-whitespace %s
+; RUN: opt -passes=loop-vectorize -vplan-print-after="optimize$" -force-vector-interleave=1 -force-vector-width=4 -enable-interleaved-mem-accesses=true -enable-masked-interleaved-mem-accesses -force-widen-divrem-via-safe-divisor=0 -disable-output %s 2>&1 | FileCheck --strict-whitespace %s
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge-vf1.ll b/llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge-vf1.ll
index 3896e67c81b1b..63c2d618bbd26 100644
--- a/llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge-vf1.ll
+++ b/llvm/test/Transforms/LoopVectorize/vplan-sink-scalars-and-merge-vf1.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
 ; REQUIRES: asserts
 
-; RUN: opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 -debug -disable-output %s 2>&1 | FileCheck %s
+; RUN: opt -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 -vplan-print-after="optimize$" -disable-output %s 2>&1 | FileCheck %s
 
 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
 
diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/vplan.ll b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/vplan.ll
index 1ef134466cfcf..8b0dd716fc1ff 100644
--- a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/vplan.ll
+++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/vplan.ll
@@ -1,5 +1,5 @@
-; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-width=4 \
-; RUN:   -disable-output %s 2>&1 | FileCheck %s
+; RUN: opt -passes=loop-vectorize -vplan-print-after="optimize$" \
+; RUN:   -force-vector-width=4 -disable-output %s 2>&1 | FileCheck %s
 
 define void @simple(ptr %p, i64 %n) {
 entry:
diff --git a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/vplan.ll.expected b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/vplan.ll.expected
index 5d0cf220faf75..970ba6afb567d 100644
--- a/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/vplan.ll.expected
+++ b/llvm/test/tools/UpdateTestChecks/update_analyze_test_checks/Inputs/vplan.ll.expected
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py
-; RUN: opt -passes=loop-vectorize -debug-only=loop-vectorize -force-vector-width=4 \
-; RUN:   -disable-output %s 2>&1 | FileCheck %s
+; RUN: opt -passes=loop-vectorize -vplan-print-after="optimize$" \
+; RUN:   -force-vector-width=4 -disable-output %s 2>&1 | FileCheck %s
 
 define void @simple(ptr %p, i64 %n) {
 ; CHECK-LABEL: 'simple'
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 9cca0a7ad5d38..5fcc056a4bb6d 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -597,6 +597,10 @@ def invoke_tool(exe, cmd_args, ir, preprocess_cmd=None, verbose=False):
     r"^\s*\'(?P<func>[\w.$-]+?)\'[^\n]*" r"\s*\n(?P<body>.*)$", flags=(re.X | re.S)
 )
 
+VPLAN_RE = re.compile(
+    r"\'(?P<func>[\w.$-]+?)\'[^\n]*\n(?P<body>.*)\n$", flags=(re.X | re.S)
+)
+
 IR_FUNCTION_RE = re.compile(r'^\s*define\s+(?:internal\s+)?[^@]*@"?([\w.$-]+)"?\s*\(')
 IR_FUNCTION_LABEL_RE = re.compile(
     r'^\s*(?:define\s+(?:internal\s+)?[^@]*)?@"?([\w.$-]+)"?\s*\('
diff --git a/llvm/utils/update_analyze_test_checks.py b/llvm/utils/update_analyze_test_checks.py
index bd249a53f458f..cc55f72425b16 100755
--- a/llvm/utils/update_analyze_test_checks.py
+++ b/llvm/utils/update_analyze_test_checks.py
@@ -41,27 +41,6 @@
 from UpdateTestChecks import common
 
 
-def extract_vplan(raw_output):
-    """
-    Extract a VPlan block from loop-vectorize debug output using brace-depth
-    tracking.
-    TODO: Remove once only -vplan-print-after is supported.
-    """
-    result = []
-    brace_depth = 0
-    for line in raw_output.splitlines():
-        if not brace_depth and line.startswith("VPlan 'Initial VPlan"):
-            brace_depth = 1
-            result.append(line)
-            continue
-        if brace_depth:
-            brace_depth += line.count("{") - line.count("}")
-            result.append(line)
-            if brace_depth == 0:
-                break
-    return "\n".join(result) if result else None
-
-
 def update_test(opt_basename: str, ti: common.TestInfo):
     triple_in_ir = None
     for l in ti.input_lines:
@@ -120,33 +99,22 @@ def update_test(opt_basename: str, ti: common.TestInfo):
 
         raw_tool_outputs = common.invoke_tool(ti.args.opt_binary, opt_args, ti.path)
 
-        # Detect VPlan output for LV pass. Don't use VPlan mode if filters are
-        # active since the user is likely filtering to specific LV debug lines
-        # (e.g., cost model).
-        is_vplan_output = (
-            not ti.args.filters
-            and re.search(r"VPlan 'Initial VPlan", raw_tool_outputs) is not None
-        )
-
         regex_map = {
             r"Printing analysis ": common.ANALYZE_FUNCTION_RE,
             r"(LV|LDist|HashRecognize): Checking a loop in ": common.LOOP_PASS_DEBUG_RE,
+            r"VPlan for loop in ": common.VPLAN_RE,
         }
 
         for split_by, regex in regex_map.items():
             if re.search(split_by, raw_tool_outputs) is None:
                 continue
             for raw_tool_output in re.split(split_by, raw_tool_outputs):
-                if is_vplan_output:
-                    vplan_output = extract_vplan(raw_tool_output)
-                    if not vplan_output:
-                        continue
-                    # Reconstruct minimal output: function header line + VPlan
-                    func_header = raw_tool_output.split("\n")[0]
-                    raw_tool_output = "\n".join([func_header, vplan_output])
-
                 # For VPlan mode, don't scrub whitespace - preserve exact alignment
-                scrubber = (lambda body: body) if is_vplan_output else common.scrub_body
+                scrubber = (
+                    (lambda body: body)
+                    if regex == common.VPLAN_RE
+                    else common.scrub_body
+                )
                 builder.process_run_line(
                     regex,
                     scrubber,

>From 4126254e946bc367d64e807cb76764f3ee3b2704 Mon Sep 17 00:00:00 2001
From: Andrei Elovikov <andrei.elovikov at sifive.com>
Date: Tue, 10 Feb 2026 09:31:12 -0800
Subject: [PATCH 3/5] [VPlan] Add VPlan-dump-based test for predication

To be used for mask optimization PRs, e.g.
https://github.com/llvm/llvm-project/pull/173265

I'm adding a new `vplan-print-limit-to-vector-region` command line
option here to narrow the dumps to relevant pieces only.

Based on https://github.com/llvm/llvm-project/pull/178736.
---
 .../Transforms/Vectorize/LoopVectorize.cpp    |   8 +-
 .../Transforms/Vectorize/VPlanTransforms.h    |   6 +-
 .../Transforms/LoopVectorize/predicator.ll    | 389 ++++++++++++++++++
 .../LoopVectorize/vplan-print-after-all.ll    |   1 +
 4 files changed, 402 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/Transforms/LoopVectorize/predicator.ll

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 164d74f1a440d..0ae6d711125ff 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -374,6 +374,11 @@ cl::opt<bool> llvm::VPlanPrintAfterAll(
 cl::list<std::string> llvm::VPlanPrintAfterPasses(
     "vplan-print-after", cl::Hidden,
     cl::desc("Print VPlans after specified VPlan transformations (regexp)."));
+
+cl::opt<bool> llvm::VPlanPrintLimitToVectorRegion(
+    "vplan-print-limit-to-vector-region", cl::init(false), cl::Hidden,
+    cl::desc("Limit VPlan printing to vector loop region in "
+             "`-vplan-print-after*` if the plan has one."));
 #endif
 
 // This flag enables the stress testing of the VPlan H-CFG construction in the
@@ -8234,7 +8239,8 @@ VPlanPtr LoopVectorizationPlanner::tryToBuildVPlanWithVPRecipes(
   // ---------------------------------------------------------------------------
   // Predicate and linearize the top-level loop region.
   // ---------------------------------------------------------------------------
-  VPlanTransforms::introduceMasksAndLinearize(*Plan, CM.foldTailByMasking());
+  RUN_VPLAN_PASS_NO_VERIFY(VPlanTransforms::introduceMasksAndLinearize, *Plan,
+                           CM.foldTailByMasking());
 
   // ---------------------------------------------------------------------------
   // Construct wide recipes and apply predication for original scalar
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index c4dcf740d6b07..3f28777211470 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -41,6 +41,7 @@ LLVM_ABI_FOR_TEST extern cl::opt<bool> EnableWideActiveLaneMask;
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 LLVM_ABI_FOR_TEST extern cl::opt<bool> VPlanPrintAfterAll;
 LLVM_ABI_FOR_TEST extern cl::list<std::string> VPlanPrintAfterPasses;
+LLVM_ABI_FOR_TEST extern cl::opt<bool> VPlanPrintLimitToVectorRegion;
 #endif
 
 struct VPlanTransforms {
@@ -64,7 +65,10 @@ struct VPlanTransforms {
             << "VPlan for loop in '"
             << Plan.getScalarHeader()->getIRBasicBlock()->getParent()->getName()
             << "' after " << PassName << '\n';
-        dbgs() << Plan << '\n';
+        if (VPlanPrintLimitToVectorRegion && Plan.getVectorLoopRegion())
+          Plan.getVectorLoopRegion()->print(dbgs());
+        else
+          dbgs() << Plan << '\n';
       }
 #endif
       if (VerifyEachVPlan && EnableVerify)
diff --git a/llvm/test/Transforms/LoopVectorize/predicator.ll b/llvm/test/Transforms/LoopVectorize/predicator.ll
new file mode 100644
index 0000000000000..0ff3cb2d8d95c
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/predicator.ll
@@ -0,0 +1,389 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -disable-output < %s -p loop-vectorize -vplan-print-after=introduceMasksAndLinearize -vplan-print-limit-to-vector-region 2>&1 | FileCheck %s
+
+define void @diamond_phi(ptr %a) {
+; CHECK-LABEL: 'diamond_phi'
+; CHECK-NEXT:  <x1> vector loop: {
+; CHECK-NEXT:    vector.body:
+; CHECK-NEXT:      EMIT vp<[[VP3:%[0-9]+]]> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
+; CHECK-NEXT:      ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; CHECK-NEXT:      EMIT ir<%gep> = getelementptr ir<%a>, ir<%iv>
+; CHECK-NEXT:      EMIT ir<%c0> = icmp sle ir<%iv>, ir<0>
+; CHECK-NEXT:    Successor(s): bb2
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb2:
+; CHECK-NEXT:      EMIT vp<[[VP4:%[0-9]+]]> = not ir<%c0>
+; CHECK-NEXT:      EMIT ir<%add2> = add ir<%iv>, ir<2>, vp<[[VP4]]>
+; CHECK-NEXT:    Successor(s): bb1
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb1:
+; CHECK-NEXT:      EMIT ir<%add1> = add ir<%iv>, ir<1>, ir<%c0>
+; CHECK-NEXT:    Successor(s): bb4
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb4:
+; CHECK-NEXT:      EMIT vp<[[VP5:%[0-9]+]]> = or vp<[[VP4]]>, ir<%c0>
+; CHECK-NEXT:      BLEND ir<%phi4> = ir<%add2>/vp<[[VP4]]> ir<%add1>/ir<%c0>
+; CHECK-NEXT:      EMIT store ir<%phi4>, ir<%gep>, vp<[[VP5]]>
+; CHECK-NEXT:      EMIT ir<%iv.next> = add nuw nsw ir<%iv>, ir<1>, vp<[[VP5]]>
+; CHECK-NEXT:      EMIT ir<%ec> = icmp eq ir<%iv.next>, ir<128>, vp<[[VP5]]>
+; CHECK-NEXT:      EMIT vp<%index.next> = add nuw vp<[[VP3]]>, vp<[[VP1:%[0-9]+]]>
+; CHECK-NEXT:      EMIT branch-on-count vp<%index.next>, vp<[[VP2:%[0-9]+]]>
+; CHECK-NEXT:    No successors
+; CHECK-NEXT:  }
+; CHECK-NEXT:  Successor(s): middle.block
+;
+entry:
+  br label %bb0
+
+bb0:
+;          bb0
+;         /  \
+;       bb1  bb2
+;         \  /
+;          bb4
+; TODO: bb4 should be unmasked.
+  %iv = phi i64 [0, %entry], [%iv.next, %bb4]
+  %gep = getelementptr i64, ptr %a, i64 %iv
+  %c0 = icmp sle i64 %iv, 0
+  br i1 %c0, label %bb1, label %bb2
+
+bb1:
+  %add1 = add i64 %iv, 1
+  br label %bb4
+
+bb2:
+  %add2 = add i64 %iv, 2
+  br label %bb4
+
+bb4:
+  %phi4 = phi i64 [%add1, %bb1], [%add2, %bb2]
+  store i64 %phi4, ptr %gep
+  %iv.next = add nsw nuw i64 %iv, 1
+  %ec = icmp eq i64 %iv.next, 128
+  br i1 %ec, label %exit, label %bb0
+
+exit:
+  ret void
+}
+
+define void @mask_reuse(ptr %a) {
+; CHECK-LABEL: 'mask_reuse'
+; CHECK-NEXT:  <x1> vector loop: {
+; CHECK-NEXT:    vector.body:
+; CHECK-NEXT:      EMIT vp<[[VP3:%[0-9]+]]> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
+; CHECK-NEXT:      ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; CHECK-NEXT:      EMIT ir<%gep> = getelementptr ir<%a>, ir<%iv>
+; CHECK-NEXT:      EMIT ir<%c0> = icmp sle ir<%iv>, ir<0>
+; CHECK-NEXT:      EMIT ir<%add0> = add ir<%iv>, ir<0>
+; CHECK-NEXT:    Successor(s): bb1
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb1:
+; CHECK-NEXT:      EMIT ir<%add1> = add ir<%iv>, ir<1>, ir<%c0>
+; CHECK-NEXT:      EMIT ir<%c1> = icmp sle ir<%iv>, ir<1>, ir<%c0>
+; CHECK-NEXT:    Successor(s): bb2
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb2:
+; CHECK-NEXT:      EMIT vp<[[VP4:%[0-9]+]]> = logical-and ir<%c0>, ir<%c1>
+; CHECK-NEXT:      EMIT ir<%add2> = add ir<%iv>, ir<2>, vp<[[VP4]]>
+; CHECK-NEXT:    Successor(s): bb3
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb3:
+; CHECK-NEXT:      EMIT vp<[[VP5:%[0-9]+]]> = not ir<%c1>
+; CHECK-NEXT:      EMIT vp<[[VP6:%[0-9]+]]> = logical-and ir<%c0>, vp<[[VP5]]>
+; CHECK-NEXT:      EMIT vp<[[VP7:%[0-9]+]]> = or vp<[[VP4]]>, vp<[[VP6]]>
+; CHECK-NEXT:      BLEND ir<%phi3> = ir<%add2>/vp<[[VP4]]> ir<%add1>/vp<[[VP6]]>
+; CHECK-NEXT:      EMIT ir<%add3> = add ir<%iv>, ir<3>, vp<[[VP7]]>
+; CHECK-NEXT:    Successor(s): bb4
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb4:
+; CHECK-NEXT:      EMIT vp<[[VP8:%[0-9]+]]> = not ir<%c0>
+; CHECK-NEXT:      EMIT vp<[[VP9:%[0-9]+]]> = or vp<[[VP7]]>, vp<[[VP8]]>
+; CHECK-NEXT:      BLEND ir<%phi4> = ir<%add3>/vp<[[VP7]]> ir<%add0>/vp<[[VP8]]>
+; CHECK-NEXT:      EMIT store ir<%phi4>, ir<%gep>, vp<[[VP9]]>
+; CHECK-NEXT:      EMIT ir<%iv.next> = add nuw nsw ir<%iv>, ir<1>, vp<[[VP9]]>
+; CHECK-NEXT:      EMIT ir<%ec> = icmp eq ir<%iv.next>, ir<128>, vp<[[VP9]]>
+; CHECK-NEXT:      EMIT vp<%index.next> = add nuw vp<[[VP3]]>, vp<[[VP1:%[0-9]+]]>
+; CHECK-NEXT:      EMIT branch-on-count vp<%index.next>, vp<[[VP2:%[0-9]+]]>
+; CHECK-NEXT:    No successors
+; CHECK-NEXT:  }
+; CHECK-NEXT:  Successor(s): middle.block
+;
+entry:
+  br label %bb0
+
+bb0:
+;         bb0:
+;         / \
+;      bb1   \
+;       /\    \
+;     bb2 |   |
+;      \  |   |
+;       bb3  /
+;         \ /
+;         bb4
+; TODO: bb3 can reuse bb1's mask and bb4 should be unmasked.
+  %iv = phi i64 [0, %entry], [%iv.next, %bb4]
+  %gep = getelementptr i64, ptr %a, i64 %iv
+  %c0 = icmp sle i64 %iv, 0
+  %add0 = add i64 %iv, 0
+  br i1 %c0, label %bb1, label %bb4
+
+bb1:
+  %add1 = add i64 %iv, 1
+  %c1 = icmp sle i64 %iv, 1
+  br i1 %c1, label %bb2, label %bb3
+
+bb2:
+  %add2 = add i64 %iv, 2
+  br label %bb3
+
+bb3:
+  %phi3 = phi i64 [%add1, %bb1], [%add2, %bb2]
+  %add3 = add i64 %iv, 3
+  br label %bb4
+
+bb4:
+  %phi4 = phi i64 [%add3, %bb3], [%add0, %bb0]
+  store i64 %phi4, ptr %gep
+  %iv.next = add nsw nuw i64 %iv, 1
+  %ec = icmp eq i64 %iv.next, 128
+  br i1 %ec, label %exit, label %bb0
+
+exit:
+  ret void
+}
+
+define void @optimized_mask(ptr %a) {
+; CHECK-LABEL: 'optimized_mask'
+; CHECK-NEXT:  <x1> vector loop: {
+; CHECK-NEXT:    vector.body:
+; CHECK-NEXT:      EMIT vp<[[VP3:%[0-9]+]]> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
+; CHECK-NEXT:      ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; CHECK-NEXT:      EMIT ir<%gep> = getelementptr ir<%a>, ir<%iv>
+; CHECK-NEXT:      EMIT ir<%c0> = icmp sle ir<%iv>, ir<0>
+; CHECK-NEXT:    Successor(s): bb6
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb6:
+; CHECK-NEXT:      EMIT vp<[[VP4:%[0-9]+]]> = not ir<%c0>
+; CHECK-NEXT:      EMIT ir<%add6> = add ir<%iv>, ir<6>, vp<[[VP4]]>
+; CHECK-NEXT:      EMIT ir<%c6> = icmp sle ir<%iv>, ir<6>, vp<[[VP4]]>
+; CHECK-NEXT:    Successor(s): bb1
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb1:
+; CHECK-NEXT:      EMIT ir<%add1> = add ir<%iv>, ir<1>, ir<%c0>
+; CHECK-NEXT:      EMIT ir<%c1> = icmp sle ir<%iv>, ir<1>, ir<%c0>
+; CHECK-NEXT:    Successor(s): bb3
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb3:
+; CHECK-NEXT:      EMIT vp<[[VP5:%[0-9]+]]> = not ir<%c1>
+; CHECK-NEXT:      EMIT vp<[[VP6:%[0-9]+]]> = logical-and ir<%c0>, vp<[[VP5]]>
+; CHECK-NEXT:      EMIT ir<%add3> = add ir<%iv>, ir<3>, vp<[[VP6]]>
+; CHECK-NEXT:      EMIT ir<%c3> = icmp sle ir<%iv>, ir<3>, vp<[[VP6]]>
+; CHECK-NEXT:    Successor(s): bb2
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb2:
+; CHECK-NEXT:      EMIT vp<[[VP7:%[0-9]+]]> = logical-and ir<%c0>, ir<%c1>
+; CHECK-NEXT:      EMIT ir<%add2> = add ir<%iv>, ir<2>, vp<[[VP7]]>
+; CHECK-NEXT:    Successor(s): bb4
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb4:
+; CHECK-NEXT:      EMIT vp<[[VP8:%[0-9]+]]> = logical-and vp<[[VP6]]>, ir<%c3>
+; CHECK-NEXT:      EMIT vp<[[VP9:%[0-9]+]]> = or vp<[[VP8]]>, vp<[[VP7]]>
+; CHECK-NEXT:      BLEND ir<%phi4> = ir<%add3>/vp<[[VP8]]> ir<%add2>/vp<[[VP7]]>
+; CHECK-NEXT:      EMIT ir<%add4> = add ir<%iv>, ir<4>, vp<[[VP9]]>
+; CHECK-NEXT:    Successor(s): bb5
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb5:
+; CHECK-NEXT:      EMIT vp<[[VP10:%[0-9]+]]> = logical-and vp<[[VP4]]>, ir<%c6>
+; CHECK-NEXT:      EMIT vp<[[VP11:%[0-9]+]]> = or vp<[[VP10]]>, vp<[[VP9]]>
+; CHECK-NEXT:      EMIT vp<[[VP12:%[0-9]+]]> = not ir<%c3>
+; CHECK-NEXT:      EMIT vp<[[VP13:%[0-9]+]]> = logical-and vp<[[VP6]]>, vp<[[VP12]]>
+; CHECK-NEXT:      EMIT vp<[[VP14:%[0-9]+]]> = or vp<[[VP11]]>, vp<[[VP13]]>
+; CHECK-NEXT:      BLEND ir<%phi5> = ir<%add6>/vp<[[VP10]]> ir<%add4>/vp<[[VP9]]> ir<%add3>/vp<[[VP13]]>
+; CHECK-NEXT:      EMIT ir<%add5> = add ir<%iv>, ir<5>, vp<[[VP14]]>
+; CHECK-NEXT:    Successor(s): bb7
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb7:
+; CHECK-NEXT:      EMIT vp<[[VP15:%[0-9]+]]> = not ir<%c6>
+; CHECK-NEXT:      EMIT vp<[[VP16:%[0-9]+]]> = logical-and vp<[[VP4]]>, vp<[[VP15]]>
+; CHECK-NEXT:      EMIT vp<[[VP17:%[0-9]+]]> = or vp<[[VP16]]>, vp<[[VP14]]>
+; CHECK-NEXT:      BLEND ir<%phi7> = ir<%add6>/vp<[[VP16]]> ir<%add5>/vp<[[VP14]]>
+; CHECK-NEXT:      EMIT store ir<%phi7>, ir<%gep>, vp<[[VP17]]>
+; CHECK-NEXT:      EMIT ir<%iv.next> = add nuw nsw ir<%iv>, ir<1>, vp<[[VP17]]>
+; CHECK-NEXT:      EMIT ir<%ec> = icmp eq ir<%iv.next>, ir<128>, vp<[[VP17]]>
+; CHECK-NEXT:      EMIT vp<%index.next> = add nuw vp<[[VP3]]>, vp<[[VP1:%[0-9]+]]>
+; CHECK-NEXT:      EMIT branch-on-count vp<%index.next>, vp<[[VP2:%[0-9]+]]>
+; CHECK-NEXT:    No successors
+; CHECK-NEXT:  }
+; CHECK-NEXT:  Successor(s): middle.block
+;
+entry:
+  br label %bb0
+
+bb0:
+;               bb0:
+;              /   \
+;             /     \
+;          bb1       bb6
+;          /  \      / |
+;        bb2  bb3   /  /
+;          \  /|   /  /
+;           bb4|  /  /
+;            \ | /  /
+;             bb5  /
+;               \ /
+;               bb7
+; TODO: bb5's mask shouldn't depend on c1/c3.
+  %iv = phi i64 [0, %entry], [%iv.next, %bb7]
+  %gep = getelementptr i64, ptr %a, i64 %iv
+  %c0 = icmp sle i64 %iv, 0
+  br i1 %c0, label %bb1, label %bb6
+
+bb1:
+  %add1 = add i64 %iv, 1
+  %c1 = icmp sle i64 %iv, 1
+  br i1 %c1, label %bb2, label %bb3
+
+bb2:
+  %add2 = add i64 %iv, 2
+  br label %bb4
+
+bb3:
+  %add3 = add i64 %iv, 3
+  %c3 = icmp sle i64 %iv, 3
+  br i1 %c3, label %bb4, label %bb5
+
+bb4:
+  %phi4 = phi i64 [%add2, %bb2], [%add3, %bb3]
+  %add4 = add i64 %iv, 4
+  br label %bb5
+
+bb5:
+  %phi5 = phi i64 [%add4, %bb4], [%add3, %bb3], [%add6, %bb6]
+  %add5 = add i64 %iv, 5
+  br label %bb7
+
+bb6:
+  %add6 = add i64 %iv, 6
+  %c6 = icmp sle i64 %iv, 6
+  br i1 %c6, label %bb5, label %bb7
+
+bb7:
+  %phi7 = phi i64 [%add5, %bb5], [%add6, %bb6]
+  store i64 %phi7, ptr %gep
+  %iv.next = add nsw nuw i64 %iv, 1
+  %ec = icmp eq i64 %iv.next, 128
+  br i1 %ec, label %exit, label %bb0
+
+exit:
+  ret void
+}
+
+define void @switch(ptr %a) {
+; CHECK-LABEL: 'switch'
+; CHECK-NEXT:  <x1> vector loop: {
+; CHECK-NEXT:    vector.body:
+; CHECK-NEXT:      EMIT vp<[[VP3:%[0-9]+]]> = CANONICAL-INDUCTION ir<0>, vp<%index.next>
+; CHECK-NEXT:      ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; CHECK-NEXT:      EMIT ir<%gep> = getelementptr ir<%a>, ir<%iv>
+; CHECK-NEXT:      EMIT ir<%c0> = icmp sle ir<%iv>, ir<0>
+; CHECK-NEXT:      EMIT ir<%add0> = add ir<%iv>, ir<0>
+; CHECK-NEXT:    Successor(s): bb2
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb2:
+; CHECK-NEXT:      EMIT vp<[[VP4:%[0-9]+]]> = not ir<%c0>
+; CHECK-NEXT:      EMIT ir<%add2> = add ir<%iv>, ir<2>, vp<[[VP4]]>
+; CHECK-NEXT:      EMIT ir<%c2> = icmp sle ir<%iv>, ir<2>, vp<[[VP4]]>
+; CHECK-NEXT:    Successor(s): bb1
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb1:
+; CHECK-NEXT:      EMIT ir<%add1> = add ir<%iv>, ir<1>, ir<%c0>
+; CHECK-NEXT:    Successor(s): bb3
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb3:
+; CHECK-NEXT:      EMIT vp<[[VP5:%[0-9]+]]> = logical-and vp<[[VP4]]>, ir<%c2>
+; CHECK-NEXT:      EMIT vp<[[VP6:%[0-9]+]]> = icmp eq ir<%iv>, ir<1>
+; CHECK-NEXT:      EMIT vp<[[VP7:%[0-9]+]]> = icmp eq ir<%iv>, ir<2>
+; CHECK-NEXT:      EMIT vp<[[VP8:%[0-9]+]]> = icmp eq ir<%iv>, ir<3>
+; CHECK-NEXT:      EMIT vp<[[VP9:%[0-9]+]]> = logical-and ir<%c0>, vp<[[VP6]]>
+; CHECK-NEXT:      EMIT vp<[[VP10:%[0-9]+]]> = or vp<[[VP7]]>, vp<[[VP8]]>
+; CHECK-NEXT:      EMIT vp<[[VP11:%[0-9]+]]> = logical-and ir<%c0>, vp<[[VP10]]>
+; CHECK-NEXT:      EMIT vp<[[VP12:%[0-9]+]]> = or vp<[[VP9]]>, vp<[[VP11]]>
+; CHECK-NEXT:      EMIT vp<[[VP13:%[0-9]+]]> = not vp<[[VP12]]>
+; CHECK-NEXT:      EMIT vp<[[VP14:%[0-9]+]]> = logical-and ir<%c0>, vp<[[VP13]]>
+; CHECK-NEXT:      EMIT vp<[[VP15:%[0-9]+]]> = or vp<[[VP5]]>, vp<[[VP11]]>
+; CHECK-NEXT:      BLEND ir<%phi3> = ir<%add2>/vp<[[VP5]]> ir<%add1>/vp<[[VP11]]> ir<%add1>/vp<[[VP11]]>
+; CHECK-NEXT:      EMIT ir<%add3> = add ir<%iv>, ir<3>, vp<[[VP15]]>
+; CHECK-NEXT:    Successor(s): bb4
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb4:
+; CHECK-NEXT:      EMIT ir<%add4> = add ir<%iv>, ir<4>, vp<[[VP9]]>
+; CHECK-NEXT:    Successor(s): bb5
+; CHECK-EMPTY:
+; CHECK-NEXT:    bb5:
+; CHECK-NEXT:      EMIT vp<[[VP16:%[0-9]+]]> = or vp<[[VP9]]>, vp<[[VP15]]>
+; CHECK-NEXT:      EMIT vp<[[VP17:%[0-9]+]]> = not ir<%c2>
+; CHECK-NEXT:      EMIT vp<[[VP18:%[0-9]+]]> = logical-and vp<[[VP4]]>, vp<[[VP17]]>
+; CHECK-NEXT:      EMIT vp<[[VP19:%[0-9]+]]> = or vp<[[VP16]]>, vp<[[VP18]]>
+; CHECK-NEXT:      EMIT vp<[[VP20:%[0-9]+]]> = or vp<[[VP19]]>, vp<[[VP14]]>
+; CHECK-NEXT:      BLEND ir<%phi5> = ir<%add4>/vp<[[VP9]]> ir<%add3>/vp<[[VP15]]> ir<%add2>/vp<[[VP18]]> ir<%add1>/vp<[[VP14]]>
+; CHECK-NEXT:      EMIT store ir<%phi5>, ir<%gep>, vp<[[VP20]]>
+; CHECK-NEXT:      EMIT ir<%iv.next> = add nuw nsw ir<%iv>, ir<1>, vp<[[VP20]]>
+; CHECK-NEXT:      EMIT ir<%ec> = icmp eq ir<%iv.next>, ir<128>, vp<[[VP20]]>
+; CHECK-NEXT:      EMIT vp<%index.next> = add nuw vp<[[VP3]]>, vp<[[VP1:%[0-9]+]]>
+; CHECK-NEXT:      EMIT branch-on-count vp<%index.next>, vp<[[VP2:%[0-9]+]]>
+; CHECK-NEXT:    No successors
+; CHECK-NEXT:  }
+; CHECK-NEXT:  Successor(s): middle.block
+;
+entry:
+  br label %bb0
+
+bb0:
+;         bb0:
+;         / \
+;      bb1-+ bb2
+;     / | \| /\
+;     \bb4 bb3|
+;      \ \ | /
+;       +>bb5
+; Test for blends at switch destinations, including multiple edges from switch
+; to a single block (bb3).
+  %iv = phi i64 [0, %entry], [%iv.next, %bb5]
+  %gep = getelementptr i64, ptr %a, i64 %iv
+  %c0 = icmp sle i64 %iv, 0
+  %add0 = add i64 %iv, 0
+  br i1 %c0, label %bb1, label %bb2
+
+bb1:
+  %add1 = add i64 %iv, 1
+  switch i64 %iv, label %bb5 [
+    i64 1, label %bb4
+    i64 2, label %bb3
+    i64 3, label %bb3
+  ]
+
+bb2:
+  %add2 = add i64 %iv, 2
+  %c2 = icmp sle i64 %iv, 2
+  br i1 %c2, label %bb3, label %bb5
+
+bb3:
+  %phi3 = phi i64 [%add1, %bb1], [%add1, %bb1], [%add2, %bb2]
+  %add3 = add i64 %iv, 3
+  br label %bb5
+
+bb4:
+  %add4 = add i64 %iv, 4
+  br label %bb5
+
+bb5:
+  %phi5 = phi i64 [%add1, %bb1], [%add2, %bb2], [%add3, %bb3], [%add4, %bb4]
+  store i64 %phi5, ptr %gep
+  %iv.next = add nsw nuw i64 %iv, 1
+  %ec = icmp eq i64 %iv.next, 128
+  br i1 %ec, label %exit, label %bb0
+
+exit:
+  ret void
+}
diff --git a/llvm/test/Transforms/LoopVectorize/vplan-print-after-all.ll b/llvm/test/Transforms/LoopVectorize/vplan-print-after-all.ll
index ae09cb1b1002e..5c133cc757010 100644
--- a/llvm/test/Transforms/LoopVectorize/vplan-print-after-all.ll
+++ b/llvm/test/Transforms/LoopVectorize/vplan-print-after-all.ll
@@ -5,6 +5,7 @@
 ; Verify that `-vplan-print-after-all` option works.
 
 ; CHECK: VPlan for loop in 'foo' after printAfterInitialConstruction
+; CHECK: VPlan for loop in 'foo' after VPlanTransforms::introduceMasksAndLinearize
 ; CHECK: VPlan for loop in 'foo' after VPlanTransforms::clearReductionWrapFlags
 ; CHECK: VPlan for loop in 'foo' after VPlanTransforms::optimizeFindIVReductions
 ; CHECK: VPlan for loop in 'foo' after VPlanTransforms::handleMultiUseReductions

>From de7e27f790cbb270bdabd535c354c3b212951364 Mon Sep 17 00:00:00 2001
From: Andrei Elovikov <andrei.elovikov at sifive.com>
Date: Wed, 11 Feb 2026 08:34:22 -0800
Subject: [PATCH 4/5] Move to `VPlan/`

---
 llvm/test/Transforms/LoopVectorize/{ => VPlan}/predicator.ll | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
 rename llvm/test/Transforms/LoopVectorize/{ => VPlan}/predicator.ll (99%)

diff --git a/llvm/test/Transforms/LoopVectorize/predicator.ll b/llvm/test/Transforms/LoopVectorize/VPlan/predicator.ll
similarity index 99%
rename from llvm/test/Transforms/LoopVectorize/predicator.ll
rename to llvm/test/Transforms/LoopVectorize/VPlan/predicator.ll
index 0ff3cb2d8d95c..e630095f25ef0 100644
--- a/llvm/test/Transforms/LoopVectorize/predicator.ll
+++ b/llvm/test/Transforms/LoopVectorize/VPlan/predicator.ll
@@ -1,5 +1,5 @@
 ; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --version 6
-; RUN: opt -disable-output < %s -p loop-vectorize -vplan-print-after=introduceMasksAndLinearize -vplan-print-limit-to-vector-region 2>&1 | FileCheck %s
+; RUN: opt -disable-output < %s -p loop-vectorize -vplan-print-after=introduceMasksAndLinearize -vplan-print-vector-region-scope 2>&1 | FileCheck %s
 
 define void @diamond_phi(ptr %a) {
 ; CHECK-LABEL: 'diamond_phi'

>From d8cd913b367b4f97ecc58b708eb2e897f71e9a1a Mon Sep 17 00:00:00 2001
From: Andrei Elovikov <andrei.elovikov at sifive.com>
Date: Wed, 11 Feb 2026 08:34:35 -0800
Subject: [PATCH 5/5] Rename option to `-vplan-print-vector-region-scope`

---
 llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 4 ++--
 llvm/lib/Transforms/Vectorize/VPlanTransforms.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
index 0ae6d711125ff..11a98df756d6c 100644
--- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -375,8 +375,8 @@ cl::list<std::string> llvm::VPlanPrintAfterPasses(
     "vplan-print-after", cl::Hidden,
     cl::desc("Print VPlans after specified VPlan transformations (regexp)."));
 
-cl::opt<bool> llvm::VPlanPrintLimitToVectorRegion(
-    "vplan-print-limit-to-vector-region", cl::init(false), cl::Hidden,
+cl::opt<bool> llvm::VPlanPrintVectorRegionScope(
+    "vplan-print-vector-region-scope", cl::init(false), cl::Hidden,
     cl::desc("Limit VPlan printing to vector loop region in "
              "`-vplan-print-after*` if the plan has one."));
 #endif
diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
index 3f28777211470..a1cb2d1d83afe 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h
@@ -41,7 +41,7 @@ LLVM_ABI_FOR_TEST extern cl::opt<bool> EnableWideActiveLaneMask;
 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
 LLVM_ABI_FOR_TEST extern cl::opt<bool> VPlanPrintAfterAll;
 LLVM_ABI_FOR_TEST extern cl::list<std::string> VPlanPrintAfterPasses;
-LLVM_ABI_FOR_TEST extern cl::opt<bool> VPlanPrintLimitToVectorRegion;
+LLVM_ABI_FOR_TEST extern cl::opt<bool> VPlanPrintVectorRegionScope;
 #endif
 
 struct VPlanTransforms {
@@ -65,7 +65,7 @@ struct VPlanTransforms {
             << "VPlan for loop in '"
             << Plan.getScalarHeader()->getIRBasicBlock()->getParent()->getName()
             << "' after " << PassName << '\n';
-        if (VPlanPrintLimitToVectorRegion && Plan.getVectorLoopRegion())
+        if (VPlanPrintVectorRegionScope && Plan.getVectorLoopRegion())
           Plan.getVectorLoopRegion()->print(dbgs());
         else
           dbgs() << Plan << '\n';



More information about the llvm-commits mailing list