[llvm] [Vplan] Tighten m_CanonicalIV() (PR #194312)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 27 01:26:41 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-vectorizers
Author: Madhur Amilkanthwar (madhur13490)
<details>
<summary>Changes</summary>
Previously `m_CanonicalIV()` matched any `VPRegionValue`, which was only correct because the canonical IV is the sole `VPRegionValue` today. Going ahead this is not scalable and there may be more `VPRegionValue`.
---
Full diff: https://github.com/llvm/llvm-project/pull/194312.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h (+9-4)
- (modified) llvm/unittests/Transforms/Vectorize/VPlanPatternMatchTest.cpp (+15)
``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
index 242046480f6e9..78368be40aef5 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
@@ -785,10 +785,15 @@ inline auto m_c_LogicalOr(const Op0_t &Op0, const Op1_t &Op1) {
return m_c_Select(Op0, m_True(), Op1);
}
-inline auto m_CanonicalIV() {
- // TODO: Don't assume all region values are canonical IVs.
- return m_Isa<VPRegionValue>();
-}
+/// Match the canonical induction variable (IV) of any loop region.
+struct canonical_iv_match {
+ template <typename ArgTy> bool match(const ArgTy *V) const {
+ const auto *RV = dyn_cast<VPRegionValue>(V);
+ return RV && RV->getDefiningRegion()->getCanonicalIV() == RV;
+ }
+};
+
+inline canonical_iv_match m_CanonicalIV() { return {}; }
template <typename Op0_t, typename Op1_t, typename Op2_t>
inline auto m_ScalarIVSteps(const Op0_t &Op0, const Op1_t &Op1,
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanPatternMatchTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanPatternMatchTest.cpp
index 167ba13ede4d0..d5ed68d1f3dc2 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanPatternMatchTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanPatternMatchTest.cpp
@@ -50,6 +50,21 @@ TEST_F(VPPatternMatchTest, ScalarIVSteps) {
m_Specific(VF))));
}
+TEST_F(VPPatternMatchTest, CanonicalIV) {
+ VPlan &Plan = getPlan();
+ IntegerType *I64Ty = IntegerType::get(C, 64);
+ VPRegionBlock *VPR =
+ Plan.createLoopRegion(I64Ty, DebugLoc::getCompilerGenerated());
+ VPValue *CanIV = VPR->getCanonicalIV();
+
+ using namespace VPlanPatternMatch;
+
+ ASSERT_TRUE(match(CanIV, m_CanonicalIV()));
+
+ VPValue *LiveIn = Plan.getOrAddLiveIn(ConstantInt::get(I64Ty, 1));
+ ASSERT_FALSE(match(LiveIn, m_CanonicalIV()));
+}
+
TEST_F(VPPatternMatchTest, GetElementPtr) {
VPlan &Plan = getPlan();
VPBasicBlock *VPBB = Plan.createVPBasicBlock("entry");
``````````
</details>
https://github.com/llvm/llvm-project/pull/194312
More information about the llvm-commits
mailing list