[llvm] [SLP][NFC]Add a test with non-profitable vectorization, NFC (PR #218122)

via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 22 04:30:05 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-risc-v

Author: Alexey Bataev (alexey-bataev)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/218122.diff


1 Files Affected:

- (added) llvm/test/Transforms/SLPVectorizer/RISCV/spillcost-loop-invariant-entry.ll (+66) 


``````````diff
diff --git a/llvm/test/Transforms/SLPVectorizer/RISCV/spillcost-loop-invariant-entry.ll b/llvm/test/Transforms/SLPVectorizer/RISCV/spillcost-loop-invariant-entry.ll
new file mode 100644
index 0000000000000..01b69b46af8ea
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/RISCV/spillcost-loop-invariant-entry.ll
@@ -0,0 +1,66 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -S < %s -passes=slp-vectorizer -mtriple=riscv64 -mattr=+v | FileCheck %s
+
+declare void @g()
+declare double @llvm.sqrt.f64(double)
+
+; The vectorized fdiv/sqrt entry is loop-invariant and emitted in the
+; preheader, but its vector value is live across the call in the loop body
+; and must be spilled/reloaded on every iteration. The spill cost must be
+; scaled by the loop trip count, which makes this marginal tree unprofitable,
+; so it must stay scalar.
+define void @invariant_entry_over_call(ptr %out, ptr %in, ptr %sink, double %a, double %b, double %c, double %d, i64 %n) {
+; CHECK-LABEL: define void @invariant_entry_over_call(
+; CHECK-SAME: ptr [[OUT:%.*]], ptr [[IN:%.*]], ptr [[SINK:%.*]], double [[A:%.*]], double [[B:%.*]], double [[C:%.*]], double [[D:%.*]], i64 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x double> poison, double [[A]], i64 0
+; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <2 x double> [[TMP0]], double [[B]], i64 1
+; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <2 x double> poison, double [[C]], i64 0
+; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <2 x double> [[TMP2]], double [[D]], i64 1
+; CHECK-NEXT:    [[TMP4:%.*]] = fdiv <2 x double> [[TMP1]], [[TMP3]]
+; CHECK-NEXT:    [[TMP5:%.*]] = call <2 x double> @llvm.sqrt.v2f64(<2 x double> [[TMP4]])
+; CHECK-NEXT:    br label %[[LOOP:.*]]
+; CHECK:       [[LOOP]]:
+; CHECK-NEXT:    [[I:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[INC:%.*]], %[[LOOP]] ]
+; CHECK-NEXT:    [[P0:%.*]] = getelementptr inbounds double, ptr [[IN]], i64 [[I]]
+; CHECK-NEXT:    [[O0:%.*]] = getelementptr inbounds double, ptr [[OUT]], i64 [[I]]
+; CHECK-NEXT:    [[TMP6:%.*]] = load <2 x double>, ptr [[P0]], align 8
+; CHECK-NEXT:    [[TMP7:%.*]] = fmul <2 x double> [[TMP6]], [[TMP5]]
+; CHECK-NEXT:    store <2 x double> [[TMP7]], ptr [[O0]], align 8
+; CHECK-NEXT:    call void @g()
+; CHECK-NEXT:    [[INC]] = add nuw nsw i64 [[I]], 2
+; CHECK-NEXT:    [[CMP:%.*]] = icmp ult i64 [[INC]], [[N]]
+; CHECK-NEXT:    br i1 [[CMP]], label %[[LOOP]], label %[[EXIT:.*]]
+; CHECK:       [[EXIT]]:
+; CHECK-NEXT:    [[M1:%.*]] = extractelement <2 x double> [[TMP7]], i64 1
+; CHECK-NEXT:    store double [[M1]], ptr [[SINK]], align 8
+; CHECK-NEXT:    ret void
+;
+entry:
+  %div0 = fdiv double %a, %c
+  %div1 = fdiv double %b, %d
+  %sq0 = call double @llvm.sqrt.f64(double %div0)
+  %sq1 = call double @llvm.sqrt.f64(double %div1)
+  br label %loop
+
+loop:
+  %i = phi i64 [ 0, %entry ], [ %inc, %loop ]
+  %p0 = getelementptr inbounds double, ptr %in, i64 %i
+  %v0 = load double, ptr %p0, align 8
+  %p1 = getelementptr inbounds double, ptr %p0, i64 1
+  %v1 = load double, ptr %p1, align 8
+  %m0 = fmul double %v0, %sq0
+  %m1 = fmul double %v1, %sq1
+  %o0 = getelementptr inbounds double, ptr %out, i64 %i
+  store double %m0, ptr %o0, align 8
+  %o1 = getelementptr inbounds double, ptr %o0, i64 1
+  store double %m1, ptr %o1, align 8
+  call void @g()
+  %inc = add nuw nsw i64 %i, 2
+  %cmp = icmp ult i64 %inc, %n
+  br i1 %cmp, label %loop, label %exit
+
+exit:
+  store double %m1, ptr %sink, align 8
+  ret void
+}

``````````

</details>


https://github.com/llvm/llvm-project/pull/218122


More information about the llvm-commits mailing list