[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:20:51 PDT 2023


wangpc updated this revision to Diff 549820.
wangpc added a comment.

Use `getName()`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157839/new/

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()->getName() << ")";
+  OS << "(" << RISCVInstPrinter::getRegisterName(AddrReg.getReg()) << ")";
   return false;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157839.549820.patch
Type: text/x-patch
Size: 1664 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230814/a9894543/attachment.bin>


More information about the llvm-commits mailing list