[llvm] [ARM][FastISel] Fix soft-float f64 register pair order on big endian (PR #227172)
dong jianqiang via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 30 21:59:33 PDT 2026
https://github.com/dongjianqiang2 updated https://github.com/llvm/llvm-project/pull/227172
>From 38184087e6c8af93cb0b41760d3572eb4266c0b4 Mon Sep 17 00:00:00 2001
From: Dong JianQiang <dongjianqiang2 at huawei.com>
Date: Tue, 29 Sep 2026 09:19:32 +0800
Subject: [PATCH 1/2] [ARM][FastISel] Fix soft-float f64 register pair order on
big endian
Under the soft-float ABI an f64 argument or return value is passed in a
core register pair which is ordered like any other 64-bit value in core
registers: on big-endian targets the register holding the most
significant word comes first.
FastISel materialized the pair with VMOVRRD/VMOVDRR in little-endian
order on both endiannesses, disagreeing with the SelectionDAG ISel
paths and miscompiling soft-float f64 argument passing and returns for
armebv7 targets at -O0.
VMOVRRD moves Dn[31:0] to Rt and Dn[63:32] to Rt2, and VMOVDRR reads
them symmetrically, so swap the destination/source pair when the data
layout is big-endian, mirroring the big-endian handling already present
in ARMISelLowering.
Fixes #227171
---
llvm/lib/Target/ARM/ARMFastISel.cpp | 22 ++++++---
.../CodeGen/ARM/fast-isel-call-be-softfp.ll | 45 +++++++++++++++++++
2 files changed, 62 insertions(+), 5 deletions(-)
create mode 100644 llvm/test/CodeGen/ARM/fast-isel-call-be-softfp.ll
diff --git a/llvm/lib/Target/ARM/ARMFastISel.cpp b/llvm/lib/Target/ARM/ARMFastISel.cpp
index 88ee3156ee339..20e08d0df7ec6 100644
--- a/llvm/lib/Target/ARM/ARMFastISel.cpp
+++ b/llvm/lib/Target/ARM/ARMFastISel.cpp
@@ -2057,10 +2057,16 @@ bool ARMFastISel::ProcessCallArgs(SmallVectorImpl<Value*> &Args,
assert(VA.isRegLoc() && NextVA.isRegLoc() &&
"We only handle register args!");
+ // VMOVRRD moves the low word to Rt and the high word to Rt2; on
+ // big-endian targets the high word goes in the first register.
+ Register Lo = VA.getLocReg();
+ Register Hi = NextVA.getLocReg();
+ if (DL.isBigEndian())
+ std::swap(Lo, Hi);
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
- TII.get(ARM::VMOVRRD), VA.getLocReg())
- .addReg(NextVA.getLocReg(), RegState::Define)
- .addReg(Arg));
+ TII.get(ARM::VMOVRRD), Lo)
+ .addReg(Hi, RegState::Define)
+ .addReg(Arg));
RegArgs.push_back(VA.getLocReg());
RegArgs.push_back(NextVA.getLocReg());
} else {
@@ -2107,10 +2113,16 @@ bool ARMFastISel::FinishCall(MVT RetVT, SmallVectorImpl<Register> &UsedRegs,
MVT DestVT = RVLocs[0].getValVT();
const TargetRegisterClass* DstRC = TLI.getRegClassFor(DestVT);
Register ResultReg = createResultReg(DstRC);
+ // VMOVDRR takes the low word from Rt and the high word from Rt2; on
+ // big-endian targets the first register holds the high word.
+ Register Lo = RVLocs[0].getLocReg();
+ Register Hi = RVLocs[1].getLocReg();
+ if (DL.isBigEndian())
+ std::swap(Lo, Hi);
AddOptionalDefs(BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, MIMD,
TII.get(ARM::VMOVDRR), ResultReg)
- .addReg(RVLocs[0].getLocReg())
- .addReg(RVLocs[1].getLocReg()));
+ .addReg(Lo)
+ .addReg(Hi));
UsedRegs.push_back(RVLocs[0].getLocReg());
UsedRegs.push_back(RVLocs[1].getLocReg());
diff --git a/llvm/test/CodeGen/ARM/fast-isel-call-be-softfp.ll b/llvm/test/CodeGen/ARM/fast-isel-call-be-softfp.ll
new file mode 100644
index 0000000000000..b64b133ae150e
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/fast-isel-call-be-softfp.ll
@@ -0,0 +1,45 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc < %s -O0 -verify-machineinstrs -fast-isel-abort=1 -relocation-model=dynamic-no-pic -mtriple=armebv7-linux-gnueabi -mattr=+vfp3 | FileCheck %s
+
+; FastISel must pass soft-float f64 call arguments and results in core
+; register pairs ordered like other 64-bit values: the most significant word
+; in the first register on big-endian targets.
+
+define void @f64_arg() {
+; CHECK-LABEL: f64_arg:
+; CHECK: @ %bb.0: @ %entry
+; CHECK-NEXT: .save {r11, lr}
+; CHECK-NEXT: push {r11, lr}
+; CHECK-NEXT: .setfp r11, sp
+; CHECK-NEXT: mov r11, sp
+; CHECK-NEXT: vldr d16, .LCPI0_0
+; CHECK-NEXT: vmov r1, r0, d16
+; CHECK-NEXT: bl void_callee
+; CHECK-NEXT: pop {r11, pc}
+; CHECK-NEXT: .p2align 3
+; CHECK-NEXT: @ %bb.1:
+; CHECK-NEXT: .LCPI0_0:
+; CHECK-NEXT: .long 1070176665 @ double 0.20000000298023224
+; CHECK-NEXT: .long 2684354560
+entry:
+ call void @void_callee(double 0x3FC99999A0000000)
+ ret void
+}
+
+define void @f64_ret() {
+; CHECK-LABEL: f64_ret:
+; CHECK: @ %bb.0: @ %entry
+; CHECK-NEXT: .save {r11, lr}
+; CHECK-NEXT: push {r11, lr}
+; CHECK-NEXT: .setfp r11, sp
+; CHECK-NEXT: mov r11, sp
+; CHECK-NEXT: bl f64_callee
+; CHECK-NEXT: vmov d16, r1, r0
+; CHECK-NEXT: pop {r11, pc}
+entry:
+ %r = call double @f64_callee()
+ ret void
+}
+
+declare void @void_callee(double)
+declare double @f64_callee()
>From b36f2a1b2819841fc55dac971ea34931d3b58f67 Mon Sep 17 00:00:00 2001
From: Dong JianQiang <dongjianqiang2 at huawei.com>
Date: Thu, 1 Oct 2026 12:59:11 +0800
Subject: [PATCH 2/2] [ARM][FastISel] Test soft-float f64 pairs with both ISel
paths
Address review feedback: run the big-endian soft-float f64 test with
-fast-isel=0 and -fast-isel=1 so both SelectionDAG and FastISel outputs
are checked and can be seen to agree. Make the f64 call result live so
the SelectionDAG path also emits the VMOVDRR pair, and drop the
unnecessary -fast-isel-abort=1.
Co-Authored-By: Claude <noreply at anthropic.com>
---
.../CodeGen/ARM/fast-isel-call-be-softfp.ll | 90 +++++++++++++------
1 file changed, 61 insertions(+), 29 deletions(-)
diff --git a/llvm/test/CodeGen/ARM/fast-isel-call-be-softfp.ll b/llvm/test/CodeGen/ARM/fast-isel-call-be-softfp.ll
index b64b133ae150e..2d929d83a9401 100644
--- a/llvm/test/CodeGen/ARM/fast-isel-call-be-softfp.ll
+++ b/llvm/test/CodeGen/ARM/fast-isel-call-be-softfp.ll
@@ -1,44 +1,76 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
-; RUN: llc < %s -O0 -verify-machineinstrs -fast-isel-abort=1 -relocation-model=dynamic-no-pic -mtriple=armebv7-linux-gnueabi -mattr=+vfp3 | FileCheck %s
+; RUN: llc < %s -O0 -verify-machineinstrs -relocation-model=dynamic-no-pic -mtriple=armebv7-linux-gnueabi -mattr=+vfp3 -fast-isel=1 | FileCheck %s --check-prefix=FAST
+; RUN: llc < %s -O0 -verify-machineinstrs -relocation-model=dynamic-no-pic -mtriple=armebv7-linux-gnueabi -mattr=+vfp3 -fast-isel=0 | FileCheck %s --check-prefix=SDAG
-; FastISel must pass soft-float f64 call arguments and results in core
+; Both ISel paths must pass soft-float f64 call arguments and results in core
; register pairs ordered like other 64-bit values: the most significant word
-; in the first register on big-endian targets.
+; in the first register on big-endian targets. The FAST output additionally
+; sets up a frame pointer for these frameless functions; the pair order is
+; the same in both outputs.
define void @f64_arg() {
-; CHECK-LABEL: f64_arg:
-; CHECK: @ %bb.0: @ %entry
-; CHECK-NEXT: .save {r11, lr}
-; CHECK-NEXT: push {r11, lr}
-; CHECK-NEXT: .setfp r11, sp
-; CHECK-NEXT: mov r11, sp
-; CHECK-NEXT: vldr d16, .LCPI0_0
-; CHECK-NEXT: vmov r1, r0, d16
-; CHECK-NEXT: bl void_callee
-; CHECK-NEXT: pop {r11, pc}
-; CHECK-NEXT: .p2align 3
-; CHECK-NEXT: @ %bb.1:
-; CHECK-NEXT: .LCPI0_0:
-; CHECK-NEXT: .long 1070176665 @ double 0.20000000298023224
-; CHECK-NEXT: .long 2684354560
+; FAST-LABEL: f64_arg:
+; FAST: @ %bb.0: @ %entry
+; FAST-NEXT: .save {r11, lr}
+; FAST-NEXT: push {r11, lr}
+; FAST-NEXT: .setfp r11, sp
+; FAST-NEXT: mov r11, sp
+; FAST-NEXT: vldr d16, .LCPI0_0
+; FAST-NEXT: vmov r1, r0, d16
+; FAST-NEXT: bl void_callee
+; FAST-NEXT: pop {r11, pc}
+; FAST-NEXT: .p2align 3
+; FAST-NEXT: @ %bb.1:
+; FAST-NEXT: .LCPI0_0:
+; FAST-NEXT: .long 1070176665 @ double 0.20000000298023224
+; FAST-NEXT: .long 2684354560
+;
+; SDAG-LABEL: f64_arg:
+; SDAG: @ %bb.0: @ %entry
+; SDAG-NEXT: .save {r11, lr}
+; SDAG-NEXT: push {r11, lr}
+; SDAG-NEXT: vldr d16, .LCPI0_0
+; SDAG-NEXT: vmov r1, r0, d16
+; SDAG-NEXT: bl void_callee
+; SDAG-NEXT: pop {r11, pc}
+; SDAG-NEXT: .p2align 3
+; SDAG-NEXT: @ %bb.1:
+; SDAG-NEXT: .LCPI0_0:
+; SDAG-NEXT: .long 1070176665 @ double 0.20000000298023224
+; SDAG-NEXT: .long 2684354560
entry:
call void @void_callee(double 0x3FC99999A0000000)
ret void
}
-define void @f64_ret() {
-; CHECK-LABEL: f64_ret:
-; CHECK: @ %bb.0: @ %entry
-; CHECK-NEXT: .save {r11, lr}
-; CHECK-NEXT: push {r11, lr}
-; CHECK-NEXT: .setfp r11, sp
-; CHECK-NEXT: mov r11, sp
-; CHECK-NEXT: bl f64_callee
-; CHECK-NEXT: vmov d16, r1, r0
-; CHECK-NEXT: pop {r11, pc}
+define double @f64_ret() {
+; FAST-LABEL: f64_ret:
+; FAST: @ %bb.0: @ %entry
+; FAST-NEXT: .save {r11, lr}
+; FAST-NEXT: push {r11, lr}
+; FAST-NEXT: .setfp r11, sp
+; FAST-NEXT: mov r11, sp
+; FAST-NEXT: bl f64_callee
+; FAST-NEXT: vmov d16, r1, r0
+; FAST-NEXT: vmov.f64 d17, #1.000000e+00
+; FAST-NEXT: vadd.f64 d16, d16, d17
+; FAST-NEXT: vmov r1, r0, d16
+; FAST-NEXT: pop {r11, pc}
+;
+; SDAG-LABEL: f64_ret:
+; SDAG: @ %bb.0: @ %entry
+; SDAG-NEXT: .save {r11, lr}
+; SDAG-NEXT: push {r11, lr}
+; SDAG-NEXT: bl f64_callee
+; SDAG-NEXT: vmov d16, r1, r0
+; SDAG-NEXT: vmov.f64 d17, #1.000000e+00
+; SDAG-NEXT: vadd.f64 d16, d16, d17
+; SDAG-NEXT: vmov r1, r0, d16
+; SDAG-NEXT: pop {r11, pc}
entry:
%r = call double @f64_callee()
- ret void
+ %s = fadd double %r, 1.000000e+00
+ ret double %s
}
declare void @void_callee(double)
More information about the llvm-commits
mailing list