Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[LoongArch] Too many sp adjustment instructions in the prologue #88109

Closed
heiher opened this issue Apr 9, 2024 · 0 comments · Fixed by #88110
Closed

[LoongArch] Too many sp adjustment instructions in the prologue #88109

heiher opened this issue Apr 9, 2024 · 0 comments · Fixed by #88110

Comments

@heiher
Copy link
Member

heiher commented Apr 9, 2024

For this reproducer:

define void @large_frame_size() {
  %1 = alloca [16384 x { i32, i32 }], align 4
  ret void
}

There are too many instructions generated for sp adjustment in the prologue:

clang -target loongarch64 -S -o - large-frame-size.ll
	.text
	.file	"large-frame-size.ll"
	.globl	large_frame_size                # -- Begin function large_frame_size
	.p2align	5
	.type	large_frame_size,@function
large_frame_size:                       # @large_frame_size
	.cfi_startproc
# %bb.0:
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -2048
	addi.d	$sp, $sp, -16
	.cfi_def_cfa_offset 131088
	lu12i.w	$a0, 32
	ori	$a0, $a0, 16
	add.d	$sp, $sp, $a0
	ret
.Lfunc_end0:
	.size	large_frame_size, .Lfunc_end0-large_frame_size
	.cfi_endproc
                                        # -- End function
	.section	".note.GNU-stack","",@progbits
	.addrsig
@heiher heiher self-assigned this Apr 9, 2024
heiher added a commit to heiher/llvm-project that referenced this issue Apr 9, 2024
After commit 18c5f3c ("[RegisterScavenger][RISCV] Don't search for FrameSetup
instrs if we were searching from Non-FrameSetup instrs"), we can revert the `sp`
adjustment 4e2364a ("[LoongArch] Add emergency spill slot for GPR for large
frames") to generate better code, as the issue with `RegScavenger` has been
resolved.

Fixes llvm#88109
heiher added a commit that referenced this issue Apr 10, 2024
After commit 18c5f3c ("[RegisterScavenger][RISCV] Don't search for
FrameSetup instrs if we were searching from Non-FrameSetup instrs"), we
can revert the `sp` adjustment 4e2364a ("[LoongArch] Add emergency
spill slot for GPR for large frames") to generate better code, as the
issue with `RegScavenger` has been resolved.

Fixes #88109
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants