[llvm] [ARM] Set combineRepeatedFPDivisors to 3 (PR #194640)

via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 28 08:43:28 PDT 2026


https://github.com/LumioseSil updated https://github.com/llvm/llvm-project/pull/194640

>From 6b34efc60a1f2831edc27653466678cb2b39f2d1 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Tue, 28 Apr 2026 09:50:07 -0400
Subject: [PATCH 1/2] Pre-commit test (NFC)

---
 llvm/test/CodeGen/ARM/fdiv-combine.ll | 37 +++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
 create mode 100644 llvm/test/CodeGen/ARM/fdiv-combine.ll

diff --git a/llvm/test/CodeGen/ARM/fdiv-combine.ll b/llvm/test/CodeGen/ARM/fdiv-combine.ll
new file mode 100644
index 0000000000000..a3bc175bf0f80
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/fdiv-combine.ll
@@ -0,0 +1,37 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=armv7-none-eabihf -mattr=+vfp3 < %s | FileCheck %s
+
+; With ARM's combineRepeatedFPDivisors() threshold set to 3:
+; - 2 matching fdiv arcp uses should stay as divisions.
+; - 3 matching fdiv arcp uses should become 1 reciprocal + 3 multiplies.
+
+define void @two_fdiv_float(float %d, float %a, float %b) {
+; CHECK-LABEL: two_fdiv_float:
+; CHECK:       @ %bb.0:
+; CHECK-NEXT:    vdiv.f32 s4, s1, s0
+; CHECK-NEXT:    vdiv.f32 s1, s2, s0
+; CHECK-NEXT:    vmov.f32 s0, s4
+; CHECK-NEXT:    b use2
+  %div0 = fdiv arcp float %a, %d
+  %div1 = fdiv arcp float %b, %d
+  tail call void @use2(float %div0, float %div1)
+  ret void
+}
+
+define void @three_fdiv_float(float %d, float %a, float %b, float %c) {
+; CHECK-LABEL: three_fdiv_float:
+; CHECK:       @ %bb.0:
+; CHECK-NEXT:    vdiv.f32 s4, s1, s0
+; CHECK-NEXT:    vdiv.f32 s1, s2, s0
+; CHECK-NEXT:    vdiv.f32 s2, s3, s0
+; CHECK-NEXT:    vmov.f32 s0, s4
+; CHECK-NEXT:    b use3
+  %div0 = fdiv arcp float %a, %d
+  %div1 = fdiv arcp float %b, %d
+  %div2 = fdiv arcp float %c, %d
+  tail call void @use3(float %div0, float %div1, float %div2)
+  ret void
+}
+
+declare void @use2(float, float)
+declare void @use3(float, float, float)

>From ac18b80a9fe07f6bed23421cb855b356b5d00f2f Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Tue, 28 Apr 2026 10:16:53 -0400
Subject: [PATCH 2/2] [ARM] Set combineRepeatedFPDivisors to 3

vdiv is slower than vmul. It may be a tiny bit bigger in size, but speed it is faster.
---
 llvm/lib/Target/ARM/ARMISelLowering.h | 2 ++
 llvm/test/CodeGen/ARM/fdiv-combine.ll | 9 +++++----
 2 files changed, 7 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/ARM/ARMISelLowering.h b/llvm/lib/Target/ARM/ARMISelLowering.h
index 491beb5434555..612ed663e76d9 100644
--- a/llvm/lib/Target/ARM/ARMISelLowering.h
+++ b/llvm/lib/Target/ARM/ARMISelLowering.h
@@ -225,6 +225,8 @@ class VectorType;
                                       const APInt &DemandedElts,
                                       TargetLoweringOpt &TLO) const override;
 
+    unsigned combineRepeatedFPDivisors() const override { return 3; }
+
     ConstraintType getConstraintType(StringRef Constraint) const override;
 
     /// Examine constraint string and operand type and determine a weight value.
diff --git a/llvm/test/CodeGen/ARM/fdiv-combine.ll b/llvm/test/CodeGen/ARM/fdiv-combine.ll
index a3bc175bf0f80..a7d2f885c51f1 100644
--- a/llvm/test/CodeGen/ARM/fdiv-combine.ll
+++ b/llvm/test/CodeGen/ARM/fdiv-combine.ll
@@ -21,10 +21,11 @@ define void @two_fdiv_float(float %d, float %a, float %b) {
 define void @three_fdiv_float(float %d, float %a, float %b, float %c) {
 ; CHECK-LABEL: three_fdiv_float:
 ; CHECK:       @ %bb.0:
-; CHECK-NEXT:    vdiv.f32 s4, s1, s0
-; CHECK-NEXT:    vdiv.f32 s1, s2, s0
-; CHECK-NEXT:    vdiv.f32 s2, s3, s0
-; CHECK-NEXT:    vmov.f32 s0, s4
+; CHECK-NEXT:    vmov.f32 s4, #1.000000e+00
+; CHECK-NEXT:    vdiv.f32 s4, s4, s0
+; CHECK-NEXT:    vmul.f32 s0, s1, s4
+; CHECK-NEXT:    vmul.f32 s1, s2, s4
+; CHECK-NEXT:    vmul.f32 s2, s3, s4
 ; CHECK-NEXT:    b use3
   %div0 = fdiv arcp float %a, %d
   %div1 = fdiv arcp float %b, %d



More information about the llvm-commits mailing list