Skip to content

Commit 4b38ceb

Browse files
committed
[X86] Remove MWAITX_SAVE_EBX pseudo instruction. Always save/restore the full %rbx register even in gnux32.
ebx/rbx only needs to be saved when 64-bit registers are supported anyway. It should be fine to save/restore the whole rbx register even in gnux32 where the base is technically just ebx. This matches what we do for cmpxchg16b where rbx is saved/restored regardless of gnux32.
1 parent 628a319 commit 4b38ceb

File tree

4 files changed

+17
-32
lines changed

4 files changed

+17
-32
lines changed

llvm/lib/Target/X86/X86ExpandPseudo.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,6 @@ bool X86ExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
442442
MBB.erase(MBBI);
443443
return true;
444444
}
445-
case X86::MWAITX_SAVE_EBX:
446445
case X86::MWAITX_SAVE_RBX: {
447446
// Perform the following transformation.
448447
// SaveRbx = pseudomwaitx InArg, SaveRbx
@@ -458,9 +457,7 @@ bool X86ExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
458457
BuildMI(MBB, MBBI, DL, TII->get(X86::MWAITXrrr));
459458
// Finally, restore the value of RBX.
460459
Register SaveRbx = MBBI->getOperand(2).getReg();
461-
unsigned BasePointer = Opcode == X86::MWAITX_SAVE_EBX ? X86::EBX : X86::RBX;
462-
TII->copyPhysReg(MBB, MBBI, DL, BasePointer, SaveRbx,
463-
/*SrcIsKill*/ true);
460+
TII->copyPhysReg(MBB, MBBI, DL, X86::RBX, SaveRbx, /*SrcIsKill*/ true);
464461
// Delete the pseudo.
465462
MBBI->eraseFromParent();
466463
return true;

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33793,7 +33793,7 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
3379333793
Register BasePtr = TRI->getBaseRegister();
3379433794
bool IsRBX = (BasePtr == X86::RBX || BasePtr == X86::EBX);
3379533795
// If no need to save the base pointer, we generate MWAITXrrr,
33796-
// else we generate pseudo MWAITX_SAVE_RBX/EBX.
33796+
// else we generate pseudo MWAITX_SAVE_RBX.
3379733797
if (!IsRBX || !TRI->hasBasePointer(*MF)) {
3379833798
BuildMI(*BB, MI, DL, TII->get(TargetOpcode::COPY), X86::ECX)
3379933799
.addReg(MI.getOperand(0).getReg());
@@ -33812,17 +33812,15 @@ X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
3381233812
.addReg(MI.getOperand(0).getReg());
3381333813
BuildMI(*BB, MI, DL, TII->get(TargetOpcode::COPY), X86::EAX)
3381433814
.addReg(MI.getOperand(1).getReg());
33815-
const TargetRegisterClass *RegClass =
33816-
BasePtr == X86::EBX ? &X86::GR32RegClass : &X86::GR64RegClass;
33817-
// Save RBX (or EBX) into a virtual register.
33818-
Register SaveRBX = MF->getRegInfo().createVirtualRegister(RegClass);
33815+
assert(Subtarget.is64Bit() && "Expected 64-bit mode!");
33816+
// Save RBX into a virtual register.
33817+
Register SaveRBX =
33818+
MF->getRegInfo().createVirtualRegister(&X86::GR64RegClass);
3381933819
BuildMI(*BB, MI, DL, TII->get(TargetOpcode::COPY), SaveRBX)
33820-
.addReg(BasePtr);
33820+
.addReg(X86::RBX);
3382133821
// Generate mwaitx pseudo.
33822-
unsigned Opcode =
33823-
BasePtr == X86::RBX ? X86::MWAITX_SAVE_RBX : X86::MWAITX_SAVE_EBX;
33824-
Register Dst = MF->getRegInfo().createVirtualRegister(RegClass);
33825-
BuildMI(*BB, MI, DL, TII->get(Opcode))
33822+
Register Dst = MF->getRegInfo().createVirtualRegister(&X86::GR64RegClass);
33823+
BuildMI(*BB, MI, DL, TII->get(X86::MWAITX_SAVE_RBX))
3382633824
.addDef(Dst) // Destination tied in with SaveRBX.
3382733825
.addReg(MI.getOperand(2).getReg()) // input value of EBX.
3382833826
.addUse(SaveRBX); // Save of base pointer.

llvm/lib/Target/X86/X86InstrCompiler.td

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -896,19 +896,9 @@ def LCMPXCHG16B_SAVE_RBX :
896896
GR64:$rbx_save))]>;
897897
}
898898

899-
// This pseudo must be used when the frame uses RBX as
899+
// This pseudo must be used when the frame uses RBX/EBX as
900900
// the base pointer.
901-
// cf comment for LCMPXCHG8B_SAVE_EBX.
902-
let Defs = [EBX], Uses = [ECX, EAX, EBX],
903-
Predicates = [HasMWAITX], SchedRW = [WriteSystem],
904-
isCodeGenOnly = 1, isPseudo = 1, Constraints = "$ebx_save = $dst" in {
905-
def MWAITX_SAVE_EBX :
906-
I<0, Pseudo, (outs GR32:$dst),
907-
(ins GR32:$ebx_input, GR32:$ebx_save),
908-
"mwaitx",
909-
[]>;
910-
}
911-
// Same as MWAITX_SAVE_EBX but for the case where RBX is the base pointer.
901+
// cf comment for LCMPXCHG16B_SAVE_RBX.
912902
let Defs = [EBX], Uses = [ECX, EAX, EBX],
913903
Predicates = [HasMWAITX], SchedRW = [WriteSystem],
914904
isCodeGenOnly = 1, isPseudo = 1, Constraints = "$rbx_save = $dst" in {

llvm/test/CodeGen/X86/base-pointer-and-mwaitx.ll

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ entry:
4242
; USE_BASE_32: movl %ecx, %eax
4343
; USE_BASE_32: movl %edx, %ecx
4444
; Save base pointer.
45-
; USE_BASE_32: movl %ebx, [[SAVE_ebx:%e(di|si)]]
45+
; USE_BASE_32: movq %rbx, [[SAVE_rbx:%r(di|si)]]
4646
; Set mwaitx ebx argument.
4747
; USE_BASE_32: movl %r8d, %ebx
4848
; USE_BASE_32-NEXT: mwaitx
4949
; Restore base pointer.
50-
; USE_BASE_32-NEXT: movl [[SAVE_ebx]], %ebx
50+
; USE_BASE_32-NEXT: movq [[SAVE_rbx]], %rbx
5151

5252
; Pass mwaitx 3 arguments in eax, ecx, ebx
5353
; NO_BASE_64: movl %r8d, %ebx
@@ -111,12 +111,12 @@ if.end:
111111
; USE_BASE_32: movl %esi, %eax
112112
; USE_BASE_32: movl %edi, %ecx
113113
; Save base pointer.
114-
; USE_BASE_32: movl %ebx, [[SAVE_ebx:%e(di|si)]]
114+
; USE_BASE_32: movq %rbx, [[SAVE_rbx:%r(di|si)]]
115115
; Set mwaitx ebx argument.
116116
; USE_BASE_32: movl %edx, %ebx
117117
; USE_BASE_32-NEXT: mwaitx
118118
; Restore base pointer.
119-
; USE_BASE_32-NEXT: movl [[SAVE_ebx]], %ebx
119+
; USE_BASE_32-NEXT: movq [[SAVE_rbx]], %rbx
120120

121121
; Pass mwaitx 3 arguments in eax, ecx, ebx
122122
; NO_BASE_64: movl %edx, %ebx
@@ -179,12 +179,12 @@ if.end:
179179
; USE_BASE_32: movl %esi, %eax
180180
; USE_BASE_32: movl %edi, %ecx
181181
; Save base pointer.
182-
; USE_BASE_32: movl %ebx, [[SAVE_ebx:%e(di|si)]]
182+
; USE_BASE_32: movq %rbx, [[SAVE_rbx:%r(di|si)]]
183183
; Set mwaitx ebx argument.
184184
; USE_BASE_32: movl %edx, %ebx
185185
; USE_BASE_32-NEXT: mwaitx
186186
; Restore base pointer.
187-
; USE_BASE_32-NEXT: movl [[SAVE_ebx]], %ebx
187+
; USE_BASE_32-NEXT: movq [[SAVE_rbx]], %rbx
188188

189189
; Pass mwaitx 3 arguments in eax, ecx, ebx
190190
; NO_BASE_64: movl %edx, %ebx

0 commit comments

Comments
 (0)