Skip to content

Commit 86098ab

Browse files
author
Quentin Colombet
committed
Reapply [X86] Add a new LOW32_ADDR_ACCESS_RBP register class.
This reapplies commit r268796, with a fix for the setting of the inline asm constraints. I.e., "mark" LOW32_ADDR_ACCESS_RBP as a GR variant, so that the regular processing of the GR operands (setting of the subregisters) happens. Original commit log: [X86] Add a new LOW32_ADDR_ACCESS_RBP register class. ABIs like NaCl uses 32-bit addresses but have 64-bit frame. The new register class reflects those constraints when choosing a register class for a address access. llvm-svn: 268955
1 parent 52d8e3b commit 86098ab

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30209,6 +30209,7 @@ static bool isGRClass(const TargetRegisterClass &RC) {
3020930209
case X86::GR64_NOSPRegClassID:
3021030210
case X86::GR64_NOREX_NOSPRegClassID:
3021130211
case X86::LOW32_ADDR_ACCESSRegClassID:
30212+
case X86::LOW32_ADDR_ACCESS_RBPRegClassID:
3021230213
return true;
3021330214
default:
3021430215
return false;

llvm/lib/Target/X86/X86RegisterInfo.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,15 @@ X86RegisterInfo::getPointerRegClass(const MachineFunction &MF,
166166
// we can still use 64-bit register as long as we know the high bits
167167
// are zeros.
168168
// Reflect that in the returned register class.
169-
return Is64Bit ? &X86::LOW32_ADDR_ACCESSRegClass : &X86::GR32RegClass;
169+
if (Is64Bit) {
170+
// When the target also allows 64-bit frame pointer and we do have a
171+
// frame, this is fine to use it for the address accesses as well.
172+
const X86FrameLowering *TFI = getFrameLowering(MF);
173+
return TFI->hasFP(MF) && TFI->Uses64BitFramePtr
174+
? &X86::LOW32_ADDR_ACCESS_RBPRegClass
175+
: &X86::LOW32_ADDR_ACCESSRegClass;
176+
}
177+
return &X86::GR32RegClass;
170178
case 1: // Normal GPRs except the stack pointer (for encoding reasons).
171179
if (Subtarget.isTarget64BitLP64())
172180
return &X86::GR64_NOSPRegClass;

llvm/lib/Target/X86/X86RegisterInfo.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,13 @@ def GR64_NOREX_NOSP : RegisterClass<"X86", [i64], 64,
427427
// which we do not have right now.
428428
def LOW32_ADDR_ACCESS : RegisterClass<"X86", [i32], 64, (add GR32, RIP)>;
429429

430+
// When RBP is used as a base pointer in a 32-bit addresses environement,
431+
// this is also safe to use the full register to access addresses.
432+
// Since RBP will never be spilled, stick to a 32 alignment to save
433+
// on memory consumption.
434+
def LOW32_ADDR_ACCESS_RBP : RegisterClass<"X86", [i32], 32,
435+
(add LOW32_ADDR_ACCESS, RBP)>;
436+
430437
// A class to support the 'A' assembler constraint: EAX then EDX.
431438
def GR32_AD : RegisterClass<"X86", [i32], 32, (add EAX, EDX)>;
432439

llvm/test/CodeGen/X86/x86-64-stack-and-frame-ptr.ll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
; RUN: llc -mtriple=x86_64-pc-linux < %s | FileCheck %s
2-
; RUN: llc -mtriple=x86_64-pc-linux-gnux32 < %s | FileCheck -check-prefix=X32ABI %s
3-
; RUN: llc -mtriple=x86_64-pc-nacl < %s | FileCheck -check-prefix=NACL %s
1+
; RUN: llc -verify-machineinstrs -mtriple=x86_64-pc-linux < %s | FileCheck %s
2+
; RUN: llc -verify-machineinstrs -mtriple=x86_64-pc-linux-gnux32 < %s | FileCheck -check-prefix=X32ABI %s
3+
; RUN: llc -verify-machineinstrs -mtriple=x86_64-pc-nacl < %s | FileCheck -check-prefix=NACL %s
44

55
; x32 uses %esp, %ebp as stack and frame pointers
66

0 commit comments

Comments
 (0)