[PATCH] D113894: [x86] Make assembler variant selection work when outputting intel-style asm

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 15 07:10:42 PST 2021


thakis created this revision.
thakis added reviewers: rnk, hans.
Herald added subscribers: pengfei, hiraditya.
thakis requested review of this revision.
Herald added a project: LLVM.

`asm` always has AT&T-style input (`asm inteldialect` has Intel-style asm
input), so EmitGCCInlineAsmStr() always has to pick variant 0 since it
cares about the input asm string, not the output asm string.

Without this, the included test case errors out with

  error: unknown use of instruction mnemonic without a size suffix
           mov rax, rbx

since it picks the intel branch and then tries to interpret it as AT&T
when selecting intel-style output with `-x86-asm-syntax=intel`.


https://reviews.llvm.org/D113894

Files:
  llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
  llvm/test/CodeGen/X86/asm-dialect.ll


Index: llvm/test/CodeGen/X86/asm-dialect.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/asm-dialect.ll
@@ -0,0 +1,24 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu %s -o - \
+; RUN:     | FileCheck --check-prefix=OUTPUT_ATT %s
+; RUN: llc -mtriple=x86_64-unknown-linux-gnu %s -x86-asm-syntax=intel -o - \
+; RUN:     | FileCheck --check-prefix=OUTPUT_INTEL %s
+
+define void @f() {
+; OUTPUT_ATT-LABEL: f:
+; OUTPUT_ATT:       # %bb.0:
+; OUTPUT_ATT-NEXT:    #APP
+; OUTPUT_ATT-NEXT:    movq %rbx, %rax
+; OUTPUT_ATT-NEXT:    #NO_APP
+; OUTPUT_ATT-NEXT:    retq
+;
+; OUTPUT_INTEL-LABEL: f:
+; OUTPUT_INTEL:       # %bb.0:
+; OUTPUT_INTEL-NEXT:    #APP
+; OUTPUT_INTEL-NEXT:    mov rax, rbx
+; OUTPUT_INTEL-NEXT:    #NO_APP
+; OUTPUT_INTEL-NEXT:    ret
+  call void asm sideeffect "$(movq %rbx, %rax $| mov rax, rbx$)", "~{dirflag},~{fpsr},~{flags}"()
+
+  ret void
+}
Index: llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
===================================================================
--- llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
+++ llvm/lib/CodeGen/AsmPrinter/AsmPrinterInlineAsm.cpp
@@ -277,7 +277,13 @@
   int CurVariant = -1;            // The number of the {.|.|.} region we are in.
   const char *LastEmitted = AsmStr; // One past the last character emitted.
   unsigned NumOperands = MI->getNumOperands();
-  int AsmPrinterVariant = MAI->getAssemblerDialect();
+
+  // Matches X86MCAsmInfo.cpp's AsmWriterFlavorTy::ATT.
+  // This function processes inline asm in AT&T style, so $(v0$|v1$) variant
+  // selection has to pick v0, the AT&T variant, since the input is AT&T.
+  // If MAI->getAssemblerDialect() returns 1, the output is Intel-style
+  // asm, but here we care about the input style.
+  int AsmPrinterVariant = 0;
 
   if (MAI->getEmitGNUAsmStartIndentationMarker())
     OS << '\t';


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113894.387248.patch
Type: text/x-patch
Size: 1972 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211115/c3decac1/attachment.bin>


More information about the llvm-commits mailing list