Skip to content

Commit 55e5908

Browse files
committed
[RISCV] Exclude vector callee saved registers from RISCVRegisterInfo::needsFrameBaseReg
The vector callee saved registers shouldn't affect the frame pointer offset so we don't want to consider them. I've listed the GPR, FPR32, and FPR64 register classes explicitly because getMinimalPhysRegClass is slow and this function is called frequently. So explicitly listing the interesting classs should be a compile time improvement.
1 parent c3028a2 commit 55e5908

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

llvm/lib/Target/RISCV/RISCVRegisterInfo.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,16 @@ bool RISCVRegisterInfo::needsFrameBaseReg(MachineInstr *MI,
615615
unsigned CalleeSavedSize = 0;
616616
for (const MCPhysReg *R = MRI.getCalleeSavedRegs(); MCPhysReg Reg = *R;
617617
++R) {
618-
if (!Subtarget.isRegisterReservedByUser(Reg))
619-
CalleeSavedSize += getSpillSize(*getMinimalPhysRegClass(Reg));
618+
if (Subtarget.isRegisterReservedByUser(Reg))
619+
continue;
620+
621+
if (RISCV::GPRRegClass.contains(Reg))
622+
CalleeSavedSize += getSpillSize(RISCV::GPRRegClass);
623+
else if (RISCV::FPR64RegClass.contains(Reg))
624+
CalleeSavedSize += getSpillSize(RISCV::FPR64RegClass);
625+
else if (RISCV::FPR32RegClass.contains(Reg))
626+
CalleeSavedSize += getSpillSize(RISCV::FPR32RegClass);
627+
// Ignore vector registers.
620628
}
621629

622630
int64_t MaxFPOffset = Offset - CalleeSavedSize;

llvm/test/CodeGen/RISCV/rvv/callee-saved-regs.ll

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,34 @@ entry:
9393

9494
ret <vscale x 1 x i32> %va
9595
}
96+
97+
; Make sure the local stack allocation pass doesn't count vector registers. The
98+
; sizes are chosen to be on the edge of what RISCVRegister::needsFrameBaseReg
99+
; considers to need a virtual base register.
100+
define riscv_vector_cc void @local_stack_allocation_frame_pointer() "frame-pointer"="all" {
101+
; SPILL-O2-LABEL: local_stack_allocation_frame_pointer:
102+
; SPILL-O2: # %bb.0:
103+
; SPILL-O2-NEXT: addi sp, sp, -2032
104+
; SPILL-O2-NEXT: .cfi_def_cfa_offset 2032
105+
; SPILL-O2-NEXT: sw ra, 2028(sp) # 4-byte Folded Spill
106+
; SPILL-O2-NEXT: sw s0, 2024(sp) # 4-byte Folded Spill
107+
; SPILL-O2-NEXT: .cfi_offset ra, -4
108+
; SPILL-O2-NEXT: .cfi_offset s0, -8
109+
; SPILL-O2-NEXT: addi s0, sp, 2032
110+
; SPILL-O2-NEXT: .cfi_def_cfa s0, 0
111+
; SPILL-O2-NEXT: addi sp, sp, -480
112+
; SPILL-O2-NEXT: lbu a0, -1912(s0)
113+
; SPILL-O2-NEXT: sb a0, -1912(s0)
114+
; SPILL-O2-NEXT: addi sp, s0, -2048
115+
; SPILL-O2-NEXT: addi sp, sp, -464
116+
; SPILL-O2-NEXT: addi sp, sp, 480
117+
; SPILL-O2-NEXT: lw ra, 2028(sp) # 4-byte Folded Reload
118+
; SPILL-O2-NEXT: lw s0, 2024(sp) # 4-byte Folded Reload
119+
; SPILL-O2-NEXT: addi sp, sp, 2032
120+
; SPILL-O2-NEXT: ret
121+
%va = alloca [2500 x i8], align 4
122+
%va_gep = getelementptr [2000 x i8], ptr %va, i64 0, i64 600
123+
%load = load volatile i8, ptr %va_gep, align 4
124+
store volatile i8 %load, ptr %va_gep, align 4
125+
ret void
126+
}

0 commit comments

Comments
 (0)