[llvm] [SLP][NFC]Add some more tests for loop accumulated reductions, NFC (PR #221597)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 6 12:11:16 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alexey Bataev (alexey-bataev)
<details>
<summary>Changes</summary>
---
Patch is 50.83 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/221597.diff
1 Files Affected:
- (modified) llvm/test/Transforms/SLPVectorizer/AArch64/loop-accumulator-reduction.ll (+1019-8)
``````````diff
diff --git a/llvm/test/Transforms/SLPVectorizer/AArch64/loop-accumulator-reduction.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/loop-accumulator-reduction.ll
index 552698e8b8576..256d16254ea29 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/loop-accumulator-reduction.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/loop-accumulator-reduction.ll
@@ -255,7 +255,7 @@ define double @loop_acc_fadd_leftover(ptr %p, i64 %n) {
; CHECK-NEXT: [[A01:%.*]] = fmul fast double [[L1]], [[C1]]
; CHECK-NEXT: [[A02:%.*]] = fadd fast double [[A01]], [[A00]]
; CHECK-NEXT: [[A03:%.*]] = fmul fast double [[L2]], [[C2]]
-; CHECK-NEXT: [[A:%.*]] = fadd fast double [[A02]], [[A03]]
+; CHECK-NEXT: [[F:%.*]] = fadd fast double [[A02]], [[A03]]
; CHECK-NEXT: [[B00:%.*]] = fmul fast double [[L0]], [[C3]]
; CHECK-NEXT: [[B01:%.*]] = fmul fast double [[L1]], [[C4]]
; CHECK-NEXT: [[B02:%.*]] = fadd fast double [[B01]], [[B00]]
@@ -266,17 +266,17 @@ define double @loop_acc_fadd_leftover(ptr %p, i64 %n) {
; CHECK-NEXT: [[D02:%.*]] = fadd fast double [[D01]], [[D00]]
; CHECK-NEXT: [[D03:%.*]] = fmul fast double [[L2]], [[C8]]
; CHECK-NEXT: [[D:%.*]] = fadd fast double [[D02]], [[D03]]
-; CHECK-NEXT: [[E:%.*]] = fadd fast double [[A]], [[B]]
-; CHECK-NEXT: [[F:%.*]] = fadd fast double [[D]], [[A]]
-; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x double> poison, double [[A]], i64 0
+; CHECK-NEXT: [[E:%.*]] = fadd fast double [[F]], [[B]]
+; CHECK-NEXT: [[F1:%.*]] = fadd fast double [[D]], [[F]]
+; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x double> poison, double [[F]], i64 0
; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x double> [[TMP0]], double [[B]], i64 1
; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x double> [[TMP1]], double [[D]], i64 2
; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x double> [[TMP2]], double [[E]], i64 3
; CHECK-NEXT: [[TMP4:%.*]] = fmul <4 x double> [[TMP3]], [[TMP3]]
-; CHECK-NEXT: [[SF:%.*]] = fmul double [[F]], [[F]]
-; CHECK-NEXT: [[TMP5:%.*]] = call fast double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP4]])
-; CHECK-NEXT: [[OP_RDX:%.*]] = fadd fast double [[TMP5]], [[SF]]
-; CHECK-NEXT: [[OP_RDX1]] = fadd fast double [[OP_RDX]], [[ACC]]
+; CHECK-NEXT: [[SF1:%.*]] = fmul double [[F1]], [[F1]]
+; CHECK-NEXT: [[T4:%.*]] = call fast double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP4]])
+; CHECK-NEXT: [[SUM:%.*]] = fadd fast double [[T4]], [[SF1]]
+; CHECK-NEXT: [[OP_RDX1]] = fadd fast double [[SUM]], [[ACC]]
; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[IV]], [[N]]
; CHECK-NEXT: br i1 [[CMP]], label %[[EXIT:.*]], label %[[LOOP]]
@@ -341,3 +341,1014 @@ exit:
%res = phi double [ %sum, %loop ]
ret double %res
}
+
+; Loop-carried fmax reduction with nnan only: the identity constant is
+; defined via getReductionIdentity, no nsz required.
+define double @loop_acc_fmax(ptr %p, i64 %n) {
+; CHECK-LABEL: define double @loop_acc_fmax(
+; CHECK-SAME: ptr [[P:%.*]], i64 [[N:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: br label %[[LOOP:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 1, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[C2:%.*]] = phi double [ 0.000000e+00, %[[ENTRY]] ], [ [[M3:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr double, ptr [[P]], i64 [[IV]]
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x double>, ptr [[P0]], align 8
+; CHECK-NEXT: [[L3:%.*]] = call nnan double @llvm.vector.reduce.fmax.v4f64(<4 x double> [[TMP0]])
+; CHECK-NEXT: [[M3]] = call nnan double @llvm.maxnum.f64(double [[L3]], double [[C2]])
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[IV]], [[N]]
+; CHECK-NEXT: br i1 [[CMP]], label %[[EXIT:.*]], label %[[LOOP]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: [[TMP2:%.*]] = phi double [ [[M3]], %[[LOOP]] ]
+; CHECK-NEXT: ret double [[TMP2]]
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]
+ %acc = phi double [ 0.000000e+00, %entry ], [ %m3, %loop ]
+ %p0 = getelementptr double, ptr %p, i64 %iv
+ %l0 = load double, ptr %p0, align 8
+ %p1 = getelementptr double, ptr %p0, i64 1
+ %l1 = load double, ptr %p1, align 8
+ %p2 = getelementptr double, ptr %p0, i64 2
+ %l2 = load double, ptr %p2, align 8
+ %p3 = getelementptr double, ptr %p0, i64 3
+ %l3 = load double, ptr %p3, align 8
+ %c0 = call nnan double @llvm.maxnum.f64(double %l0, double %acc)
+ %c1 = call nnan double @llvm.maxnum.f64(double %l1, double %c0)
+ %c2 = call nnan double @llvm.maxnum.f64(double %l2, double %c1)
+ %m3 = call nnan double @llvm.maxnum.f64(double %l3, double %c2)
+ %iv.next = add nuw nsw i64 %iv, 1
+ %cmp = icmp eq i64 %iv, %n
+ br i1 %cmp, label %exit, label %loop
+
+exit:
+ %res = phi double [ %m3, %loop ]
+ ret double %res
+}
+
+; The root has an in-loop non-phi use: no vector accumulator, the
+; phi is folded back on top of the emitted reduction.
+define double @root_stored(ptr %p, i64 %n, ptr %o) {
+; CHECK-LABEL: define double @root_stored(
+; CHECK-SAME: ptr [[P:%.*]], i64 [[N:%.*]], ptr [[O:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: br label %[[LOOP:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 1, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[ACC:%.*]] = phi double [ 0.000000e+00, %[[ENTRY]] ], [ [[TMP23:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[IV3:%.*]] = mul nuw i64 [[IV]], 3
+; CHECK-NEXT: [[P0:%.*]] = getelementptr double, ptr [[P]], i64 [[IV3]]
+; CHECK-NEXT: [[P1:%.*]] = getelementptr double, ptr [[P0]], i64 1
+; CHECK-NEXT: [[P2:%.*]] = getelementptr double, ptr [[P0]], i64 2
+; CHECK-NEXT: [[L2:%.*]] = load double, ptr [[P2]], align 8
+; CHECK-NEXT: [[C8:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 8), align 8
+; CHECK-NEXT: [[L1:%.*]] = load double, ptr [[P1]], align 8
+; CHECK-NEXT: [[L0:%.*]] = load double, ptr [[P0]], align 8
+; CHECK-NEXT: [[C7:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 7), align 8
+; CHECK-NEXT: [[C6:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 6), align 8
+; CHECK-NEXT: [[C5:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 5), align 8
+; CHECK-NEXT: [[C4:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 4), align 8
+; CHECK-NEXT: [[C3:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 3), align 8
+; CHECK-NEXT: [[C2:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 2), align 8
+; CHECK-NEXT: [[C1:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 1), align 8
+; CHECK-NEXT: [[C0:%.*]] = load double, ptr @cst, align 8
+; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x double> <double poison, double -0.000000e+00, double poison, double poison>, double [[L0]], i64 0
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x double> [[TMP0]], <4 x double> poison, <4 x i32> <i32 0, i32 0, i32 0, i32 1>
+; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x double> <double poison, double poison, double poison, double 1.000000e+00>, double [[C0]], i64 0
+; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x double> [[TMP2]], double [[C3]], i64 1
+; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x double> [[TMP3]], double [[C6]], i64 2
+; CHECK-NEXT: [[TMP5:%.*]] = fmul fast <4 x double> [[TMP1]], [[TMP4]]
+; CHECK-NEXT: [[TMP11:%.*]] = insertelement <4 x double> poison, double [[L1]], i64 0
+; CHECK-NEXT: [[TMP6:%.*]] = insertelement <4 x double> [[TMP11]], double [[ACC]], i64 1
+; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <4 x double> [[TMP6]], <4 x double> poison, <4 x i32> <i32 0, i32 0, i32 0, i32 1>
+; CHECK-NEXT: [[TMP8:%.*]] = insertelement <4 x double> <double poison, double poison, double poison, double 1.000000e+00>, double [[C1]], i64 0
+; CHECK-NEXT: [[TMP9:%.*]] = insertelement <4 x double> [[TMP8]], double [[C4]], i64 1
+; CHECK-NEXT: [[TMP10:%.*]] = insertelement <4 x double> [[TMP9]], double [[C7]], i64 2
+; CHECK-NEXT: [[TMP12:%.*]] = fmul reassoc nsz arcp contract afn <4 x double> [[TMP7]], [[TMP10]]
+; CHECK-NEXT: [[TMP24:%.*]] = fadd reassoc nsz arcp contract afn <4 x double> [[TMP12]], [[TMP5]]
+; CHECK-NEXT: [[TMP13:%.*]] = insertelement <4 x double> <double poison, double -0.000000e+00, double poison, double poison>, double [[L2]], i64 0
+; CHECK-NEXT: [[TMP14:%.*]] = shufflevector <4 x double> [[TMP13]], <4 x double> poison, <4 x i32> <i32 0, i32 0, i32 0, i32 1>
+; CHECK-NEXT: [[TMP15:%.*]] = insertelement <4 x double> <double poison, double poison, double poison, double 1.000000e+00>, double [[C2]], i64 0
+; CHECK-NEXT: [[TMP16:%.*]] = insertelement <4 x double> [[TMP15]], double [[C5]], i64 1
+; CHECK-NEXT: [[TMP17:%.*]] = insertelement <4 x double> [[TMP16]], double [[C8]], i64 2
+; CHECK-NEXT: [[TMP18:%.*]] = fmul fast <4 x double> [[TMP14]], [[TMP17]]
+; CHECK-NEXT: [[TMP19:%.*]] = fadd reassoc nsz arcp contract afn <4 x double> [[TMP24]], [[TMP18]]
+; CHECK-NEXT: [[TMP20:%.*]] = shufflevector <4 x double> [[TMP19]], <4 x double> <double poison, double poison, double poison, double 1.000000e+00>, <4 x i32> <i32 0, i32 1, i32 poison, i32 7>
+; CHECK-NEXT: [[TMP21:%.*]] = shufflevector <4 x double> [[TMP20]], <4 x double> [[TMP19]], <4 x i32> <i32 0, i32 1, i32 6, i32 3>
+; CHECK-NEXT: [[TMP22:%.*]] = fmul <4 x double> [[TMP19]], [[TMP21]]
+; CHECK-NEXT: [[TMP23]] = call fast double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP22]])
+; CHECK-NEXT: store double [[TMP23]], ptr [[O]], align 8
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[IV]], [[N]]
+; CHECK-NEXT: br i1 [[CMP]], label %[[EXIT:.*]], label %[[LOOP]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: [[RES:%.*]] = phi double [ [[TMP23]], %[[LOOP]] ]
+; CHECK-NEXT: ret double [[RES]]
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]
+ %acc = phi double [ 0.000000e+00, %entry ], [ %sum, %loop ]
+ %iv3 = mul nuw i64 %iv, 3
+ %p0 = getelementptr double, ptr %p, i64 %iv3
+ %l0 = load double, ptr %p0, align 8
+ %p1 = getelementptr double, ptr %p0, i64 1
+ %l1 = load double, ptr %p1, align 8
+ %p2 = getelementptr double, ptr %p0, i64 2
+ %l2 = load double, ptr %p2, align 8
+ %c0 = load double, ptr @cst, align 8
+ %c1 = load double, ptr getelementptr (double, ptr @cst, i64 1), align 8
+ %c2 = load double, ptr getelementptr (double, ptr @cst, i64 2), align 8
+ %c3 = load double, ptr getelementptr (double, ptr @cst, i64 3), align 8
+ %c4 = load double, ptr getelementptr (double, ptr @cst, i64 4), align 8
+ %c5 = load double, ptr getelementptr (double, ptr @cst, i64 5), align 8
+ %c6 = load double, ptr getelementptr (double, ptr @cst, i64 6), align 8
+ %c7 = load double, ptr getelementptr (double, ptr @cst, i64 7), align 8
+ %c8 = load double, ptr getelementptr (double, ptr @cst, i64 8), align 8
+ %a00 = fmul fast double %l0, %c0
+ %a01 = fmul fast double %l1, %c1
+ %a02 = fadd fast double %a01, %a00
+ %a03 = fmul fast double %l2, %c2
+ %a = fadd fast double %a02, %a03
+ %b00 = fmul fast double %l0, %c3
+ %b01 = fmul fast double %l1, %c4
+ %b02 = fadd fast double %b01, %b00
+ %b03 = fmul fast double %l2, %c5
+ %b = fadd fast double %b02, %b03
+ %d00 = fmul fast double %l0, %c6
+ %d01 = fmul fast double %l1, %c7
+ %d02 = fadd fast double %d01, %d00
+ %d03 = fmul fast double %l2, %c8
+ %d = fadd fast double %d02, %d03
+ %sa = fmul double %a, %a
+ %t1 = fadd fast double %sa, %acc
+ %sb = fmul double %b, %b
+ %t2 = fadd fast double %t1, %sb
+ %sd = fmul double %d, %d
+ %sum = fadd fast double %t2, %sd
+ store double %sum, ptr %o, align 8
+ %iv.next = add nuw nsw i64 %iv, 1
+ %cmp = icmp eq i64 %iv, %n
+ br i1 %cmp, label %exit, label %loop
+
+exit:
+ %res = phi double [ %sum, %loop ]
+ ret double %res
+}
+
+; Two exit phis in the same block: each gets its own vector exit phi
+; and final reduction.
+define double @two_exit_phis(ptr %p, i64 %n, i1 %c) {
+; CHECK-LABEL: define double @two_exit_phis(
+; CHECK-SAME: ptr [[P:%.*]], i64 [[N:%.*]], i1 [[C:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: br label %[[LOOP:.*]]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 1, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[ACC:%.*]] = phi double [ 0.000000e+00, %[[ENTRY]] ], [ [[TMP25:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[IV3:%.*]] = mul nuw i64 [[IV]], 3
+; CHECK-NEXT: [[P0:%.*]] = getelementptr double, ptr [[P]], i64 [[IV3]]
+; CHECK-NEXT: [[P1:%.*]] = getelementptr double, ptr [[P0]], i64 1
+; CHECK-NEXT: [[P2:%.*]] = getelementptr double, ptr [[P0]], i64 2
+; CHECK-NEXT: [[L2:%.*]] = load double, ptr [[P2]], align 8
+; CHECK-NEXT: [[C8:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 8), align 8
+; CHECK-NEXT: [[L1:%.*]] = load double, ptr [[P1]], align 8
+; CHECK-NEXT: [[L0:%.*]] = load double, ptr [[P0]], align 8
+; CHECK-NEXT: [[C7:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 7), align 8
+; CHECK-NEXT: [[C6:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 6), align 8
+; CHECK-NEXT: [[C5:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 5), align 8
+; CHECK-NEXT: [[C4:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 4), align 8
+; CHECK-NEXT: [[C3:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 3), align 8
+; CHECK-NEXT: [[C2:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 2), align 8
+; CHECK-NEXT: [[C1:%.*]] = load double, ptr getelementptr (double, ptr @cst, i64 1), align 8
+; CHECK-NEXT: [[C0:%.*]] = load double, ptr @cst, align 8
+; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x double> <double poison, double -0.000000e+00, double poison, double poison>, double [[L0]], i64 0
+; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x double> [[TMP0]], <4 x double> poison, <4 x i32> <i32 0, i32 0, i32 0, i32 1>
+; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x double> <double poison, double poison, double poison, double 1.000000e+00>, double [[C0]], i64 0
+; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x double> [[TMP2]], double [[C3]], i64 1
+; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x double> [[TMP3]], double [[C6]], i64 2
+; CHECK-NEXT: [[TMP5:%.*]] = fmul fast <4 x double> [[TMP1]], [[TMP4]]
+; CHECK-NEXT: [[TMP11:%.*]] = insertelement <4 x double> poison, double [[L1]], i64 0
+; CHECK-NEXT: [[TMP6:%.*]] = insertelement <4 x double> [[TMP11]], double [[ACC]], i64 1
+; CHECK-NEXT: [[TMP7:%.*]] = shufflevector <4 x double> [[TMP6]], <4 x double> poison, <4 x i32> <i32 0, i32 0, i32 0, i32 1>
+; CHECK-NEXT: [[TMP8:%.*]] = insertelement <4 x double> <double poison, double poison, double poison, double 1.000000e+00>, double [[C1]], i64 0
+; CHECK-NEXT: [[TMP9:%.*]] = insertelement <4 x double> [[TMP8]], double [[C4]], i64 1
+; CHECK-NEXT: [[TMP10:%.*]] = insertelement <4 x double> [[TMP9]], double [[C7]], i64 2
+; CHECK-NEXT: [[TMP12:%.*]] = fmul reassoc nsz arcp contract afn <4 x double> [[TMP7]], [[TMP10]]
+; CHECK-NEXT: [[TMP26:%.*]] = fadd reassoc nsz arcp contract afn <4 x double> [[TMP12]], [[TMP5]]
+; CHECK-NEXT: [[TMP13:%.*]] = insertelement <4 x double> <double poison, double -0.000000e+00, double poison, double poison>, double [[L2]], i64 0
+; CHECK-NEXT: [[TMP14:%.*]] = shufflevector <4 x double> [[TMP13]], <4 x double> poison, <4 x i32> <i32 0, i32 0, i32 0, i32 1>
+; CHECK-NEXT: [[TMP15:%.*]] = insertelement <4 x double> <double poison, double poison, double poison, double 1.000000e+00>, double [[C2]], i64 0
+; CHECK-NEXT: [[TMP16:%.*]] = insertelement <4 x double> [[TMP15]], double [[C5]], i64 1
+; CHECK-NEXT: [[TMP17:%.*]] = insertelement <4 x double> [[TMP16]], double [[C8]], i64 2
+; CHECK-NEXT: [[TMP18:%.*]] = fmul fast <4 x double> [[TMP14]], [[TMP17]]
+; CHECK-NEXT: [[TMP19:%.*]] = fadd reassoc nsz arcp contract afn <4 x double> [[TMP26]], [[TMP18]]
+; CHECK-NEXT: [[TMP20:%.*]] = shufflevector <4 x double> [[TMP19]], <4 x double> <double poison, double poison, double poison, double 1.000000e+00>, <4 x i32> <i32 0, i32 1, i32 poison, i32 7>
+; CHECK-NEXT: [[TMP21:%.*]] = shufflevector <4 x double> [[TMP20]], <4 x double> [[TMP19]], <4 x i32> <i32 0, i32 1, i32 6, i32 3>
+; CHECK-NEXT: [[TMP22:%.*]] = fmul <4 x double> [[TMP19]], [[TMP21]]
+; CHECK-NEXT: [[TMP25]] = call fast double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP22]])
+; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
+; CHECK-NEXT: [[CMP:%.*]] = icmp eq i64 [[IV]], [[N]]
+; CHECK-NEXT: br i1 [[CMP]], label %[[EXIT:.*]], label %[[LOOP]]
+; CHECK: [[EXIT]]:
+; CHECK-NEXT: [[TMP23:%.*]] = phi double [ [[TMP25]], %[[LOOP]] ]
+; CHECK-NEXT: [[TMP24:%.*]] = phi double [ [[TMP25]], %[[LOOP]] ]
+; CHECK-NEXT: [[R:%.*]] = fadd double [[TMP23]], [[TMP24]]
+; CHECK-NEXT: ret double [[R]]
+;
+entry:
+ br label %loop
+
+loop:
+ %iv = phi i64 [ 1, %entry ], [ %iv.next, %loop ]
+ %acc = phi double [ 0.000000e+00, %entry ], [ %sum, %loop ]
+ %iv3 = mul nuw i64 %iv, 3
+ %p0 = getelementptr double, ptr %p, i64 %iv3
+ %l0 = load double, ptr %p0, align 8
+ %p1 = getelementptr double, ptr %p0, i64 1
+ %l1 = load double, ptr %p1, align 8
+ %p2 = getelementptr double, ptr %p0, i64 2
+ %l2 = load double, ptr %p2, align 8
+ %c0 = load double, ptr @cst, align 8
+ %c1 = load double, ptr getelementptr (double, ptr @cst, i64 1), align 8
+ %c2 = load double, ptr getelementptr (double, ptr @cst, i64 2), align 8
+ %c3 = load double, ptr getelementptr (double, ptr @cst, i64 3), align 8
+ %c4 = load double, ptr getelementptr (double, ptr @cst, i64 4), align 8
+ %c5 = load double, ptr getelementptr (double, ptr @cst, i64 5), align 8
+ %c6 = load double, ptr getelementptr (double, ptr @cst, i64 6), align 8
+ %c7 = load double, ptr getelementptr (double, ptr @cst, i64 7), align 8
+ %c8 = load double, ptr getelementptr (double, ptr @cst, i64 8), align 8
+ %a00 = fmul fast double %l0, %c0
+ %a01 = fmul fast double %l1, %c1
+ %a02 = fadd fast double %a01, %a00
+ %a03 = fmul fast double %l2, %c2
+ %a = fadd fast double %a02, %a03
+ %b00 = fmul fast double %l0, %c3
+ %b01 = fmul fast double %l1, %c4
+ %b02 = fadd fast double %b01, %b00
+ %b03 = fmul fast double %l2, %c5
+ %b = fadd fast double %b02, %b03
+ %d00 = fmul fast double %l0, %c6
+ %d01 = fmul fast double %l1, %c7
+ %d02 = fadd fast double %d01, %d00
+ %d03 = fmul fast double %l2, %c8
+ %d = fadd fast double %d02, %d03
+ %sa = fmul double %a, %a
+ %t1 = fadd fast double %sa, %acc
+ %sb = fmul double %b, %b
+ %t2 = fadd fast double %t1, %sb
+ %sd = fmul double %d, %d
+ %sum = fadd fast double %t2, %sd
+ %iv.next = add nuw nsw i64 %iv, 1
+ %cmp = icmp eq i64 %iv, %n
+ br i1 %cmp, label %exit, label %loop
+
+exit:
+ %res = phi double [ %sum, %loop ]
+ %res2 = phi double [ %sum, %loop ]
+ %r = fadd double %res, %res2
+ ret double %r
+}
+
+; The accumulator phi has two entries for the preheader (switch with two
+; edges): a single insert of the initial value is shared by both entries.
+define double @dup_preheader_edges(ptr %p, i64 %n, double %init, i32 %sw) {
+; CHECK-LABEL: define double @dup_preheader_edges(
+; CHECK-SAME: ptr [[P:%.*]], i64 [[N:%.*]], double [[INIT:%.*]], i32 [[SW:%.*]]) {
+; CHECK-NEXT: [[ENTRY:.*]]:
+; CHECK-NEXT: switch i32 [[SW]], label %[[LOOP:.*]] [
+; CHECK-NEXT: i32 1, label %[[LOOP]]
+; CHECK-NEXT: ]
+; CHECK: [[LOOP]]:
+; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 1, %[[ENTRY]] ], [ 1, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[ACC:%.*]] = phi double [ [[INIT]], %[[ENTRY]] ], [ [[INIT]], %[[ENTRY]] ], [ [[OP_RDX:%.*]], %[[LOOP]] ]
+; CHECK-NEXT: [[P0:%.*]] = getelementptr double, ptr [[P]], i64 [[IV]]
+; CHECK-NEXT: [[TMP0:%.*]] = load <4 x double>, ptr [[P0]], align 8
+; CHECK-NEXT: [[TMP2:%.*]] = call fast double @llvm.vector.reduce.fadd.v4f64(double 0.000000e+00, <4 x double> [[TMP0]])
+; CHECK-NEXT: [[OP_RDX]] = fadd fast dou...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/221597
More information about the llvm-commits
mailing list