Skip to content

Commit 8bc7c0a

Browse files
committed
[X86] Fix failures on EXPENSIVE_CHECKS builds
Error message ``` *** Bad machine code: Illegal virtual register for instruction *** - function: test__blsi_u32 - basic block: %bb.0 (0x7a61208) - instruction: %5:gr32 = MOV32r0 implicit-def $eflags - operand 0: %5:gr32 Expected a GR32_NOREX2 register, but got a GR32 register ``` Reported by RKSimon in #77433 The failure is b/c compiler emits a MOV32r0 with operand GR32 when fast-isel is enabled. ``` // X86FastISel.cpp Register SrcReg = fastEmitInst_(X86::MOV32r0, &X86::GR32RegClass) ``` However, before this patch, compiler only allows GR32_NOREX operand b/c MOV32r0 is a pseudo instruction. In this patch, we relax the register class of the operand to GR32 b/c MOV32r0 is always expanded to XOR32rr, which can use EGPR. The bug was not introduced by #77433 but caught by it.
1 parent 3044d75 commit 8bc7c0a

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

llvm/lib/Target/X86/MCTargetDesc/X86BaseInfo.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,10 @@ inline bool canUseApxExtendedReg(const MCInstrDesc &Desc) {
12601260
if (Encoding == X86II::EVEX)
12611261
return true;
12621262

1263+
unsigned Opcode = Desc.Opcode;
1264+
// MOV32r0 is always expanded to XOR32rr
1265+
if (Opcode == X86::MOV32r0)
1266+
return true;
12631267
// To be conservative, egpr is not used for all pseudo instructions
12641268
// because we are not sure what instruction it will become.
12651269
// FIXME: Could we improve it in X86ExpandPseudo?
@@ -1268,7 +1272,6 @@ inline bool canUseApxExtendedReg(const MCInstrDesc &Desc) {
12681272

12691273
// MAP OB/TB in legacy encoding space can always use egpr except
12701274
// XSAVE*/XRSTOR*.
1271-
unsigned Opcode = Desc.Opcode;
12721275
switch (Opcode) {
12731276
default:
12741277
break;

0 commit comments

Comments
 (0)