[llvm] [VPlan] Strip VPDT-assert forbidding replicate regions (PR #189342)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 2 08:28:58 PDT 2026
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/189342
>From c4d0b7046321e64590c2fabe45732cfa5ca34666 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Mon, 30 Mar 2026 09:56:03 +0100
Subject: [PATCH 1/4] [VPlan] Strip VPDT-assert forbidding replicate regions
(NFC)
VPDominatorTree::properlyDominates currently unnecessarily forbids
replicate regions, as there is no such limitation either in the parent
DominatorTree, or in VPlanCFG. Strip the assert entirely.
---
.../lib/Transforms/Vectorize/VPlanAnalysis.cpp | 18 ------------------
1 file changed, 18 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
index 9667227a329ac..2f6377614a9bf 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
+++ b/llvm/lib/Transforms/Vectorize/VPlanAnalysis.cpp
@@ -391,24 +391,6 @@ bool VPDominatorTree::properlyDominates(const VPRecipeBase *A,
if (ParentA == ParentB)
return LocalComesBefore(A, B);
-#ifndef NDEBUG
- auto GetReplicateRegion = [](VPRecipeBase *R) -> VPRegionBlock * {
- VPRegionBlock *Region = R->getRegion();
- if (Region && Region->isReplicator()) {
- assert(Region->getNumSuccessors() == 1 &&
- Region->getNumPredecessors() == 1 && "Expected SESE region!");
- assert(R->getParent()->size() == 1 &&
- "A recipe in an original replicator region must be the only "
- "recipe in its block");
- return Region;
- }
- return nullptr;
- };
- assert(!GetReplicateRegion(const_cast<VPRecipeBase *>(A)) &&
- "No replicate regions expected at this point");
- assert(!GetReplicateRegion(const_cast<VPRecipeBase *>(B)) &&
- "No replicate regions expected at this point");
-#endif
return Base::properlyDominates(ParentA, ParentB);
}
>From 6a244453370dda6b146acf41a1dcf0bc75365607 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Tue, 31 Mar 2026 22:13:23 +0100
Subject: [PATCH 2/4] [VPlan] Add VPDomTreeTest
---
.../Transforms/Vectorize/VPDomTreeTest.cpp | 65 ++++++++++++++++++-
1 file changed, 64 insertions(+), 1 deletion(-)
diff --git a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
index e108c4d77c5a9..0c964bdd0b902 100644
--- a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
@@ -175,7 +175,7 @@ TEST_F(VPDominatorTreeTest, DominanceRegionsTest) {
VPBasicBlock *R2BB1 = Plan.createVPBasicBlock("R2BB1");
VPBasicBlock *R2BB2 = Plan.createVPBasicBlock("R2BB2");
- VPBasicBlock *R2BB3 = Plan.createVPBasicBlock("R2BB#");
+ VPBasicBlock *R2BB3 = Plan.createVPBasicBlock("R2BB3");
VPRegionBlock *R2 = Plan.createLoopRegion("R2", R2BB1, R2BB3);
R2BB2->setParent(R2);
VPBlockUtils::connectBlocks(R2BB1, R2BB2);
@@ -208,6 +208,69 @@ TEST_F(VPDominatorTreeTest, DominanceRegionsTest) {
checkDomChildren(VPDT, R1BB3, {VPBB2});
checkDomChildren(VPDT, VPBB2, {Plan.getScalarHeader()});
}
+
+ {
+ // 2 nested replicate regions.
+ // VPBB1
+ // |
+ // R1 {
+ // R1BB1
+ // / \
+ // R2 { |
+ // \ |
+ // R2BB1 |
+ // | \ R1BB2
+ // R2BB2-/ |
+ // \ |
+ // R2BB3 |
+ // } /
+ // \ /
+ // R1BB3
+ // }
+ // |
+ // VPBB2
+ //
+ VPlan &Plan = getPlan();
+ VPBasicBlock *R1BB1 = Plan.createVPBasicBlock("R1BB1");
+ VPBasicBlock *R1BB2 = Plan.createVPBasicBlock("R1BB2");
+ VPBasicBlock *R1BB3 = Plan.createVPBasicBlock("R1BB3");
+ VPRegionBlock *R1 = Plan.createReplicateRegion(R1BB1, R1BB3, "R1");
+
+ VPBasicBlock *R2BB1 = Plan.createVPBasicBlock("R2BB1");
+ VPBasicBlock *R2BB2 = Plan.createVPBasicBlock("R2BB2");
+ VPBasicBlock *R2BB3 = Plan.createVPBasicBlock("R2BB3");
+ VPRegionBlock *R2 = Plan.createReplicateRegion(R2BB1, R2BB3, "R2");
+ R2BB2->setParent(R2);
+ VPBlockUtils::connectBlocks(R2BB1, R2BB2);
+ VPBlockUtils::connectBlocks(R2BB2, R2BB1);
+ VPBlockUtils::connectBlocks(R2BB2, R2BB3);
+
+ R2->setParent(R1);
+ VPBlockUtils::connectBlocks(R1BB1, R2);
+ R1BB2->setParent(R1);
+ VPBlockUtils::connectBlocks(R1BB1, R1BB2);
+ VPBlockUtils::connectBlocks(R1BB2, R1BB3);
+ VPBlockUtils::connectBlocks(R2, R1BB3);
+
+ VPBasicBlock *VPBB1 = Plan.getEntry();
+ VPBlockUtils::connectBlocks(VPBB1, R1);
+ VPBasicBlock *VPBB2 = Plan.createVPBasicBlock("VPBB2");
+ VPBlockUtils::connectBlocks(R1, VPBB2);
+
+ VPBlockUtils::connectBlocks(VPBB2, Plan.getScalarHeader());
+ VPDominatorTree VPDT(Plan);
+
+ checkDomChildren(VPDT, VPBB1, {R1});
+ checkDomChildren(VPDT, R1, {R1BB1});
+ checkDomChildren(VPDT, R1BB1, {R2, R1BB3, R1BB2});
+ checkDomChildren(VPDT, R1BB2, {});
+ checkDomChildren(VPDT, R2, {R2BB1});
+ checkDomChildren(VPDT, R2BB1, {R2BB2});
+ checkDomChildren(VPDT, R2BB2, {R2BB3});
+ checkDomChildren(VPDT, R2BB3, {});
+ checkDomChildren(VPDT, R1BB3, {VPBB2});
+ checkDomChildren(VPDT, VPBB2, {Plan.getScalarHeader()});
+ }
}
} // namespace
>From 83a2b6a9561a796b234249b74cd6f98861366bb5 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Thu, 2 Apr 2026 10:59:18 +0100
Subject: [PATCH 3/4] [VPDomTreeTest] Improve ascii diagram in comments
---
.../Transforms/Vectorize/VPDomTreeTest.cpp | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
index 0c964bdd0b902..41bdccbf3ebed 100644
--- a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
@@ -151,12 +151,12 @@ TEST_F(VPDominatorTreeTest, DominanceRegionsTest) {
// VPBB1
// |
// R1 {
- // R1BB1
- // / \
+ // R1BB1 <-+
+ // / |
// R2 { |
// \ |
- // R2BB1 |
- // | \ R1BB2
+ // R2BB1<-+ |
+ // | | R1BB2
// R2BB2-/ |
// \ |
// R2BB3 |
@@ -214,12 +214,12 @@ TEST_F(VPDominatorTreeTest, DominanceRegionsTest) {
// VPBB1
// |
// R1 {
- // R1BB1
- // / \
+ // R1BB1 <-+
+ // / |
// R2 { |
// \ |
- // R2BB1 |
- // | \ R1BB2
+ // R2BB1<-+ |
+ // | | R1BB2
// R2BB2-/ |
// \ |
// R2BB3 |
>From 784714fc0b4dd69db9c7907cbf275dba3333879e Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Thu, 2 Apr 2026 15:51:42 +0100
Subject: [PATCH 4/4] [VPlan] Add missing tests, thanks Florian!
---
.../unittests/Transforms/Vectorize/VPDomTreeTest.cpp | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
index 41bdccbf3ebed..fe9012682f4bf 100644
--- a/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPDomTreeTest.cpp
@@ -270,6 +270,18 @@ TEST_F(VPDominatorTreeTest, DominanceRegionsTest) {
checkDomChildren(VPDT, R2BB3, {});
checkDomChildren(VPDT, R1BB3, {VPBB2});
checkDomChildren(VPDT, VPBB2, {Plan.getScalarHeader()});
+
+ EXPECT_FALSE(VPDT.properlyDominates(R1BB1, R1BB1));
+ EXPECT_FALSE(VPDT.properlyDominates(R2, R1BB3));
+ EXPECT_FALSE(VPDT.properlyDominates(R2, R1BB2));
+ EXPECT_TRUE(VPDT.properlyDominates(R1BB1, R2));
+ EXPECT_TRUE(VPDT.properlyDominates(R1BB1, R1BB2));
+ EXPECT_TRUE(VPDT.properlyDominates(R1BB1, R1BB3));
+ EXPECT_TRUE(VPDT.properlyDominates(R2, R2BB1));
+ EXPECT_TRUE(VPDT.properlyDominates(R2, R2BB2));
+ EXPECT_TRUE(VPDT.properlyDominates(R2, R2BB3));
+ EXPECT_TRUE(VPDT.properlyDominates(R2BB1, R2BB2));
+ EXPECT_TRUE(VPDT.properlyDominates(R2BB1, R2BB3));
}
}
More information about the llvm-commits
mailing list