[llvm] c6a51ba - [LV] Add cost tests for induction recipes (NFC). (#203376)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 11 13:03:44 PDT 2026
Author: Florian Hahn
Date: 2026-06-11T20:03:39Z
New Revision: c6a51bab81e5637201d54d680654562a6936a618
URL: https://github.com/llvm/llvm-project/commit/c6a51bab81e5637201d54d680654562a6936a618
DIFF: https://github.com/llvm/llvm-project/commit/c6a51bab81e5637201d54d680654562a6936a618.diff
LOG: [LV] Add cost tests for induction recipes (NFC). (#203376)
Added:
llvm/test/Transforms/LoopVectorize/induction-cost.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/Transforms/LoopVectorize/induction-cost.ll b/llvm/test/Transforms/LoopVectorize/induction-cost.ll
new file mode 100644
index 0000000000000..057424e2d0d63
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/induction-cost.ll
@@ -0,0 +1,98 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --filter "(Cost.*WIDEN-INDUCTION)|(induction instruction)"
+; REQUIRES: asserts
+; RUN: opt -passes=loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -debug-only=loop-vectorize -disable-output %s 2>&1 | FileCheck %s
+
+define void @int_induction(ptr noalias %dst, i64 %n) {
+; CHECK-LABEL: 'int_induction'
+; CHECK: Cost of 1 for VF 4: induction instruction %iv.next = add nuw nsw i64 %iv, 1
+; CHECK: Cost of 1 for VF 4: induction instruction %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK: Cost of 0 for VF 4: ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+ %gep = getelementptr inbounds i64, ptr %dst, i64 %iv
+ store i64 %iv, ptr %gep, align 8
+ %iv.next = add nuw nsw i64 %iv, 1
+ %ec = icmp eq i64 %iv.next, %n
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+define void @fp_induction(ptr noalias %dst, i64 %n) {
+; CHECK-LABEL: 'fp_induction'
+; CHECK: Cost of 1 for VF 4: induction instruction %iv.next = add nuw nsw i64 %iv, 1
+; CHECK: Cost of 1 for VF 4: induction instruction %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK: Cost of 1 for VF 4: induction instruction %f.next = fadd fast float %f.iv, 1.000000e+00
+; CHECK: Cost of 1 for VF 4: induction instruction %f.iv = phi float [ 0.000000e+00, %entry ], [ %f.next, %loop ]
+; CHECK: Cost of 0 for VF 4: ir<%f.iv> = WIDEN-INDUCTION fast ir<0.000000e+00>, ir<1.000000e+00>, vp<[[VP0:%[0-9]+]]>
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+ %f.iv = phi float [ 0.000000e+00, %entry ], [ %f.next, %loop ]
+ %gep = getelementptr inbounds float, ptr %dst, i64 %iv
+ store float %f.iv, ptr %gep, align 4
+ %f.next = fadd fast float %f.iv, 1.000000e+00
+ %iv.next = add nuw nsw i64 %iv, 1
+ %ec = icmp eq i64 %iv.next, %n
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+define void @trunc_induction(ptr noalias %dst, i64 %n) {
+; CHECK-LABEL: 'trunc_induction'
+; CHECK: Cost of 1 for VF 4: induction instruction %iv.next = add nuw nsw i64 %iv, 1
+; CHECK: Cost of 1 for VF 4: induction instruction %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK: Cost of 1 for VF 4: induction instruction %iv.trunc = trunc i64 %iv to i32
+; CHECK: Cost of 0 for VF 4: ir<%iv> = WIDEN-INDUCTION ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]> (truncated to i32)
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+ %iv.trunc = trunc i64 %iv to i32
+ %gep = getelementptr inbounds i32, ptr %dst, i64 %iv
+ store i32 %iv.trunc, ptr %gep, align 4
+ %iv.next = add nuw nsw i64 %iv, 1
+ %ec = icmp eq i64 %iv.next, %n
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
+
+define void @trunc_and_wide_induction(ptr noalias %dst, ptr noalias %dst2, i64 %n) {
+; CHECK-LABEL: 'trunc_and_wide_induction'
+; CHECK: Cost of 1 for VF 4: induction instruction %iv.next = add nuw nsw i64 %iv, 1
+; CHECK: Cost of 1 for VF 4: induction instruction %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+; CHECK: Cost of 1 for VF 4: induction instruction %iv.trunc = trunc i64 %iv to i32
+; CHECK: Cost of 0 for VF 4: ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; CHECK: Cost of 0 for VF 4: ir<%iv>.1 = WIDEN-INDUCTION ir<0>, ir<1>, vp<[[VP0]]> (truncated to i32)
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+ %iv.trunc = trunc i64 %iv to i32
+ %gep = getelementptr inbounds i32, ptr %dst, i64 %iv
+ store i32 %iv.trunc, ptr %gep, align 4
+ %gep2 = getelementptr inbounds i64, ptr %dst2, i64 %iv
+ store i64 %iv, ptr %gep2, align 8
+ %iv.next = add nuw nsw i64 %iv, 1
+ %ec = icmp eq i64 %iv.next, %n
+ br i1 %ec, label %exit, label %loop
+
+exit:
+ ret void
+}
More information about the llvm-commits
mailing list