[llvm] [VPlan] Pre-commit test for VPWidenCanonicalIVRecipe cost (NFC) (PR #195014)
Madhur Amilkanthwar via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 23:30:43 PDT 2026
https://github.com/madhur13490 created https://github.com/llvm/llvm-project/pull/195014
Add a small test that checks the cost reported for `VPWidenCanonicalIVRecipe` under tail folding. The recipe widens the canonical IV so its lane values can feed an active-lane-mask compare, and is currently charged a cost of 0.
>From 959472785c330a845b1ed7a2520a5f0e7f3ee195 Mon Sep 17 00:00:00 2001
From: Madhur Amilkanthwar <madhura at nvidia.com>
Date: Wed, 29 Apr 2026 23:06:41 -0700
Subject: [PATCH] [VPlan] Pre-commit test for VPWidenCanonicalIVRecipe cost
(NFC)
Add a small test that pins the cost reported for
VPWidenCanonicalIVRecipe under tail folding. The recipe widens the
canonical IV so its lane values can feed an active-lane-mask compare,
and is currently charged a cost of 0.
---
.../VPlan/widen-canonical-iv-cost.ll | 36 +++++++++++++++++++
1 file changed, 36 insertions(+)
create mode 100644 llvm/test/Transforms/LoopVectorize/VPlan/widen-canonical-iv-cost.ll
diff --git a/llvm/test/Transforms/LoopVectorize/VPlan/widen-canonical-iv-cost.ll b/llvm/test/Transforms/LoopVectorize/VPlan/widen-canonical-iv-cost.ll
new file mode 100644
index 0000000000000..8fc14b6f46ceb
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/VPlan/widen-canonical-iv-cost.ll
@@ -0,0 +1,36 @@
+; REQUIRES: asserts
+; RUN: opt -passes=loop-vectorize -force-vector-width=4 \
+; RUN: -force-target-supports-masked-memory-ops -tail-folding-policy=must-fold-tail \
+; RUN: -debug-only=loop-vectorize -disable-output %s 2>&1 | FileCheck %s
+
+; Two reductions force the canonical IV to be widened so its lane values
+; can feed the active-lane-mask compare under tail folding. Check the
+; cost reported for VPWidenCanonicalIVRecipe.
+
+; CHECK-LABEL: LV: Checking a loop in 'two_reductions'
+; CHECK: Cost of 0 for VF 4: EMIT vp<{{.*}}> = WIDEN-CANONICAL-INDUCTION
+
+define i32 @two_reductions(i64 %N, ptr %a, ptr %b) {
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+ %sum.a = phi i32 [ 0, %entry ], [ %sum.a.next, %loop ]
+ %sum.b = phi i32 [ 0, %entry ], [ %sum.b.next, %loop ]
+ %ga = getelementptr inbounds i32, ptr %a, i64 %iv
+ %gb = getelementptr inbounds i32, ptr %b, i64 %iv
+ %la = load i32, ptr %ga, align 4
+ %lb = load i32, ptr %gb, align 4
+ %sum.a.next = add i32 %sum.a, %la
+ %sum.b.next = add i32 %sum.b, %lb
+ %iv.next = add nuw nsw i64 %iv, 1
+ %ec = icmp eq i64 %iv.next, %N
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ %r.a = phi i32 [ %sum.a.next, %loop ]
+ %r.b = phi i32 [ %sum.b.next, %loop ]
+ %res = add i32 %r.a, %r.b
+ ret i32 %res
+}
More information about the llvm-commits
mailing list