[llvm] 4245b1d - [LV] Add cost printing test with forced instruction costs (NFC). (#222895)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 11 03:49:11 PDT 2026


Author: Florian Hahn
Date: 2026-09-11T11:49:06+01:00
New Revision: 4245b1dbc9d439c16c378486544f47a77b72ca53

URL: https://github.com/llvm/llvm-project/commit/4245b1dbc9d439c16c378486544f47a77b72ca53
DIFF: https://github.com/llvm/llvm-project/commit/4245b1dbc9d439c16c378486544f47a77b72ca53.diff

LOG: [LV] Add cost printing test with forced instruction costs (NFC). (#222895)

Add a test printing the cost of all recipes in the vector loop region
with -force-target-instruction-cost. Currently the flag is ignored for
VPDerivedIVRecipe and VPScalarIVStepsRecipe.

Added: 
    llvm/test/Transforms/LoopVectorize/force-instruction-cost.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/LoopVectorize/force-instruction-cost.ll b/llvm/test/Transforms/LoopVectorize/force-instruction-cost.ll
new file mode 100644
index 0000000000000..d0d83c3aa2df9
--- /dev/null
+++ b/llvm/test/Transforms/LoopVectorize/force-instruction-cost.ll
@@ -0,0 +1,77 @@
+; NOTE: Assertions have been autogenerated by utils/update_analyze_test_checks.py UTC_ARGS: --filter "Cost of" --filter-out-after "EMIT branch-on-count" --version 6
+; REQUIRES: asserts
+; RUN: opt -passes=loop-vectorize -force-vector-width=2 -force-target-instruction-cost=1 -debug-only=loop-vectorize -disable-output %s 2>&1 | FileCheck --check-prefix=FORCED1 %s
+; RUN: opt -passes=loop-vectorize -force-vector-width=2 -force-target-instruction-cost=3 -debug-only=loop-vectorize -disable-output %s 2>&1 | FileCheck --check-prefix=FORCED3 %s
+
+define void @int_induction(ptr noalias %dst, i64 %n) {
+; FORCED1-LABEL: 'int_induction'
+; FORCED1:  Cost of 1 for VF 2: ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; FORCED1:  Cost of 0 for VF 2: vp<[[VP4:%[0-9]+]]> = SCALAR-STEPS vp<[[VP3:%[0-9]+]]>, ir<1>, vp<[[VP0]]>
+; FORCED1:  Cost of 1 for VF 2: CLONE ir<%gep> = getelementptr inbounds ir<%dst>, vp<[[VP4]]>
+; FORCED1:  Cost of 0 for VF 2: vp<[[VP5:%[0-9]+]]> = vector-pointer inbounds i64, ir<%gep>, ir<1>
+; FORCED1:  Cost of 1 for VF 2: WIDEN store vp<[[VP5]]>, ir<%iv>
+; FORCED1:  Cost of 0 for VF 2: EMIT vp<%index.next> = add nuw vp<[[VP3]]>, vp<[[VP1:%[0-9]+]]>
+; FORCED1:  Cost of 0 for VF 2: EMIT branch-on-count vp<%index.next>, vp<[[VP2:%[0-9]+]]>
+;
+; FORCED3-LABEL: 'int_induction'
+; FORCED3:  Cost of 3 for VF 2: ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; FORCED3:  Cost of 0 for VF 2: vp<[[VP4:%[0-9]+]]> = SCALAR-STEPS vp<[[VP3:%[0-9]+]]>, ir<1>, vp<[[VP0]]>
+; FORCED3:  Cost of 3 for VF 2: CLONE ir<%gep> = getelementptr inbounds ir<%dst>, vp<[[VP4]]>
+; FORCED3:  Cost of 0 for VF 2: vp<[[VP5:%[0-9]+]]> = vector-pointer inbounds i64, ir<%gep>, ir<1>
+; FORCED3:  Cost of 3 for VF 2: WIDEN store vp<[[VP5]]>, ir<%iv>
+; FORCED3:  Cost of 0 for VF 2: EMIT vp<%index.next> = add nuw vp<[[VP3]]>, vp<[[VP1:%[0-9]+]]>
+; FORCED3:  Cost of 0 for VF 2: EMIT branch-on-count vp<%index.next>, vp<[[VP2:%[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_scalar_users(ptr noalias %dst, i64 %n) {
+; FORCED1-LABEL: 'fp_induction_scalar_users'
+; FORCED1:  Cost of 1 for VF 2: ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; FORCED1:  Cost of 0 for VF 2: vp<[[VP5:%[0-9]+]]> = DERIVED-IV ir<0.000000e+00> + vp<[[VP4:%[0-9]+]]> * ir<1.000000e+00>
+; FORCED1:  Cost of 0 for VF 2: vp<[[VP6:%[0-9]+]]> = SCALAR-STEPS vp<[[VP5]]>, ir<1.000000e+00>, vp<[[VP0]]>
+; FORCED1:  Cost of 1 for VF 2: WIDEN ir<%idx> = mul ir<%iv>, ir<3>
+; FORCED1:  Cost of 1 for VF 2: REPLICATE ir<%gep> = getelementptr inbounds ir<%dst>, ir<%idx>
+; FORCED1:  Cost of 1 for VF 2: REPLICATE store vp<[[VP6]]>, ir<%gep>
+; FORCED1:  Cost of 0 for VF 2: EMIT vp<%index.next> = add nuw vp<[[VP4]]>, vp<[[VP1:%[0-9]+]]>
+; FORCED1:  Cost of 0 for VF 2: EMIT branch-on-count vp<%index.next>, vp<[[VP2:%[0-9]+]]>
+;
+; FORCED3-LABEL: 'fp_induction_scalar_users'
+; FORCED3:  Cost of 3 for VF 2: ir<%iv> = WIDEN-INDUCTION nuw nsw ir<0>, ir<1>, vp<[[VP0:%[0-9]+]]>
+; FORCED3:  Cost of 0 for VF 2: vp<[[VP5:%[0-9]+]]> = DERIVED-IV ir<0.000000e+00> + vp<[[VP4:%[0-9]+]]> * ir<1.000000e+00>
+; FORCED3:  Cost of 0 for VF 2: vp<[[VP6:%[0-9]+]]> = SCALAR-STEPS vp<[[VP5]]>, ir<1.000000e+00>, vp<[[VP0]]>
+; FORCED3:  Cost of 3 for VF 2: WIDEN ir<%idx> = mul ir<%iv>, ir<3>
+; FORCED3:  Cost of 3 for VF 2: REPLICATE ir<%gep> = getelementptr inbounds ir<%dst>, ir<%idx>
+; FORCED3:  Cost of 3 for VF 2: REPLICATE store vp<[[VP6]]>, ir<%gep>
+; FORCED3:  Cost of 0 for VF 2: EMIT vp<%index.next> = add nuw vp<[[VP4]]>, vp<[[VP1:%[0-9]+]]>
+; FORCED3:  Cost of 0 for VF 2: EMIT branch-on-count vp<%index.next>, vp<[[VP2:%[0-9]+]]>
+;
+entry:
+  br label %loop
+
+loop:
+  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
+  %fp.iv = phi float [ 0.000000e+00, %entry ], [ %fp.iv.next, %loop ]
+  %idx = mul i64 %iv, 3
+  %gep = getelementptr inbounds float, ptr %dst, i64 %idx
+  store float %fp.iv, ptr %gep, align 4
+  %fp.iv.next = fadd fast float %fp.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
+}


        


More information about the llvm-commits mailing list