This is an archive of the discontinued LLVM Phabricator instance.

[LoongArch] Add emergency spill slot for GPR for large frames
ClosedPublic

Authored by wangleiat on Oct 12 2022, 2:22 AM.

Details

Summary

An emergency spill slot is created when the stack size cannot be
represented by an 11-bit signed number.

This patch also modifies how the sp is adjusted in the prologue.

RegScavenger will place the spill instruction before the prologue
if a VReg is created in the prologue. This will pollute the caller's
stack data. Therefore, until there is better way, we just use the
addi.w/d instruction for stack adjustment to ensure that VReg will
not be created. (RISCV has the same issue #58286)

Diff Detail

Event Timeline

wangleiat created this revision.Oct 12 2022, 2:22 AM
wangleiat requested review of this revision.Oct 12 2022, 2:22 AM
wangleiat added inline comments.Oct 12 2022, 5:53 PM
llvm/lib/Target/LoongArch/LoongArchFrameLowering.cpp
176

Wrong logic, I will modify it to enable fp when the size is greater than 4096 and frame-pointer=none is not specified.

wangleiat updated this revision to Diff 467352.Oct 12 2022, 8:18 PM

Unfortunately, the framesize cannot be correctly judged in hasFP(). It seems that we can only use multiple addi.w/d instructions to adjust SP when FP is eliminated.

SixWeining accepted this revision.EditedOct 23 2022, 5:52 AM

This patch survives several tests from llvm-test-suite in O0 build which otherwise report errors like:

fatal error: error in backend: Error while trying to spill R7 from class GPR: Cannot scavenge register without an emergency spill slot!

These tests include:

  • MultiSource/Benchmarks/mafft
  • SingleSource/Regression/C/gcc-c-torture/execute/multi-ix.c
  • SingleSource/UnitTests/matrix-types-spec.cpp
This revision is now accepted and ready to land.Oct 23 2022, 5:52 AM

I get 2 failed tests after applying this patch:

Failed Tests (2):
  LLVM :: CodeGen/LoongArch/emergency-spill-slot.ll
  LLVM :: CodeGen/LoongArch/stack-realignment.ll

Perhaps should rebase?

I get 2 failed tests after applying this patch:

Failed Tests (2):
  LLVM :: CodeGen/LoongArch/emergency-spill-slot.ll
  LLVM :: CodeGen/LoongArch/stack-realignment.ll

Perhaps should rebase?

Thanks, i will rebase it.

wangleiat updated this revision to Diff 471457.Oct 28 2022, 2:42 AM

Rebase, based on D136222 with some modifications.

wangleiat updated this revision to Diff 471461.Oct 28 2022, 2:46 AM

fix spelling mistakes

This revision was landed with ongoing or failed builds.Oct 28 2022, 2:52 AM
This revision was automatically updated to reflect the committed changes.