[llvm] Allow FP reg conversion when copying Sx to Dx (PR #147559)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 8 09:18:22 PDT 2025


https://github.com/eleviant created https://github.com/llvm/llvm-project/pull/147559

This allows copying float value to Dx reg using inline asm, e.g:
```
float a;
void b() {
  register float d1 asm("d1") =
      a;
  asm("" ::"r"(d1));
}
```

>From 23bdf661a94a52a28ff6dcbc20aa193e25fd2a23 Mon Sep 17 00:00:00 2001
From: Evgeny Leviant <eleviant at accesssoftek.com>
Date: Tue, 8 Jul 2025 18:16:12 +0200
Subject: [PATCH] Allow FP reg conversion when copying Sx to Dx

This allows copying float value to Dx reg using inline asm, e.g:
```
float a;
void b() {
  register float d1 asm("d1") =
      a;
  asm("" ::"r"(d1));
}
```
---
 llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp |  3 +++
 llvm/test/CodeGen/ARM/copy-reg-vcvt.ll   | 17 +++++++++++++++++
 2 files changed, 20 insertions(+)
 create mode 100644 llvm/test/CodeGen/ARM/copy-reg-vcvt.ll

diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
index 50217c3a047df..751f06c4eadf9 100644
--- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
+++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp
@@ -743,6 +743,9 @@ void ARMBaseInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
     Opc = ARM::VMOVSR;
   else if (ARM::DPRRegClass.contains(DestReg, SrcReg) && Subtarget.hasFP64())
     Opc = ARM::VMOVD;
+  else if (ARM::DPRRegClass.contains(DestReg) &&
+           ARM::SPRRegClass.contains(SrcReg) && Subtarget.hasFP64())
+    Opc = ARM::VCVTDS;
   else if (ARM::QPRRegClass.contains(DestReg, SrcReg))
     Opc = Subtarget.hasNEON() ? ARM::VORRq : ARM::MQPRCopy;
 
diff --git a/llvm/test/CodeGen/ARM/copy-reg-vcvt.ll b/llvm/test/CodeGen/ARM/copy-reg-vcvt.ll
new file mode 100644
index 0000000000000..fa93c3b1aae8c
--- /dev/null
+++ b/llvm/test/CodeGen/ARM/copy-reg-vcvt.ll
@@ -0,0 +1,17 @@
+; RUN: llc -filetype=asm -O3  %s -o - | FileCheck %s
+; CHECK:      vldr s0, [r0]
+; CHECK-NEXT: vcvt.f64.f32 d1, s0
+
+target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64"
+target triple = "armv8a-unknown-linux-gnueabihf"
+
+ at a = local_unnamed_addr global float 0.000000e+00, align 4
+
+; Function Attrs: mustprogress noimplicitfloat nounwind
+define void @_Z1bv() local_unnamed_addr {
+entry:
+  %0 = load float, ptr @a, align 4
+  tail call void asm sideeffect "", "{d1}"(float %0)
+  ret void
+}
+



More information about the llvm-commits mailing list