[PATCH] D51991: [WebAssembly] Make tied inline asm operands work again

Heejin Ahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 12 09:02:10 PDT 2018


aheejin created this revision.
aheejin added a reviewer: sunfish.
Herald added subscribers: llvm-commits, eraman, jgravelle-google, sbc100, dschuff.

https://reviews.llvm.org/rL341389 broke code with tied register operands in inline assembly. For
example, `asm("" : "=r"(var) : "0"(var));`
The code above specifies the input operand to be in the same register
with the output operand, tying the two register. This patch makes this
kind of code work again.


Repository:
  rL LLVM

https://reviews.llvm.org/D51991

Files:
  lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
  test/CodeGen/WebAssembly/inline-asm.ll


Index: test/CodeGen/WebAssembly/inline-asm.ll
===================================================================
--- test/CodeGen/WebAssembly/inline-asm.ll
+++ test/CodeGen/WebAssembly/inline-asm.ll
@@ -97,6 +97,15 @@
   ret i32 %t0
 }
 
+; CHECK-LABEL: tied_operands
+; CHECK: get_local  $push0=, 0
+; CHECK: return    $pop0
+define i32 @tied_operands(i32 %var) {
+entry:
+  %ret = call i32 asm "", "=r,0"(i32 %var)
+  ret i32 %ret
+}
+
 attributes #0 = { nounwind }
 
 !0 = !{i32 47}
Index: lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
===================================================================
--- lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
+++ lib/Target/WebAssembly/WebAssemblyExplicitLocals.cpp
@@ -316,6 +316,7 @@
         if (MO.isDef()) {
           assert(MI.getOpcode() == TargetOpcode::INLINEASM);
           unsigned LocalId = getLocalId(Reg2Local, CurLocal, OldReg);
+          MI.untieRegOperand(MI.getOperandNo(&MO));
           MO.ChangeToImmediate(LocalId);
           continue;
         }
@@ -331,6 +332,7 @@
         // indices as immediates.
         if (MI.getOpcode() == TargetOpcode::INLINEASM) {
           unsigned LocalId = getLocalId(Reg2Local, CurLocal, OldReg);
+          MI.untieRegOperand(MI.getOperandNo(&MO));
           MO.ChangeToImmediate(LocalId);
           continue;
         }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51991.165098.patch
Type: text/x-patch
Size: 1347 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180912/05c4443a/attachment.bin>


More information about the llvm-commits mailing list