[llvm] AArch64: Drop AllowFPOpFusion from the MachineCombiner FMA conditions (PR #221404)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 4 23:40:52 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-backend-aarch64

Author: Matt Arsenault (arsenm)

<details>
<summary>Changes</summary>

Only use the flags, and add missing tests for a missing flag on only
one of the participating instructions. This is a step toward removing
the AllowFPOpFusion field from TargetOptions.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply@<!-- -->anthropic.com>

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


2 Files Affected:

- (modified) llvm/lib/Target/AArch64/AArch64InstrInfo.cpp (+3-5) 
- (modified) llvm/test/CodeGen/AArch64/arm64-neon-2velem.ll (+56-6) 


``````````diff
diff --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index e69336ea04857..6bfb1f36295e1 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -7569,11 +7569,9 @@ static bool isCombineInstrCandidateFP(const MachineInstr &Inst) {
   case AArch64::FSUBv2f32:
   case AArch64::FSUBv2f64:
   case AArch64::FSUBv4f32:
-    TargetOptions Options = Inst.getParent()->getParent()->getTarget().Options;
-    // We can fuse FADD/FSUB with FMUL, if fusion is either allowed globally by
-    // the target options or if FADD/FSUB has the contract fast-math flag.
-    return Options.AllowFPOpFusion == FPOpFusion::Fast ||
-           Inst.getFlag(MachineInstr::FmContract);
+    // We can fuse FADD/FSUB with FMUL, if FADD/FSUB has the contract fast-math
+    // flag.
+    return Inst.getFlag(MachineInstr::FmContract);
   }
   return false;
 }
diff --git a/llvm/test/CodeGen/AArch64/arm64-neon-2velem.ll b/llvm/test/CodeGen/AArch64/arm64-neon-2velem.ll
index 85d8b7c3e2866..f90333012c21f 100644
--- a/llvm/test/CodeGen/AArch64/arm64-neon-2velem.ll
+++ b/llvm/test/CodeGen/AArch64/arm64-neon-2velem.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc < %s -verify-machineinstrs -mtriple=arm64-none-linux-gnu -fp-contract=fast | FileCheck %s --check-prefixes=CHECK,CHECK-SD
-; RUN: llc < %s -verify-machineinstrs -mtriple=arm64-none-linux-gnu -fp-contract=fast -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-GI
+; RUN: llc < %s -verify-machineinstrs -mtriple=arm64-none-linux-gnu | FileCheck %s --check-prefixes=CHECK,CHECK-SD
+; RUN: llc < %s -verify-machineinstrs -mtriple=arm64-none-linux-gnu -global-isel -global-isel-abort=2 2>&1 | FileCheck %s --check-prefixes=CHECK,CHECK-GI
 
 ; CHECK-GI:       warning: Instruction selection used fallback path for test_vfms_lane_f32
 ; CHECK-GI-NEXT:  warning: Instruction selection used fallback path for test_vfmsq_lane_f32
@@ -4231,8 +4231,8 @@ entry:
   %lane1 = shufflevector <4 x float> %v, <4 x float> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
   %0 = tail call <4 x float> @llvm.fma.v4f32(<4 x float> %lane1, <4 x float> %b, <4 x float> %a)
   %lane2 = shufflevector <4 x float> %v, <4 x float> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
-	%1 = fmul <4 x float> %lane2, %c
-	%s = fsub <4 x float> %0, %1
+	%1 = fmul contract <4 x float> %lane2, %c
+	%s = fsub contract <4 x float> %0, %1
   ret <4 x float> %s
 }
 
@@ -4246,8 +4246,58 @@ entry:
   %lane1 = shufflevector <4 x float> %v, <4 x float> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
   %0 = tail call <4 x float> @llvm.fma.v4f32(<4 x float> %lane1, <4 x float> %b, <4 x float> %a)
   %lane2 = shufflevector <4 x float> %v, <4 x float> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
-	%1 = fmul <4 x float> %lane2, %c
-	%s = fsub <4 x float> %0, %1
+	%1 = fmul contract <4 x float> %lane2, %c
+	%s = fsub contract <4 x float> %0, %1
+  ret <4 x float> %s
+}
+
+; The multiply-subtract is only fused when the fsub carries the contract flag;
+; without it the fmul stays separate.
+define <4 x float> @no_fuse_dup_fsub_no_contract(<4 x float> %a, <4 x float> %b, <4 x float> %c, <4 x float> %v) {
+; CHECK-SD-LABEL: no_fuse_dup_fsub_no_contract:
+; CHECK-SD:       // %bb.0: // %entry
+; CHECK-SD-NEXT:    fmul v2.4s, v2.4s, v3.s[3]
+; CHECK-SD-NEXT:    fmla v0.4s, v1.4s, v3.s[3]
+; CHECK-SD-NEXT:    fsub v0.4s, v0.4s, v2.4s
+; CHECK-SD-NEXT:    ret
+;
+; CHECK-GI-LABEL: no_fuse_dup_fsub_no_contract:
+; CHECK-GI:       // %bb.0: // %entry
+; CHECK-GI-NEXT:    fmla v0.4s, v1.4s, v3.s[3]
+; CHECK-GI-NEXT:    fmul v1.4s, v2.4s, v3.s[3]
+; CHECK-GI-NEXT:    fsub v0.4s, v0.4s, v1.4s
+; CHECK-GI-NEXT:    ret
+entry:
+  %lane1 = shufflevector <4 x float> %v, <4 x float> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
+  %0 = tail call <4 x float> @llvm.fma.v4f32(<4 x float> %lane1, <4 x float> %b, <4 x float> %a)
+  %lane2 = shufflevector <4 x float> %v, <4 x float> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
+  %1 = fmul contract <4 x float> %lane2, %c
+  %s = fsub <4 x float> %0, %1
+  ret <4 x float> %s
+}
+
+; Likewise, the multiply-add is only fused when the fadd carries the contract
+; flag.
+define <4 x float> @no_fuse_dup_fadd_no_contract(<4 x float> %a, <4 x float> %b, <4 x float> %c, <4 x float> %v) {
+; CHECK-SD-LABEL: no_fuse_dup_fadd_no_contract:
+; CHECK-SD:       // %bb.0: // %entry
+; CHECK-SD-NEXT:    fmul v2.4s, v2.4s, v3.s[3]
+; CHECK-SD-NEXT:    fmla v0.4s, v1.4s, v3.s[3]
+; CHECK-SD-NEXT:    fadd v0.4s, v0.4s, v2.4s
+; CHECK-SD-NEXT:    ret
+;
+; CHECK-GI-LABEL: no_fuse_dup_fadd_no_contract:
+; CHECK-GI:       // %bb.0: // %entry
+; CHECK-GI-NEXT:    fmla v0.4s, v1.4s, v3.s[3]
+; CHECK-GI-NEXT:    fmul v1.4s, v2.4s, v3.s[3]
+; CHECK-GI-NEXT:    fadd v0.4s, v0.4s, v1.4s
+; CHECK-GI-NEXT:    ret
+entry:
+  %lane1 = shufflevector <4 x float> %v, <4 x float> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
+  %0 = tail call <4 x float> @llvm.fma.v4f32(<4 x float> %lane1, <4 x float> %b, <4 x float> %a)
+  %lane2 = shufflevector <4 x float> %v, <4 x float> undef, <4 x i32> <i32 3, i32 3, i32 3, i32 3>
+  %1 = fmul contract <4 x float> %lane2, %c
+  %s = fadd <4 x float> %0, %1
   ret <4 x float> %s
 }
 

``````````

</details>


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


More information about the llvm-commits mailing list