[llvm] r333722 - [X86][Disassembler] Make sure EVEX.X is not used to extend base registers of memory operations.

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu May 31 21:29:34 PDT 2018


Author: ctopper
Date: Thu May 31 21:29:34 2018
New Revision: 333722

URL: http://llvm.org/viewvc/llvm-project?rev=333722&view=rev
Log:
[X86][Disassembler] Make sure EVEX.X is not used to extend base registers of memory operations.

This was an accidental side effect of EVEX.X being used to encode XMM16-XMM31 using modrm.rm with modrm.mod==0x3.

I think there are still more bugs related to this.

Modified:
    llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp
    llvm/trunk/test/MC/Disassembler/X86/x86-64.txt

Modified: llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp?rev=333722&r1=333721&r2=333722&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp (original)
+++ llvm/trunk/lib/Target/X86/Disassembler/X86DisassemblerDecoder.cpp Thu May 31 21:29:34 2018
@@ -1304,7 +1304,7 @@ static int readDisplacement(struct Inter
  * @return      - 0 if the information was successfully read; nonzero otherwise.
  */
 static int readModRM(struct InternalInstruction* insn) {
-  uint8_t mod, rm, reg;
+  uint8_t mod, rm, reg, evexrm;
 
   dbgprintf(insn, "readModRM()");
 
@@ -1341,9 +1341,11 @@ static int readModRM(struct InternalInst
 
   reg |= rFromREX(insn->rexPrefix) << 3;
   rm  |= bFromREX(insn->rexPrefix) << 3;
+
+  evexrm = 0;
   if (insn->vectorExtensionType == TYPE_EVEX && insn->mode == MODE_64BIT) {
     reg |= r2FromEVEX2of4(insn->vectorExtensionPrefix[1]) << 4;
-    rm  |=  xFromEVEX2of4(insn->vectorExtensionPrefix[1]) << 4;
+    evexrm = xFromEVEX2of4(insn->vectorExtensionPrefix[1]) << 4;
   }
 
   insn->reg = (Reg)(insn->regBase + reg);
@@ -1433,7 +1435,7 @@ static int readModRM(struct InternalInst
       break;
     case 0x3:
       insn->eaDisplacement = EA_DISP_NONE;
-      insn->eaBase = (EABase)(insn->eaRegBase + rm);
+      insn->eaBase = (EABase)(insn->eaRegBase + rm + evexrm);
       break;
     }
     break;

Modified: llvm/trunk/test/MC/Disassembler/X86/x86-64.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Disassembler/X86/x86-64.txt?rev=333722&r1=333721&r2=333722&view=diff
==============================================================================
--- llvm/trunk/test/MC/Disassembler/X86/x86-64.txt (original)
+++ llvm/trunk/test/MC/Disassembler/X86/x86-64.txt Thu May 31 21:29:34 2018
@@ -576,3 +576,7 @@
 
 #CHECK: enclv
 0x0f 0x01 0xc0
+
+# Make sure we ignore EVEX.X when the index register isn't being used.
+#CHECK: vaddps (%rax), %xmm16, %xmm1
+0x62 0xb1 0x7c 0x00 0x58 0x08




More information about the llvm-commits mailing list