llvm / llvm/llvm-project

[IPRA] IPRA Skips Saving Used Callee-Saved Registers in Prologue/Epilogue

Open
#196,865 1 comment 0 reactions 1 assignee Claimed by @vigbalu View on GitHub
llvm:codegen llvm:regalloc missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

When IPRA is enabled, the callee-saved register (CSR) set considered during prologue/epilogue construction is restricted to RBP. This can cause callee-saved registers that are actually used by a function (e.g., R13, R14) to be neither saved nor restored.

Test Case:
-------
```llvm
; RUN: llc -enable-ipra < %s -o - | FileCheck %s

target triple = "x86_64-unknown-unknown"

; Prologue/Epilogue should not skip R13 and R14 when IPRA enabled since it is used.
; CHECK-LABEL: function1:
; CHECK: pushq %r14
; CHECK: pushq %r13

define internal void @function1() norecurse noinline {
call void asm sideeffect "movl %r13d, %eax\0A addl %r14d, %eax", "~{eax},~{r13},~{r14}"()
ret void
}

; r13 and r14 live across call to function1 so it must be saved by callee before use.
; CHECK-LABEL: function2:
; CHECK: pushq %r14
; CHECK: pushq %r13
define void @function2(i32 %x) noinline {
call void asm sideeffect "movl %edi, %r13d\0A movl %edi, %r14d", "~{r13},~{r14}"()
call void @function1()
call void asm sideeffect "movl %r13d, %eax\0A addl %r14d, %eax", "~{eax},~{r13},~{r14}"()
ret void
}

define i32 @main() {
call void @function2(i32 7)
ret i32 0
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.