[llvm-branch-commits] [llvm] [AArch64] Use 64-bit registers for wide "r" inline asm operands (PR #239127)
Bill Wendling via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Nov 11 00:26:42 PST 2026
https://github.com/isanbard updated https://github.com/llvm/llvm-project/pull/239127
>From 01297f9d3490c48a79ecb047c6618ee7bc3f9499 Mon Sep 17 00:00:00 2001
From: Bill Wendling <isanbard at gmail.com>
Date: Wed, 4 Nov 2026 23:31:04 -0800
Subject: [PATCH] [AArch64] Use 64-bit registers for wide "r" inline asm
operands
An integer wider than 64 bits, such as an i128, in an "r" operand was
given a 32-bit register for each 64 bits of it, so half of its bits were
lost. Give it 64-bit registers instead.
Fixes #238926.
Assisted-by: Claude Opus 5.5
---
.../Target/AArch64/AArch64ISelLowering.cpp | 8 +++-
llvm/test/CodeGen/AArch64/build-pair-isel.ll | 7 +---
.../CodeGen/AArch64/inline-asm-wide-gpr.ll | 41 +++++++++++++++++++
3 files changed, 50 insertions(+), 6 deletions(-)
create mode 100644 llvm/test/CodeGen/AArch64/inline-asm-wide-gpr.ll
diff --git a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
index a51e6bb18cdd8e..741cad2f162a09 100644
--- a/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
+++ b/llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
@@ -14484,8 +14484,14 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
return std::make_pair(0U, nullptr);
if (Subtarget->hasLS64() && VT.getSizeInBits() == 512)
return std::make_pair(0U, &AArch64::GPR64x8ClassRegClass);
- if (VT.getFixedSizeInBits() == 64)
+
+ // An integer wider than 64 bits, such as an i128, takes a 64-bit
+ // register for each 64 bits of it. 32-bit registers would hold only half
+ // of it.
+ if (VT.getFixedSizeInBits() == 64 ||
+ (VT.isScalarInteger() && VT.getFixedSizeInBits() > 64))
return std::make_pair(0U, &AArch64::GPR64commonRegClass);
+
return std::make_pair(0U, &AArch64::GPR32commonRegClass);
case 'w': {
if (!Subtarget->hasFPARMv8())
diff --git a/llvm/test/CodeGen/AArch64/build-pair-isel.ll b/llvm/test/CodeGen/AArch64/build-pair-isel.ll
index cd68bde0f8da73..ee5fc8b7df13cf 100644
--- a/llvm/test/CodeGen/AArch64/build-pair-isel.ll
+++ b/llvm/test/CodeGen/AArch64/build-pair-isel.ll
@@ -10,11 +10,8 @@ define void @compare_and_swap128() {
; CHECK-NEXT: //APP
; CHECK-NEXT: nop
; CHECK-NEXT: //NO_APP
-; CHECK-NEXT: // implicit-def: $x9
-; CHECK-NEXT: mov w9, w10
-; CHECK-NEXT: mov w8, w8
-; CHECK-NEXT: // kill: def $x8 killed $w8
-; CHECK-NEXT: orr x8, x8, x9, lsl #32
+; CHECK-NEXT: // implicit-def: $x10
+; CHECK-NEXT: str x9, [x10]
; CHECK-NEXT: // implicit-def: $x9
; CHECK-NEXT: str x8, [x9]
; CHECK-NEXT: ret
diff --git a/llvm/test/CodeGen/AArch64/inline-asm-wide-gpr.ll b/llvm/test/CodeGen/AArch64/inline-asm-wide-gpr.ll
new file mode 100644
index 00000000000000..05144bcdd69714
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/inline-asm-wide-gpr.ll
@@ -0,0 +1,41 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=aarch64-linux-gnu < %s | FileCheck %s
+
+; An integer wider than 64 bits in an "r" operand goes in 64-bit registers,
+; one for each 64 bits of it. 32-bit registers would hold only half of it.
+
+define void @test_i128_input(i128 %x) {
+; CHECK-LABEL: test_i128_input:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: //APP
+; CHECK-NEXT: // x0
+; CHECK-NEXT: //NO_APP
+; CHECK-NEXT: ret
+entry:
+ call void asm sideeffect "// $0", "r"(i128 %x)
+ ret void
+}
+
+define i128 @test_i128_output() {
+; CHECK-LABEL: test_i128_output:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: //APP
+; CHECK-NEXT: // x0
+; CHECK-NEXT: //NO_APP
+; CHECK-NEXT: ret
+entry:
+ %r = call i128 asm sideeffect "// $0", "=r"()
+ ret i128 %r
+}
+
+; The asm doesn't change its operand, so the function returns its argument.
+define i128 @test_i128_tied(i128 %x) {
+; CHECK-LABEL: test_i128_tied:
+; CHECK: // %bb.0: // %entry
+; CHECK-NEXT: //APP
+; CHECK-NEXT: //NO_APP
+; CHECK-NEXT: ret
+entry:
+ %r = call i128 asm sideeffect "", "=&r,0"(i128 %x)
+ ret i128 %r
+}
More information about the llvm-branch-commits
mailing list