[WebAssembly] Support inline asm constraints of type i16 and similar.
authorDan Gohman <dan433584@gmail.com>
Sat, 5 Dec 2015 20:03:44 +0000 (20:03 +0000)
committerDan Gohman <dan433584@gmail.com>
Sat, 5 Dec 2015 20:03:44 +0000 (20:03 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@254861 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/WebAssembly/WebAssemblyISelLowering.cpp
test/CodeGen/WebAssembly/inline-asm.ll

index baefd8d0758d52d924816ecfbb677fb7a8f1a0b3..6e1283b4d3341ae4df0c79f5b509402c2a248430 100644 (file)
@@ -228,10 +228,13 @@ WebAssemblyTargetLowering::getRegForInlineAsmConstraint(
   if (Constraint.size() == 1) {
     switch (Constraint[0]) {
     case 'r':
-      if (VT == MVT::i32)
-        return std::make_pair(0U, &WebAssembly::I32RegClass);
-      if (VT == MVT::i64)
-        return std::make_pair(0U, &WebAssembly::I64RegClass);
+      assert(VT != MVT::iPTR && "Pointer MVT not expected here");
+      if (VT.isInteger() && !VT.isVector()) {
+        if (VT.getSizeInBits() <= 32)
+          return std::make_pair(0U, &WebAssembly::I32RegClass);
+        if (VT.getSizeInBits() <= 64)
+          return std::make_pair(0U, &WebAssembly::I64RegClass);
+      }
       break;
     default:
       break;
index e9d2ebf51f6378c21169a7746e0c06c61aa484a9..646ea779dc8fdc2cbccd89fcca998d11c9b25d88 100644 (file)
@@ -56,6 +56,22 @@ entry:
   ret i64 %0
 }
 
+; CHECK-LABEL: X_i16:
+; CHECK: foo $1{{$}}
+; CHECK: i32.store16 $discard=, 0($0), $1{{$}}
+define void @X_i16(i16 * %t) {
+  call void asm sideeffect "foo $0", "=*X,~{dirflag},~{fpsr},~{flags},~{memory}"(i16* %t)
+  ret void
+}
+
+; CHECK-LABEL: X_ptr:
+; CHECK: foo $1{{$}}
+; CHECK: i32.store $discard=, 0($0), $1
+define void @X_ptr(i16 ** %t) {
+  call void asm sideeffect "foo $0", "=*X,~{dirflag},~{fpsr},~{flags},~{memory}"(i16** %t)
+  ret void
+}
+
 attributes #0 = { nounwind }
 
 !0 = !{i32 47}