[PATCH] D157839: [RISCV] Support global address as inline asm memory operand of `m`
Wang Pengcheng via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 14 01:06:34 PDT 2023
wangpc created this revision.
wangpc added reviewers: mikhail.ramalho, asb, craig.topper, kito-cheng.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
wangpc requested review of this revision.
Herald added subscribers: llvm-commits, eopXD, MaskRay.
Herald added a project: LLVM.
In D146245 <https://reviews.llvm.org/D146245>, we have supported lowering inline asm `m` with offset
to `register+imm`, but we didn't handle the case that the offset
is the low part of global address.
This patch will emit `%lo(g)` when `g` is a global address.
Fixes #64656
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157839
Files:
llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
llvm/test/CodeGen/RISCV/inline-asm.ll
Index: llvm/test/CodeGen/RISCV/inline-asm.ll
===================================================================
--- llvm/test/CodeGen/RISCV/inline-asm.ll
+++ llvm/test/CodeGen/RISCV/inline-asm.ll
@@ -128,6 +128,26 @@
ret i32 %2
}
+define void @constraint_m_with_global() nounwind {
+; RV32I-LABEL: constraint_m_with_global:
+; RV32I: # %bb.0:
+; RV32I-NEXT: lui a0, %hi(gi)
+; RV32I-NEXT: #APP
+; RV32I-NEXT: sw zero, %lo(gi)(a0)
+; RV32I-NEXT: #NO_APP
+; RV32I-NEXT: ret
+;
+; RV64I-LABEL: constraint_m_with_global:
+; RV64I: # %bb.0:
+; RV64I-NEXT: lui a0, %hi(gi)
+; RV64I-NEXT: #APP
+; RV64I-NEXT: sw zero, %lo(gi)(a0)
+; RV64I-NEXT: #NO_APP
+; RV64I-NEXT: ret
+ call void asm "sw zero, $0", "=*m"(ptr elementtype(i32) @gi)
+ ret void
+}
+
define void @constraint_o(ptr %a) nounwind {
; RV32I-LABEL: constraint_o:
; RV32I: # %bb.0:
Index: llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
===================================================================
--- llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
+++ llvm/lib/Target/RISCV/RISCVAsmPrinter.cpp
@@ -237,11 +237,14 @@
// RISCVDAGToDAGISel::SelectInlineAsmMemoryOperand).
if (!AddrReg.isReg())
return true;
- if (!DispImm.isImm())
+ if (!DispImm.isImm() && !DispImm.isGlobal())
return true;
- OS << DispImm.getImm() << "("
- << RISCVInstPrinter::getRegisterName(AddrReg.getReg()) << ")";
+ if (DispImm.isImm())
+ OS << DispImm.getImm();
+ else if (DispImm.isGlobal())
+ OS << "%lo(" << DispImm.getGlobal()->getGlobalIdentifier() << ")";
+ OS << "(" << RISCVInstPrinter::getRegisterName(AddrReg.getReg()) << ")";
return false;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157839.549815.patch
Type: text/x-patch
Size: 1676 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230814/5b00e90e/attachment.bin>
More information about the llvm-commits
mailing list