[llvm] [ARM] Set combineRepeatedFPDivisors to 3 (PR #194640)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 28 08:25:55 PDT 2026
https://github.com/LumioseSil updated https://github.com/llvm/llvm-project/pull/194640
>From cfe4e8fd3bbeda832573781c07a1e13729347019 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
Revert "Pre-commit test"
This reverts commit 9ba649bf78cf84ffb500ca06d39ce7d881720458.
Pre-commit test (NFC)
---
llvm/test/CodeGen/ARM/fdiv-combine.ll | 38 +++++++++++++++++++++++++++
1 file changed, 38 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..182394df1649a
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/fdiv-combine.ll
@@ -0,0 +1,38 @@
+; 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
+; CHECK-COUNT-3: vmul.f32
+ %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 24eb795766315c34e10c731e57badac7c65772b5 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 182394df1649a..5007dbc73a05b 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
; CHECK-COUNT-3: vmul.f32
%div0 = fdiv arcp float %a, %d
More information about the llvm-commits
mailing list