[PATCH] D44031: [X86] Reject registers that require a REX prefix in inline asm constraints in 32-bit mode

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Mar 5 10:17:43 PST 2018


craig.topper updated this revision to Diff 137037.
craig.topper added a comment.

Add RUN line for gnux32


https://reviews.llvm.org/D44031

Files:
  lib/Target/X86/X86ISelLowering.cpp
  test/CodeGen/X86/asm-reject-rex.ll
  test/CodeGen/X86/asm-reject-xmm16.ll


Index: test/CodeGen/X86/asm-reject-xmm16.ll
===================================================================
--- test/CodeGen/X86/asm-reject-xmm16.ll
+++ test/CodeGen/X86/asm-reject-xmm16.ll
@@ -1,5 +1,5 @@
-; RUN: not llc -o /dev/null %s 2>&1 | FileCheck %s
-target triple = "x86_64--"
+; RUN: not llc -o /dev/null %s -mtriple=x86_64-unknown-unknown 2>&1 | FileCheck %s
+; RUN: not llc -o /dev/null %s -mtriple=i386-unknown-unknown -mattr=avx512vl 2>&1 | FileCheck %s
 
 ; CHECK: error: couldn't allocate output register for constraint '{xmm16}'
 define i64 @blup() {
Index: test/CodeGen/X86/asm-reject-rex.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/asm-reject-rex.ll
@@ -0,0 +1,21 @@
+; RUN: not llc -o /dev/null %s -mtriple=i386-unknown-unknown 2>&1 | FileCheck %s
+; Make sure X32 still works.
+; RUN: llc -o /dev/null %s -mtriple=x86_64-linux-gnux32
+
+; CHECK: error: couldn't allocate output register for constraint '{xmm8}'
+define i64 @blup() {
+  %v = tail call i64 asm "", "={xmm8},0"(i64 0)
+  ret i64 %v
+}
+
+; CHECK: error: couldn't allocate output register for constraint '{r8d}'
+define i32 @foo() {
+  %v = tail call i32 asm "", "={r8d},0"(i32 0)
+  ret i32 %v
+}
+
+; CHECK: error: couldn't allocate output register for constraint '{rax}'
+define i64 @bar() {
+  %v = tail call i64 asm "", "={rax},0"(i64 0)
+  ret i64 %v
+}
Index: lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- lib/Target/X86/X86ISelLowering.cpp
+++ lib/Target/X86/X86ISelLowering.cpp
@@ -39277,6 +39277,16 @@
     return Res;
   }
 
+  // Make sure it isn't a register that requires 64-bit mode.
+  if (!Subtarget.is64Bit() &&
+      (isFRClass(*Res.second) || isGRClass(*Res.second)) &&
+      TRI->getEncodingValue(Res.first) >= 8) {
+    // Register requires REX prefix, but we're in 32-bit mode.
+    Res.first = 0;
+    Res.second = nullptr;
+    return Res;
+  }
+
   // Make sure it isn't a register that requires AVX512.
   if (!Subtarget.hasAVX512() && isFRClass(*Res.second) &&
       TRI->getEncodingValue(Res.first) & 0x10) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44031.137037.patch
Type: text/x-patch
Size: 2152 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180305/cb84485d/attachment.bin>


More information about the llvm-commits mailing list