[llvm-branch-commits] [llvm] [PowerPC] Use 64-bit registers for wide "r" inline asm operands (PR #239128)
Bill Wendling via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Nov 5 18:54:05 PST 2026
https://github.com/isanbard updated https://github.com/llvm/llvm-project/pull/239128
>From a8ce570df2fd08b1a04cc018a39f43ac4220fb86 Mon Sep 17 00:00:00 2001
From: Bill Wendling <isanbard at gmail.com>
Date: Wed, 4 Nov 2026 23:33:17 -0800
Subject: [PATCH] [PowerPC] Use 64-bit registers for wide "r" inline asm
operands
On PPC64, an integer wider than 64 bits, such as an i128, in an "r" or
"b" 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. AArch64 had the
same problem (#238926).
Assisted-by: Claude Opus 5.5
---
llvm/lib/Target/PowerPC/PPCISelLowering.cpp | 10 +++-
.../CodeGen/PowerPC/inline-asm-wide-gpr.ll | 54 +++++++++++++++++++
2 files changed, 62 insertions(+), 2 deletions(-)
create mode 100644 llvm/test/CodeGen/PowerPC/inline-asm-wide-gpr.ll
diff --git a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
index b904d355915c66..142b7b43bc0b5a 100644
--- a/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -19019,14 +19019,20 @@ PPCTargetLowering::getRegForInlineAsmConstraint(const TargetRegisterInfo *TRI,
StringRef Constraint,
MVT VT) const {
if (Constraint.size() == 1) {
+ // On a 64-bit target, an i64 takes a 64-bit register, and an integer wider
+ // than that, such as an i128, takes one for each 64 bits of it. 32-bit
+ // registers would hold only half of it.
+ bool Use64BitGPRs =
+ Subtarget.isPPC64() && VT.isScalarInteger() && VT.getSizeInBits() >= 64;
+
// GCC RS6000 Constraint Letters
switch (Constraint[0]) {
case 'b': // R1-R31
- if (VT == MVT::i64 && Subtarget.isPPC64())
+ if (Use64BitGPRs)
return std::make_pair(0U, &PPC::G8RC_NOX0RegClass);
return std::make_pair(0U, &PPC::GPRC_NOR0RegClass);
case 'r': // R0-R31
- if (VT == MVT::i64 && Subtarget.isPPC64())
+ if (Use64BitGPRs)
return std::make_pair(0U, &PPC::G8RCRegClass);
return std::make_pair(0U, &PPC::GPRCRegClass);
// 'd' and 'f' constraints are both defined to be "the floating point
diff --git a/llvm/test/CodeGen/PowerPC/inline-asm-wide-gpr.ll b/llvm/test/CodeGen/PowerPC/inline-asm-wide-gpr.ll
new file mode 100644
index 00000000000000..5d54f56d1bc35e
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/inline-asm-wide-gpr.ll
@@ -0,0 +1,54 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -mtriple=powerpc64le-linux-gnu < %s | FileCheck %s
+
+; On a 64-bit target, an integer wider than 64 bits in an "r" or "b" 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: # 3
+; CHECK-NEXT: #NO_APP
+; CHECK-NEXT: blr
+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: # 3
+; CHECK-NEXT: #NO_APP
+; CHECK-NEXT: blr
+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: blr
+entry:
+ %r = call i128 asm sideeffect "", "=&r,0"(i128 %x)
+ ret i128 %r
+}
+
+define void @test_i128_input_b(i128 %x) {
+; CHECK-LABEL: test_i128_input_b:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: #APP
+; CHECK-NEXT: # 3
+; CHECK-NEXT: #NO_APP
+; CHECK-NEXT: blr
+entry:
+ call void asm sideeffect "# $0", "b"(i128 %x)
+ ret void
+}
More information about the llvm-branch-commits
mailing list