[llvm] [SLP] Check the fmul's own flags in canConvertToFMA (PR #216599)

via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 16 12:52:19 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-vectorizers

Author: Dmitry Sidorov (MrSidims)

<details>
<summary>Changes</summary>

CheckForContractable ran the operand bundle through the fadd's InstructionsState, so every fmul in it failed the main/alt op test and was skipped. The flags stayed set and allowContract was trivially true, which priced a plain fmul feeding a contract fadd as if it would fuse. The backend will not do that. Give the lambda the state to assess against and pass the fmul's own.

Assisted-by: Claude Code Opus 5

---

Patch is 27.15 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/216599.diff


5 Files Affected:

- (modified) llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp (+4-3) 
- (modified) llvm/test/Transforms/SLPVectorizer/AArch64/recalc-copyable-node.ll (+28-33) 
- (modified) llvm/test/Transforms/SLPVectorizer/AArch64/wide-store.ll (+9-7) 
- (added) llvm/test/Transforms/SLPVectorizer/AMDGPU/fma-operand-contract-selection.ll (+265) 
- (modified) llvm/test/Transforms/SLPVectorizer/X86/dot-product.ll (+10-16) 


``````````diff
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 53816d49de722..9d7e3d48f5af9 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14359,7 +14359,8 @@ static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
          "Can only convert to FMA for floating point types");
   assert(S.isAddSubLikeOp() && "Can only convert to FMA for add/sub");
 
-  auto CheckForContractable = [&](ArrayRef<Value *> VL) {
+  auto CheckForContractable = [](ArrayRef<Value *> VL,
+                                 const InstructionsState &S) {
     FastMathFlags FMF;
     FMF.set();
     for (Value *V : VL) {
@@ -14376,7 +14377,7 @@ static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
     }
     return FMF.allowContract();
   };
-  if (!CheckForContractable(VL))
+  if (!CheckForContractable(VL, S))
     return InstructionCost::getInvalid();
   // fmul also should be contractable
   InstructionsCompatibilityAnalysis Analysis(DT, DL, TTI, TLI);
@@ -14388,7 +14389,7 @@ static InstructionCost canConvertToFMA(ArrayRef<Value *> VL,
 
   if (OpS.isAltShuffle() || OpS.getOpcode() != Instruction::FMul)
     return InstructionCost::getInvalid();
-  if (!CheckForContractable(Operands.front()))
+  if (!CheckForContractable(Operands.front(), OpS))
     return InstructionCost::getInvalid();
   // Compare the costs.
   InstructionCost FMulPlusFAddCost = 0;
diff --git a/llvm/test/Transforms/SLPVectorizer/AArch64/recalc-copyable-node.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/recalc-copyable-node.ll
index 0500c00537a32..c88179da10110 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/recalc-copyable-node.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/recalc-copyable-node.ll
@@ -4,43 +4,38 @@
 define { double, double } @test1(ptr %0, double %.unpack753, double %factor828) {
 ; CHECK-LABEL: define { double, double } @test1(
 ; CHECK-SAME: ptr [[TMP0:%.*]], double [[DOTUNPACK753:%.*]], double [[FACTOR828:%.*]]) {
-; CHECK-NEXT:    [[TMP2:%.*]] = load <2 x double>, ptr [[TMP0]], align 8
-; CHECK-NEXT:    [[TMP3:%.*]] = insertelement <2 x double> <double poison, double 1.000000e+00>, double [[DOTUNPACK753]], i64 0
-; CHECK-NEXT:    [[TMP4:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> poison, <2 x i32> zeroinitializer
-; CHECK-NEXT:    [[TMP5:%.*]] = fmul <2 x double> [[TMP3]], [[TMP4]]
-; CHECK-NEXT:    [[TMP6:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> <double 0.000000e+00, double poison>, <2 x i32> <i32 2, i32 0>
-; CHECK-NEXT:    [[TMP7:%.*]] = fmul <2 x double> [[TMP5]], [[TMP6]]
-; CHECK-NEXT:    [[TMP8:%.*]] = fmul <2 x double> [[TMP7]], zeroinitializer
-; CHECK-NEXT:    [[TMP9:%.*]] = shufflevector <2 x double> [[TMP7]], <2 x double> [[TMP5]], <2 x i32> <i32 1, i32 2>
-; CHECK-NEXT:    [[TMP10:%.*]] = insertelement <2 x double> <double poison, double f0xC1502A98AE76C8B4>, double [[FACTOR828]], i64 0
-; CHECK-NEXT:    [[TMP11:%.*]] = fmul <2 x double> [[TMP9]], [[TMP10]]
-; CHECK-NEXT:    [[TMP12:%.*]] = fadd contract <2 x double> [[TMP11]], zeroinitializer
-; CHECK-NEXT:    [[TMP13:%.*]] = fmul <2 x double> [[TMP12]], zeroinitializer
-; CHECK-NEXT:    [[TMP14:%.*]] = fsub <2 x double> zeroinitializer, [[TMP13]]
-; CHECK-NEXT:    [[TMP15:%.*]] = shufflevector <2 x double> [[TMP7]], <2 x double> poison, <2 x i32> zeroinitializer
-; CHECK-NEXT:    [[TMP16:%.*]] = fmul <2 x double> [[TMP14]], [[TMP15]]
-; CHECK-NEXT:    [[TMP17:%.*]] = shufflevector <2 x double> [[TMP16]], <2 x double> poison, <4 x i32> <i32 poison, i32 poison, i32 0, i32 1>
-; CHECK-NEXT:    [[TMP18:%.*]] = shufflevector <2 x double> [[TMP16]], <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP19:%.*]] = shufflevector <4 x double> [[TMP18]], <4 x double> <double 0.000000e+00, double poison, double 0.000000e+00, double poison>, <4 x i32> <i32 4, i32 0, i32 6, i32 1>
-; CHECK-NEXT:    [[TMP20:%.*]] = shufflevector <2 x double> [[TMP8]], <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP21:%.*]] = shufflevector <4 x double> <double poison, double poison, double -0.000000e+00, double poison>, <4 x double> [[TMP20]], <4 x i32> <i32 4, i32 5, i32 2, i32 poison>
-; CHECK-NEXT:    [[TMP22:%.*]] = shufflevector <4 x double> [[TMP21]], <4 x double> poison, <4 x i32> <i32 0, i32 1, i32 2, i32 1>
-; CHECK-NEXT:    [[TMP23:%.*]] = fadd contract <4 x double> [[TMP19]], [[TMP22]]
-; CHECK-NEXT:    [[TMP24:%.*]] = insertelement <4 x double> <double poison, double 1.000000e+00, double poison, double poison>, double [[DOTUNPACK753]], i64 0
-; CHECK-NEXT:    [[TMP25:%.*]] = shufflevector <4 x double> [[TMP24]], <4 x double> poison, <4 x i32> <i32 0, i32 0, i32 1, i32 0>
-; CHECK-NEXT:    [[TMP26:%.*]] = fmul <4 x double> [[TMP23]], [[TMP25]]
-; CHECK-NEXT:    [[TMP27:%.*]] = shufflevector <4 x double> [[TMP24]], <4 x double> <double 0.000000e+00, double poison, double poison, double poison>, <4 x i32> <i32 4, i32 0, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP28:%.*]] = shufflevector <2 x double> [[TMP2]], <2 x double> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
-; CHECK-NEXT:    [[TMP29:%.*]] = shufflevector <4 x double> [[TMP27]], <4 x double> [[TMP28]], <4 x i32> <i32 0, i32 1, i32 4, i32 5>
-; CHECK-NEXT:    [[TMP30:%.*]] = fadd <4 x double> [[TMP29]], [[TMP26]]
-; CHECK-NEXT:    [[TMP31:%.*]] = extractelement <4 x double> [[TMP30]], i64 0
+; CHECK-NEXT:    [[DOTELT752:%.*]] = getelementptr i8, ptr [[TMP0]], i64 8
+; CHECK-NEXT:    [[DOTUNPACK7532:%.*]] = load double, ptr [[DOTELT752]], align 8
+; CHECK-NEXT:    [[DOTUNPACK1:%.*]] = load double, ptr [[TMP0]], align 8
+; CHECK-NEXT:    [[TMP2:%.*]] = fmul double [[DOTUNPACK753]], [[DOTUNPACK1]]
+; CHECK-NEXT:    [[FACTOR8283:%.*]] = fmul double [[TMP2]], 0.000000e+00
+; CHECK-NEXT:    [[TMP3:%.*]] = fmul double [[FACTOR8283]], 0.000000e+00
+; CHECK-NEXT:    [[TMP4:%.*]] = fadd contract double [[TMP3]], 0.000000e+00
+; CHECK-NEXT:    [[TMP5:%.*]] = fmul double [[TMP4]], [[DOTUNPACK753]]
+; CHECK-NEXT:    [[TMP31:%.*]] = fadd contract double [[TMP5]], 0.000000e+00
 ; CHECK-NEXT:    [[TMP32:%.*]] = call { double, double } @__divdc3(double [[TMP31]])
+; CHECK-NEXT:    [[TMP8:%.*]] = fmul double [[DOTUNPACK1]], [[DOTUNPACK1]]
+; CHECK-NEXT:    [[TMP9:%.*]] = fmul double [[TMP8]], [[FACTOR828]]
+; CHECK-NEXT:    [[TMP10:%.*]] = fadd contract double [[TMP9]], 0.000000e+00
+; CHECK-NEXT:    [[TMP11:%.*]] = fmul double [[TMP10]], 0.000000e+00
 ; CHECK-NEXT:    call void @llvm.stackrestore.p0(ptr null)
-; CHECK-NEXT:    [[TMP33:%.*]] = extractelement <4 x double> [[TMP30]], i64 1
+; CHECK-NEXT:    [[TMP12:%.*]] = fsub double 0.000000e+00, [[TMP11]]
+; CHECK-NEXT:    [[TMP13:%.*]] = fmul double [[TMP12]], [[FACTOR8283]]
+; CHECK-NEXT:    [[TMP14:%.*]] = fmul double [[TMP8]], 0.000000e+00
+; CHECK-NEXT:    [[TMP15:%.*]] = fadd contract double [[TMP13]], [[TMP14]]
+; CHECK-NEXT:    [[TMP16:%.*]] = fmul double [[TMP15]], [[DOTUNPACK753]]
+; CHECK-NEXT:    [[TMP33:%.*]] = fadd double [[DOTUNPACK753]], [[TMP16]]
 ; CHECK-NEXT:    [[TMP34:%.*]] = call { double, double } @__divdc3(double [[TMP33]])
-; CHECK-NEXT:    [[TMP35:%.*]] = extractelement <4 x double> [[TMP30]], i64 2
+; CHECK-NEXT:    [[TMP35:%.*]] = fadd double [[DOTUNPACK1]], 0.000000e+00
 ; CHECK-NEXT:    [[TMP36:%.*]] = call { double, double } @__divdc3(double [[TMP35]])
-; CHECK-NEXT:    [[TMP37:%.*]] = extractelement <4 x double> [[TMP30]], i64 3
+; CHECK-NEXT:    [[TMP21:%.*]] = fmul double [[TMP2]], f0xC1502A98AE76C8B4
+; CHECK-NEXT:    [[TMP22:%.*]] = fadd contract double [[TMP21]], 0.000000e+00
+; CHECK-NEXT:    [[TMP23:%.*]] = fmul double [[TMP22]], 0.000000e+00
+; CHECK-NEXT:    [[TMP24:%.*]] = fsub double 0.000000e+00, [[TMP23]]
+; CHECK-NEXT:    [[TMP25:%.*]] = fmul double [[TMP24]], [[FACTOR8283]]
+; CHECK-NEXT:    [[TMP26:%.*]] = fadd contract double [[TMP25]], [[TMP14]]
+; CHECK-NEXT:    [[TMP27:%.*]] = fmul double [[TMP26]], [[DOTUNPACK753]]
+; CHECK-NEXT:    [[TMP37:%.*]] = fadd double [[DOTUNPACK7532]], [[TMP27]]
 ; CHECK-NEXT:    [[TMP38:%.*]] = call { double, double } @__divdc3(double [[TMP37]])
 ; CHECK-NEXT:    ret { double, double } [[TMP38]]
 ;
diff --git a/llvm/test/Transforms/SLPVectorizer/AArch64/wide-store.ll b/llvm/test/Transforms/SLPVectorizer/AArch64/wide-store.ll
index 51c2040a86d64..37fc33318430b 100644
--- a/llvm/test/Transforms/SLPVectorizer/AArch64/wide-store.ll
+++ b/llvm/test/Transforms/SLPVectorizer/AArch64/wide-store.ll
@@ -5,20 +5,22 @@ define void @test(ptr %p, float %conv, i64 %n) {
 ; CHECK-LABEL: define void @test(
 ; CHECK-SAME: ptr [[P:%.*]], float [[CONV:%.*]], i64 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
 ; CHECK-NEXT:  [[ENTRY:.*]]:
+; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <2 x float> poison, float [[CONV]], i64 0
+; CHECK-NEXT:    [[TMP1:%.*]] = shufflevector <2 x float> [[TMP0]], <2 x float> poison, <2 x i32> zeroinitializer
 ; CHECK-NEXT:    br label %[[FOR_BODY:.*]]
 ; CHECK:       [[FOR_COND_CLEANUP:.*]]:
 ; CHECK-NEXT:    ret void
 ; CHECK:       [[FOR_BODY]]:
 ; CHECK-NEXT:    [[IV:%.*]] = phi i64 [ 0, %[[ENTRY]] ], [ [[IV_NEXT:%.*]], %[[FOR_BODY]] ]
 ; CHECK-NEXT:    [[OUT:%.*]] = phi ptr [ [[P]], %[[ENTRY]] ], [ [[OUT_NEXT:%.*]], %[[FOR_BODY]] ]
-; CHECK-NEXT:    [[M2:%.*]] = fmul float [[CONV]], 0.000000e+00
-; CHECK-NEXT:    [[M3:%.*]] = fmul float [[CONV]], 0.000000e+00
 ; CHECK-NEXT:    [[S0:%.*]] = fsub float 0.000000e+00, [[CONV]]
-; CHECK-NEXT:    [[TMP0:%.*]] = insertelement <4 x float> <float poison, float poison, float poison, float -0.000000e+00>, float [[S0]], i64 0
-; CHECK-NEXT:    [[TMP1:%.*]] = insertelement <4 x float> [[TMP0]], float [[M2]], i64 1
-; CHECK-NEXT:    [[TMP2:%.*]] = insertelement <4 x float> [[TMP1]], float [[M3]], i64 2
-; CHECK-NEXT:    [[TMP3:%.*]] = fadd contract <4 x float> <float -0.000000e+00, float 0.000000e+00, float 0.000000e+00, float 0.000000e+00>, [[TMP2]]
-; CHECK-NEXT:    store <4 x float> [[TMP3]], ptr [[OUT]], align 4
+; CHECK-NEXT:    store float [[S0]], ptr [[OUT]], align 4
+; CHECK-NEXT:    [[TMP2:%.*]] = fmul <2 x float> [[TMP1]], zeroinitializer
+; CHECK-NEXT:    [[O1:%.*]] = getelementptr inbounds i8, ptr [[OUT]], i64 4
+; CHECK-NEXT:    [[TMP3:%.*]] = fadd contract <2 x float> [[TMP2]], zeroinitializer
+; CHECK-NEXT:    store <2 x float> [[TMP3]], ptr [[O1]], align 4
+; CHECK-NEXT:    [[O3:%.*]] = getelementptr inbounds i8, ptr [[OUT]], i64 12
+; CHECK-NEXT:    store float 0.000000e+00, ptr [[O3]], align 4
 ; CHECK-NEXT:    [[OUT_NEXT]] = getelementptr inbounds i8, ptr [[OUT]], i64 16
 ; CHECK-NEXT:    [[IV_NEXT]] = add i64 [[IV]], 1
 ; CHECK-NEXT:    [[EC:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
diff --git a/llvm/test/Transforms/SLPVectorizer/AMDGPU/fma-operand-contract-selection.ll b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fma-operand-contract-selection.ll
new file mode 100644
index 0000000000000..9723bdd6bb369
--- /dev/null
+++ b/llvm/test/Transforms/SLPVectorizer/AMDGPU/fma-operand-contract-selection.ll
@@ -0,0 +1,265 @@
+; 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 < %s | FileCheck %s
+; RUN: opt -passes=slp-vectorizer -S -mtriple=amdgcn-amd-amdhsa -mcpu=gfx90a -slp-threshold=15 < %s | FileCheck %s --check-prefix=THR15
+
+; The fma check has to read the multiply's own fast math flags. Reading the
+; add's instead makes every multiply look contractable, so a fusion that the
+; backend will not perform gets paid for. mixed_contract_mul carries contract
+; on one lane only and moves at the default threshold.
+
+
+define void @nocontract_mul(ptr noalias %d, ptr noalias %a, ptr noalias %b, ptr noalias %c) {
+; CHECK-LABEL: define void @nocontract_mul(
+; CHECK-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0:[0-9]+]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[AP0:%.*]] = getelementptr inbounds float, ptr [[A]], i64 0
+; CHECK-NEXT:    [[BP0:%.*]] = getelementptr inbounds float, ptr [[B]], i64 0
+; CHECK-NEXT:    [[CP0:%.*]] = getelementptr inbounds float, ptr [[C]], i64 0
+; CHECK-NEXT:    [[DP0:%.*]] = getelementptr inbounds float, ptr [[D]], i64 0
+; CHECK-NEXT:    [[TMP0:%.*]] = load <2 x float>, ptr [[AP0]], align 4
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[BP0]], align 4
+; CHECK-NEXT:    [[TMP2:%.*]] = load <2 x float>, ptr [[CP0]], align 4
+; CHECK-NEXT:    [[TMP3:%.*]] = fmul <2 x float> [[TMP0]], [[TMP1]]
+; CHECK-NEXT:    [[TMP4:%.*]] = fadd contract <2 x float> [[TMP3]], [[TMP2]]
+; CHECK-NEXT:    store <2 x float> [[TMP4]], ptr [[DP0]], align 4
+; CHECK-NEXT:    [[AP2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
+; CHECK-NEXT:    [[BP2:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
+; CHECK-NEXT:    [[CP2:%.*]] = getelementptr inbounds float, ptr [[C]], i64 2
+; CHECK-NEXT:    [[DP2:%.*]] = getelementptr inbounds float, ptr [[D]], i64 2
+; CHECK-NEXT:    [[TMP5:%.*]] = load <2 x float>, ptr [[AP2]], align 4
+; CHECK-NEXT:    [[TMP6:%.*]] = load <2 x float>, ptr [[BP2]], align 4
+; CHECK-NEXT:    [[TMP7:%.*]] = load <2 x float>, ptr [[CP2]], align 4
+; CHECK-NEXT:    [[TMP8:%.*]] = fmul <2 x float> [[TMP5]], [[TMP6]]
+; CHECK-NEXT:    [[TMP9:%.*]] = fadd contract <2 x float> [[TMP8]], [[TMP7]]
+; CHECK-NEXT:    store <2 x float> [[TMP9]], ptr [[DP2]], align 4
+; CHECK-NEXT:    ret void
+;
+; THR15-LABEL: define void @nocontract_mul(
+; THR15-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0:[0-9]+]] {
+; THR15-NEXT:  [[ENTRY:.*:]]
+; THR15-NEXT:    [[AP0:%.*]] = getelementptr inbounds float, ptr [[A]], i64 0
+; THR15-NEXT:    [[BP0:%.*]] = getelementptr inbounds float, ptr [[B]], i64 0
+; THR15-NEXT:    [[CP0:%.*]] = getelementptr inbounds float, ptr [[C]], i64 0
+; THR15-NEXT:    [[DP0:%.*]] = getelementptr inbounds float, ptr [[D]], i64 0
+; THR15-NEXT:    [[TMP0:%.*]] = load <4 x float>, ptr [[AP0]], align 4
+; THR15-NEXT:    [[TMP1:%.*]] = load <4 x float>, ptr [[BP0]], align 4
+; THR15-NEXT:    [[TMP2:%.*]] = load <4 x float>, ptr [[CP0]], align 4
+; THR15-NEXT:    [[TMP3:%.*]] = fmul <4 x float> [[TMP0]], [[TMP1]]
+; THR15-NEXT:    [[TMP4:%.*]] = fadd contract <4 x float> [[TMP3]], [[TMP2]]
+; THR15-NEXT:    store <4 x float> [[TMP4]], ptr [[DP0]], align 4
+; THR15-NEXT:    ret void
+;
+entry:
+  %ap0 = getelementptr inbounds float, ptr %a, i64 0
+  %bp0 = getelementptr inbounds float, ptr %b, i64 0
+  %cp0 = getelementptr inbounds float, ptr %c, i64 0
+  %dp0 = getelementptr inbounds float, ptr %d, i64 0
+  %a0 = load float, ptr %ap0
+  %b0 = load float, ptr %bp0
+  %c0 = load float, ptr %cp0
+  %m0 = fmul float %a0, %b0
+  %r0 = fadd contract float %m0, %c0
+  store float %r0, ptr %dp0
+  %ap1 = getelementptr inbounds float, ptr %a, i64 1
+  %bp1 = getelementptr inbounds float, ptr %b, i64 1
+  %cp1 = getelementptr inbounds float, ptr %c, i64 1
+  %dp1 = getelementptr inbounds float, ptr %d, i64 1
+  %a1 = load float, ptr %ap1
+  %b1 = load float, ptr %bp1
+  %c1 = load float, ptr %cp1
+  %m1 = fmul float %a1, %b1
+  %r1 = fadd contract float %m1, %c1
+  store float %r1, ptr %dp1
+  %ap2 = getelementptr inbounds float, ptr %a, i64 2
+  %bp2 = getelementptr inbounds float, ptr %b, i64 2
+  %cp2 = getelementptr inbounds float, ptr %c, i64 2
+  %dp2 = getelementptr inbounds float, ptr %d, i64 2
+  %a2 = load float, ptr %ap2
+  %b2 = load float, ptr %bp2
+  %c2 = load float, ptr %cp2
+  %m2 = fmul float %a2, %b2
+  %r2 = fadd contract float %m2, %c2
+  store float %r2, ptr %dp2
+  %ap3 = getelementptr inbounds float, ptr %a, i64 3
+  %bp3 = getelementptr inbounds float, ptr %b, i64 3
+  %cp3 = getelementptr inbounds float, ptr %c, i64 3
+  %dp3 = getelementptr inbounds float, ptr %d, i64 3
+  %a3 = load float, ptr %ap3
+  %b3 = load float, ptr %bp3
+  %c3 = load float, ptr %cp3
+  %m3 = fmul float %a3, %b3
+  %r3 = fadd contract float %m3, %c3
+  store float %r3, ptr %dp3
+  ret void
+}
+
+define void @contract_mul(ptr noalias %d, ptr noalias %a, ptr noalias %b, ptr noalias %c) {
+; CHECK-LABEL: define void @contract_mul(
+; CHECK-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0]] {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:    [[AP0:%.*]] = getelementptr inbounds float, ptr [[A]], i64 0
+; CHECK-NEXT:    [[BP0:%.*]] = getelementptr inbounds float, ptr [[B]], i64 0
+; CHECK-NEXT:    [[CP0:%.*]] = getelementptr inbounds float, ptr [[C]], i64 0
+; CHECK-NEXT:    [[DP0:%.*]] = getelementptr inbounds float, ptr [[D]], i64 0
+; CHECK-NEXT:    [[TMP0:%.*]] = load <2 x float>, ptr [[AP0]], align 4
+; CHECK-NEXT:    [[TMP1:%.*]] = load <2 x float>, ptr [[BP0]], align 4
+; CHECK-NEXT:    [[TMP2:%.*]] = load <2 x float>, ptr [[CP0]], align 4
+; CHECK-NEXT:    [[TMP3:%.*]] = fmul contract <2 x float> [[TMP0]], [[TMP1]]
+; CHECK-NEXT:    [[TMP4:%.*]] = fadd contract <2 x float> [[TMP3]], [[TMP2]]
+; CHECK-NEXT:    store <2 x float> [[TMP4]], ptr [[DP0]], align 4
+; CHECK-NEXT:    [[AP2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 2
+; CHECK-NEXT:    [[BP2:%.*]] = getelementptr inbounds float, ptr [[B]], i64 2
+; CHECK-NEXT:    [[CP2:%.*]] = getelementptr inbounds float, ptr [[C]], i64 2
+; CHECK-NEXT:    [[DP2:%.*]] = getelementptr inbounds float, ptr [[D]], i64 2
+; CHECK-NEXT:    [[TMP5:%.*]] = load <2 x float>, ptr [[AP2]], align 4
+; CHECK-NEXT:    [[TMP6:%.*]] = load <2 x float>, ptr [[BP2]], align 4
+; CHECK-NEXT:    [[TMP7:%.*]] = load <2 x float>, ptr [[CP2]], align 4
+; CHECK-NEXT:    [[TMP8:%.*]] = fmul contract <2 x float> [[TMP5]], [[TMP6]]
+; CHECK-NEXT:    [[TMP9:%.*]] = fadd contract <2 x float> [[TMP8]], [[TMP7]]
+; CHECK-NEXT:    store <2 x float> [[TMP9]], ptr [[DP2]], align 4
+; CHECK-NEXT:    ret void
+;
+; THR15-LABEL: define void @contract_mul(
+; THR15-SAME: ptr noalias [[D:%.*]], ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], ptr noalias [[C:%.*]]) #[[ATTR0]] {
+; THR15-NEXT:  [[ENTRY:.*:]]
+; THR15-NEXT:    [[AP0:%.*]] = getelementptr inbounds float, ptr [[A]], i64 0
+; THR15-NEXT:    [[BP0:%.*]] = getelementptr inbounds float, ptr [[B]], i64 0
+; THR15-NEXT:    [[CP0:%.*]] = getelementptr inbounds float, ptr [[C]], i64 0
+; THR15-NEXT:    [[DP0:%.*]] = getelementptr inbounds float, ptr [[D]], i64 0
+; THR15-NEXT:    [[TMP0:%.*]] = load <4 x float>, ptr [[AP0]], align 4
+; THR15-NEXT:    [[TMP1:%.*]] = load <4 x float>, ptr [[BP0]], align 4
+; THR15-NEXT:    [[TMP2:%.*]] = load <4 x float>, ptr [[CP0]], align 4
+; THR15-NEXT:    [[TMP3:%.*]] = fmul contract <4 x float> [[TMP0]], [[TMP1]]
+; THR15-NEXT:    [[TMP4:%.*]] = fadd contract <4 x float> [[TMP3]], [[TMP2]]
+; THR15-NEXT:    store <4 x float> [[TMP4]], ptr [[DP0]], align 4
+; THR15-NEXT:    ret void
+;
+entry:
+  %ap0 = getelementptr inbounds float, ptr %a, i64 0
+  %bp0 = getelementptr inbounds float, ptr %b, i64 0
+  %cp0 = getelementptr inbounds float, ptr %c, i64 0
+  %dp0 = getelementptr inbounds float, ptr %d, i64 0
+  %a0 = load float, ptr %ap0
+  %b0 = load float, ptr %bp0
+  %c0 = load float, ptr %cp0
+  %m0 = fmul contract float %a0, %b0
+  %r0 = fadd contract float %m0, %c0
+  store float %r0, ptr %dp0
+  %ap1 = getelementptr inbounds float, ptr %a, i64 1
+  %bp1 = getelementptr inbounds float, ptr %b, i64 1
+  %cp1 = getelementptr inbounds float, ptr %c, i64 1
+  %dp1 = getelementptr inbounds float, ptr %d, i64 1
+  %a1 = load float, ptr %ap1
+  %b1 = load float, ptr %bp1
+  %c1 = load float, ptr %cp1
+  %m1 = fmul contract float %a1, %b1
+  %r1 = fadd contract float %m1, %c1
+  store float %r1, ptr %dp1
+  %ap2 = getelementptr inbounds float, ptr %a, i64 2
+  %bp2 = getelementptr inbounds float, ptr %b, i64 2
+  %cp2 = getelementptr inbounds float, ptr %c, i64 2
+  %dp2 = getelementptr inbounds float, ptr %d, i64 2
+  %a2 = load float, ptr %ap2
+  %b2 = load float, ptr %bp2
+  %c2 = load float, ptr %cp2
+  %m2 = fmul contract float %a2, %b2
+  %r2 = fadd contract float %m2, %c2
+  store float %r2, ptr %dp2
+  %ap3 = getelementptr inbounds float, ptr %a, i64 3
+  %bp3 = getelementptr inbounds float, ptr %b, i64 3
+  %cp3 = getelementptr inbounds float, ptr %c, i64 3
+  %dp3 = getelementptr inbounds float, ptr %d, i64 3
+  %a3 = load float, ptr %ap...
[truncated]

``````````

</details>


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


More information about the llvm-commits mailing list