Issue 233318
Summary [RISCV] Shadow stack epilogue loads FP callee-saved registers after freeing the frame
Labels backend:RISC-V, miscompilation
Assignees
Reporter MitchBriles
    Looks like this was introduced by #226309. If a function has a shadow stack and `+save-restore`, FP and vector callee-saved registers are restored twice. The second reload happens after sp is released, so it's reading from the caller's frame and clobbers the regs.

Repro:
```llvm
declare void @g()
define double @f(double %a, double %b) nounwind shadowcallstack {
  %c = fadd double %a, %b
  call void @g()
  %d = fmul double %c, %a
  ret double %d
}
```
`llc -mtriple=riscv64 -mattr=+d,+save-restore -target-abi=lp64d`
```asm
fld  fs0, 8(sp)   <
fld  fs1, 0(sp)   <
ld ra, 24(sp)
addi sp, sp, 32
ld   ra, -8(gp)
addi gp, gp, -8
fld  fs0, 8(sp)   < !!
fld  fs1, 0(sp)   < !!
ret
```
cc @lenary 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to