[PATCH] D45761: [Sparc] Fix addressing mode when using 64-bit values in inline assembly

Daniel Cederman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 18 04:16:16 PDT 2018


dcederman created this revision.
dcederman added reviewers: jyknight, venkatra.
Herald added subscribers: jrtc27, fedor.sergeev, eraman.

If a 64-bit register is used as an operand in inline assembly together with a memory reference, the memory addressing will be wrong. The addressing will be a single reg, instead of reg+reg or reg+imm. This will generate a bad offset value or an exception in printMemOperand().

For example:

  long long int val = 5;
  long long int mem;
  __asm__ volatile ("std %1, %0":"=m"(mem):"r"(val));

becomes:

  std %i0, [%i2+589833]

The problem is that SelectInlineAsmMemoryOperand() is never called for the memory references if one of the operands is a 64-bit register. By calling SelectInlineAsmMemoryOperands() in tryInlineAsm() the Sparc version of  SelectInlineAsmMemoryOperand() gets called for each memory reference.

A comment above SelectInlineAsmMemoryOperands() says that it should only be called by tblgen. So alternatively one could call SelectCode() on the new Node instead, or copy the content of SelectInlineAsmMemoryOperands() to tryInlineAsm().


Repository:
  rL LLVM

https://reviews.llvm.org/D45761

Files:
  lib/Target/Sparc/SparcISelDAGToDAG.cpp
  test/CodeGen/SPARC/inlineasm.ll


Index: test/CodeGen/SPARC/inlineasm.ll
===================================================================
--- test/CodeGen/SPARC/inlineasm.ll
+++ test/CodeGen/SPARC/inlineasm.ll
@@ -112,3 +112,11 @@
   %2 = tail call double asm sideeffect "faddd  $1, $2, $0;", "=f,f,e"(double %0, double %1) #7
   ret double %2
 }
+
+; CHECK-LABEL: test_addressing_mode_i64:
+; CHECK: std %l0, [%o0]
+define void @test_addressing_mode_i64(i64* %out) {
+entry:
+  call void asm "std %l0, $0", "=*m,r"(i64* nonnull %out, i64 0)
+  ret void
+}
Index: lib/Target/Sparc/SparcISelDAGToDAG.cpp
===================================================================
--- lib/Target/Sparc/SparcISelDAGToDAG.cpp
+++ lib/Target/Sparc/SparcISelDAGToDAG.cpp
@@ -311,6 +311,8 @@
   if (!Changed)
     return false;
 
+  SelectInlineAsmMemoryOperands(AsmNodeOperands, SDLoc(N));
+
   SDValue New = CurDAG->getNode(ISD::INLINEASM, SDLoc(N),
       CurDAG->getVTList(MVT::Other, MVT::Glue), AsmNodeOperands);
   New->setNodeId(-1);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45761.142906.patch
Type: text/x-patch
Size: 996 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180418/b5871638/attachment.bin>


More information about the llvm-commits mailing list