[PATCH] D144183: [X86][MC] Fix the bug of -output-asm-variant=1 for intel syntax

Kan Shengchen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Feb 16 05:28:21 PST 2023


skan created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
skan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Before this patch

  $ echo "leal    (,%r15), %eax" | llvm-mc --show-encoding --output-asm-variant=1
  
          lea     eax, [r15]                      # encoding: [0x42,0x8d,0x04,0x3d,0x00,0x00,0x00,0x00]
  
  $ echo "lea     eax, [r15]" | llvm-mc --show-encoding -x86-asm-syntax=intel --output-asm-variant=1
  
          lea     eax, [r15]                      # encoding: [0x41,0x8d,0x07]

MC printed the register r15 as a base in intel syntax even when it's an index.
Then we got a different encoding by using the assembly from the output of the
first command.

I believe the behavior is too weird to be called a feature.

After this patch, we get

  $ echo "leal    (,%r15), %eax" | llvm-mc --show-encoding --output-asm-variant=1
  
          lea     eax, [1*r15]                    # encoding: [0x42,0x8d,0x04,0x3d,0x00,0x00,0x00,0x00]


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144183

Files:
  llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.cpp
  llvm/test/MC/Disassembler/X86/intel-syntax.txt


Index: llvm/test/MC/Disassembler/X86/intel-syntax.txt
===================================================================
--- llvm/test/MC/Disassembler/X86/intel-syntax.txt
+++ llvm/test/MC/Disassembler/X86/intel-syntax.txt
@@ -171,4 +171,5 @@
 # CHECK: lea	rcx, [rsp + 4]
 0x48 0x8d 0x4c 0x24 0x04 
 
-
+# CHECK: lea    rcx, [1*rax]
+0x48 0x8d 0x0c 0x05 0x00 0x00 0x00 0x00
Index: llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.cpp
===================================================================
--- llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.cpp
+++ llvm/lib/Target/X86/MCTargetDesc/X86IntelInstPrinter.cpp
@@ -398,7 +398,7 @@
 
   if (IndexReg.getReg()) {
     if (NeedPlus) O << " + ";
-    if (ScaleVal != 1)
+    if (ScaleVal != 1 || !BaseReg.getReg())
       O << ScaleVal << '*';
     printOperand(MI, Op+X86::AddrIndexReg, O);
     NeedPlus = true;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144183.497981.patch
Type: text/x-patch
Size: 878 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230216/765f789a/attachment.bin>


More information about the llvm-commits mailing list