[PATCH] D31902: Use correct registers for "A" inline asm constraint

Dimitry Andric via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 10 12:13:50 PDT 2017


dim updated this revision to Diff 94715.
dim added a comment.

Remove extraneous space at the end of `llvm_unreachable`.


https://reviews.llvm.org/D31902

Files:
  lib/Target/X86/X86ISelLowering.cpp
  lib/Target/X86/X86RegisterInfo.td
  test/CodeGen/X86/inline-asm-A-constraint.ll


Index: test/CodeGen/X86/inline-asm-A-constraint.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/inline-asm-A-constraint.ll
@@ -0,0 +1,12 @@
+; RUN: llc < %s -march=x86-64 -no-integrated-as
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64"
+
+ at x = common global i128 0, align 16
+
+define void @foo() #0 {
+entry:
+  %0 = call i128 asm "", "=A,~{dirflag},~{fpsr},~{flags}"()
+  store i128 %0, i128* @x, align 16
+  ret void
+}
Index: lib/Target/X86/X86RegisterInfo.td
===================================================================
--- lib/Target/X86/X86RegisterInfo.td
+++ lib/Target/X86/X86RegisterInfo.td
@@ -437,8 +437,10 @@
 def LOW32_ADDR_ACCESS_RBP : RegisterClass<"X86", [i32], 32,
                                           (add LOW32_ADDR_ACCESS, RBP)>;
 
-// A class to support the 'A' assembler constraint: EAX then EDX.
+// A class to support the 'A' assembler constraint: [ER]AX then [ER]DX.
+def GR16_AD : RegisterClass<"X86", [i16], 16, (add AX, DX)>;
 def GR32_AD : RegisterClass<"X86", [i32], 32, (add EAX, EDX)>;
+def GR64_AD : RegisterClass<"X86", [i64], 64, (add RAX, RDX)>;
 
 // Scalar SSE2 floating point registers.
 def FR32 : RegisterClass<"X86", [f32], 32, (sequence "XMM%u", 0, 15)>;
Index: lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- lib/Target/X86/X86ISelLowering.cpp
+++ lib/Target/X86/X86ISelLowering.cpp
@@ -35915,10 +35915,20 @@
       return Res;
     }
 
-    // 'A' means EAX + EDX.
+    // 'A' means [ER]AX + [ER]DX.
     if (Constraint == "A") {
-      Res.first = X86::EAX;
-      Res.second = &X86::GR32_ADRegClass;
+      if (Subtarget.is64Bit()) {
+        Res.first = X86::RAX;
+        Res.second = &X86::GR64_ADRegClass;
+      } else if (Subtarget.is32Bit()) {
+        Res.first = X86::EAX;
+        Res.second = &X86::GR32_ADRegClass;
+      } else if (Subtarget.is16Bit()) {
+        Res.first = X86::AX;
+        Res.second = &X86::GR16_ADRegClass;
+      } else {
+        llvm_unreachable("Expecting 64, 32 or 16 bit subtarget");
+      }
       return Res;
     }
     return Res;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31902.94715.patch
Type: text/x-patch
Size: 2196 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170410/41d330a4/attachment.bin>


More information about the llvm-commits mailing list