[llvm] 47aa7b9 - [NFC][SLP] Add a test for fma fusion with the fmul on operand 1 (#216428)

via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 14 17:09:18 PDT 2026


Author: Dmitry Sidorov
Date: 2026-08-15T00:09:14Z
New Revision: 47aa7b93b9ccc8980066abcbdcab6134b1a90105

URL: https://github.com/llvm/llvm-project/commit/47aa7b93b9ccc8980066abcbdcab6134b1a90105
DIFF: https://github.com/llvm/llvm-project/commit/47aa7b93b9ccc8980066abcbdcab6134b1a90105.diff

LOG: [NFC][SLP] Add a test for fma fusion with the fmul on operand 1 (#216428)

canConvertToFMA only looks at operand 0 of the fadd, so the accumulator
shape fadd c, a * b is never recognised, and the fmul it does find is
priced with the target's fusion discount already applied. The threshold
puts the decision right at the cost boundary so the checks record which
way SLP goes today.

Added: 
    llvm/test/Transforms/SLPVectorizer/AMDGPU/elementwise-fma-operand1.ll

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/elementwise-fma-operand1.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/elementwise-fma-operand1.ll
new file mode 100644
index 0000000000000..3bcc9f03d0220
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/elementwise-fma-operand1.ll
@@ -0,0 +1,114 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -slp-threshold=14 < %s | FileCheck %s
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx942 -slp-threshold=14 < %s | FileCheck %s
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx950 -slp-threshold=14 < %s | FileCheck %s
+
+; Elementwise d = c + a * b, where the fmul is operand 1 of the fadd. The
+; threshold puts the decision right at the cost boundary, so how the fmul and
+; fadd are priced against a fused fma is what decides it. These targets halve
+; the cost of a packed fmul, which is what tempts SLP into vectorizing and
+; breaking the scalar fma chain.
+
+define void @axpy4_contract(ptr noalias %d, ptr noalias %a, ptr noalias %b, ptr noalias %c) {
+; CHECK-LABEL: define void @axpy4_contract(
+; CHECK-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = load <4 x float>, ptr [[C]], align 4
+; CHECK-NEXT:    [[TMP1:%.*]] = load <4 x float>, ptr [[A]], align 4
+; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x float>, ptr [[B]], align 4
+; CHECK-NEXT:    [[TMP3:%.*]] = fmul contract <4 x float> [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[TMP4:%.*]] = fadd contract <4 x float> [[TMP0]], [[TMP3]]
+; CHECK-NEXT:    store <4 x float> [[TMP4]], ptr [[D]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %c0 = load float, ptr %c, align 4
+  %a0 = load float, ptr %a, align 4
+  %b0 = load float, ptr %b, align 4
+  %m0 = fmul contract float %a0, %b0
+  %r0 = fadd contract float %c0, %m0
+  store float %r0, ptr %d, align 4
+  %cp1 = getelementptr inbounds float, ptr %c, i64 1
+  %c1 = load float, ptr %cp1, align 4
+  %ap1 = getelementptr inbounds float, ptr %a, i64 1
+  %a1 = load float, ptr %ap1, align 4
+  %bp1 = getelementptr inbounds float, ptr %b, i64 1
+  %b1 = load float, ptr %bp1, align 4
+  %m1 = fmul contract float %a1, %b1
+  %r1 = fadd contract float %c1, %m1
+  %dp1 = getelementptr inbounds float, ptr %d, i64 1
+  store float %r1, ptr %dp1, align 4
+  %cp2 = getelementptr inbounds float, ptr %c, i64 2
+  %c2 = load float, ptr %cp2, align 4
+  %ap2 = getelementptr inbounds float, ptr %a, i64 2
+  %a2 = load float, ptr %ap2, align 4
+  %bp2 = getelementptr inbounds float, ptr %b, i64 2
+  %b2 = load float, ptr %bp2, align 4
+  %m2 = fmul contract float %a2, %b2
+  %r2 = fadd contract float %c2, %m2
+  %dp2 = getelementptr inbounds float, ptr %d, i64 2
+  store float %r2, ptr %dp2, align 4
+  %cp3 = getelementptr inbounds float, ptr %c, i64 3
+  %c3 = load float, ptr %cp3, align 4
+  %ap3 = getelementptr inbounds float, ptr %a, i64 3
+  %a3 = load float, ptr %ap3, align 4
+  %bp3 = getelementptr inbounds float, ptr %b, i64 3
+  %b3 = load float, ptr %bp3, align 4
+  %m3 = fmul contract float %a3, %b3
+  %r3 = fadd contract float %c3, %m3
+  %dp3 = getelementptr inbounds float, ptr %d, i64 3
+  store float %r3, ptr %dp3, align 4
+  ret void
+}
+
+define void @axpy4_reassoc(ptr noalias %d, ptr noalias %a, ptr noalias %b, ptr noalias %c) {
+; CHECK-LABEL: define void @axpy4_reassoc(
+; CHECK-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[TMP0:%.*]] = load <4 x float>, ptr [[C]], align 4
+; CHECK-NEXT:    [[TMP1:%.*]] = load <4 x float>, ptr [[A]], align 4
+; CHECK-NEXT:    [[TMP2:%.*]] = load <4 x float>, ptr [[B]], align 4
+; CHECK-NEXT:    [[TMP3:%.*]] = fmul reassoc contract <4 x float> [[TMP1]], [[TMP2]]
+; CHECK-NEXT:    [[TMP4:%.*]] = fadd reassoc contract <4 x float> [[TMP0]], [[TMP3]]
+; CHECK-NEXT:    store <4 x float> [[TMP4]], ptr [[D]], align 4
+; CHECK-NEXT:    ret void
+;
+entry:
+  %c0 = load float, ptr %c, align 4
+  %a0 = load float, ptr %a, align 4
+  %b0 = load float, ptr %b, align 4
+  %m0 = fmul contract reassoc float %a0, %b0
+  %r0 = fadd contract reassoc float %c0, %m0
+  store float %r0, ptr %d, align 4
+  %cp1 = getelementptr inbounds float, ptr %c, i64 1
+  %c1 = load float, ptr %cp1, align 4
+  %ap1 = getelementptr inbounds float, ptr %a, i64 1
+  %a1 = load float, ptr %ap1, align 4
+  %bp1 = getelementptr inbounds float, ptr %b, i64 1
+  %b1 = load float, ptr %bp1, align 4
+  %m1 = fmul contract reassoc float %a1, %b1
+  %r1 = fadd contract reassoc float %c1, %m1
+  %dp1 = getelementptr inbounds float, ptr %d, i64 1
+  store float %r1, ptr %dp1, align 4
+  %cp2 = getelementptr inbounds float, ptr %c, i64 2
+  %c2 = load float, ptr %cp2, align 4
+  %ap2 = getelementptr inbounds float, ptr %a, i64 2
+  %a2 = load float, ptr %ap2, align 4
+  %bp2 = getelementptr inbounds float, ptr %b, i64 2
+  %b2 = load float, ptr %bp2, align 4
+  %m2 = fmul contract reassoc float %a2, %b2
+  %r2 = fadd contract reassoc float %c2, %m2
+  %dp2 = getelementptr inbounds float, ptr %d, i64 2
+  store float %r2, ptr %dp2, align 4
+  %cp3 = getelementptr inbounds float, ptr %c, i64 3
+  %c3 = load float, ptr %cp3, align 4
+  %ap3 = getelementptr inbounds float, ptr %a, i64 3
+  %a3 = load float, ptr %ap3, align 4
+  %bp3 = getelementptr inbounds float, ptr %b, i64 3
+  %b3 = load float, ptr %bp3, align 4
+  %m3 = fmul contract reassoc float %a3, %b3
+  %r3 = fadd contract reassoc float %c3, %m3
+  %dp3 = getelementptr inbounds float, ptr %d, i64 3
+  store float %r3, ptr %dp3, align 4
+  ret void
+}


        


More information about the llvm-commits mailing list