Skip to content

Commit 420928b

Browse files
committed
[X86][CodeGen] Fix compile crash in EVEX compression for corner case
The base register of OPmi_ND may be allocated to the same physic register as the ND operand. OPmi_ND is not compressible b/c it has different semnatic from OPmi. In this case, `isRedundantNewDataDest` should return false, otherwise we would get error Assertion `!IsNDLike && "Missing entry for ND-like instruction"' failed.
1 parent 6c39fa9 commit 420928b

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

llvm/lib/Target/X86/X86CompressEVEX.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ static bool isRedundantNewDataDest(MachineInstr &MI, const X86Subtarget &ST) {
189189
const MCInstrDesc &Desc = MI.getDesc();
190190
Register Reg0 = MI.getOperand(0).getReg();
191191
const MachineOperand &Op1 = MI.getOperand(1);
192-
if (!Op1.isReg())
192+
if (!Op1.isReg() || X86::getFirstAddrOperandIdx(MI) == 1)
193193
return false;
194194
Register Reg1 = Op1.getReg();
195195
if (Reg1 == Reg0)

llvm/test/CodeGen/X86/apx/compress-evex.mir

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@ body: |
5252
RET64 $rax
5353
...
5454
---
55+
name: ndd_2_non_ndd_mem
56+
body: |
57+
bb.0.entry:
58+
; CHECK: addq $123456, (%rax), %rax # encoding: [0x62,0xf4,0xfc,0x18,0x81,0x00,0x40,0xe2,0x01,0x00]
59+
renamable $rax = MOV64rm $noreg, 1, $noreg, 0, $fs
60+
renamable $rax = nsw ADD64mi32_ND killed renamable $rax, 1, $noreg, 0, $noreg, 123456, implicit-def dead $eflags
61+
RET64 $rax
62+
...
63+
---
5564
name: ndd_2_non_ndd_egpr
5665
body: |
5766
bb.0.entry:

0 commit comments

Comments
 (0)