[llvm] [Draft] Support save/restore point splitting in shrink-wrap (PR #119359)

Alex Bradbury via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 2 14:33:40 PST 2025


asb wrote:

Thanks for the updates. There are definitely remaining issues as I'm still getting crashes in those same benchmarks (and additionally in gcc). Looking at the codegen diffs for spec built with an unmodified baseline compiler vs this branch and picking the first one where the bad codegen is easy to see (another example of stack frame being allocated twice) I get this minimal reproducer:

```llvm
; ModuleID = 'reduced.ll'
source_filename = "reduced.ll"
target datalayout = "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128"
target triple = "riscv64-unknown-linux-gnu"

define double @widget(ptr %arg, ptr %arg1, double %arg2, i1 %arg3, double %arg4, double %arg5, double %arg6, double %arg7, double %arg8, double %arg9, double %arg10, double %arg11, double %arg12, double %arg13, double %arg14, double %arg15) {
bb:
  %select = select i1 %arg3, double %arg2, double 0.000000e+00
  %fadd = fadd double %arg2, -1.000000e+00
  %fadd16 = fadd double %arg6, -1.000000e+00
  %fsub = fsub double 1.000000e+00, %arg15
  %fsub17 = fsub double 1.000000e+00, %arg2
  %getelementptr = getelementptr i8, ptr %arg, i64 16
  store double %fsub17, ptr %arg, align 8
  %call = tail call double @llvm.fmuladd.f64(double %arg2, double 0.000000e+00, double 0.000000e+00)
  store double 0.000000e+00, ptr %arg1, align 8
  %load = load double, ptr inttoptr (i64 136 to ptr), align 8
  %call18 = tail call double @llvm.fmuladd.f64(double %call, double %fadd, double %load)
  %call19 = tail call double @llvm.fmuladd.f64(double %arg14, double %arg13, double %call18)
  %load20 = load double, ptr inttoptr (i64 176 to ptr), align 8
  %call21 = tail call double @llvm.fmuladd.f64(double %load20, double 0.000000e+00, double %call19)
  %call22 = tail call double @llvm.fmuladd.f64(double %arg8, double %call21, double %arg4)
  store double %call22, ptr %getelementptr, align 8
  %load23 = load double, ptr %arg, align 8
  %call24 = tail call double @llvm.fmuladd.f64(double %select, double 0.000000e+00, double %load23)
  %call25 = tail call double @llvm.fmuladd.f64(double %arg5, double %call24, double %arg7)
  store double %call25, ptr %arg, align 8
  %load26 = load double, ptr %arg1, align 8
  %call27 = tail call double @llvm.fmuladd.f64(double %load26, double 0.000000e+00, double %arg10)
  %call28 = tail call double @llvm.fmuladd.f64(double %call27, double 0.000000e+00, double %arg9)
  store double %call28, ptr %arg1, align 8
  store double %arg2, ptr %arg, align 8
  %fmul = fmul double %arg11, %fsub
  %call29 = tail call double @llvm.fmuladd.f64(double %fadd16, double 0.000000e+00, double %arg12)
  %call30 = tail call double @llvm.fmuladd.f64(double %fmul, double %call29, double 0.000000e+00)
  ret double %call30
}

; Function Attrs: nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.fmuladd.f64(double, double, double) #0

attributes #0 = { nocallback nocreateundeforpoison nofree nosync nounwind speculatable willreturn memory(none) }

```

The bad codegen is the duplicated `addi sp, sp, -16`:
```
widget:                                 # @widget
# %bb.0:                                # %bb
	addi	sp, sp, -16
	fmv.d.x	ft0, a4
	fmv.d.x	ft1, a3
	fmv.d.x	ft3, a5
	fmv.d.x	ft4, a6
	fmv.d.x	ft5, a7
	andi	a2, a2, 1
	fmv.d.x	ft2, zero
	fmv.d	ft6, fa0
	bnez	a2, .LBB0_2
# %bb.1:                                # %bb
	fmv.d	ft6, ft2
.LBB0_2:                                # %bb
	addi	sp, sp, -16
	fsd	fs0, 8(sp)                      # 8-byte Folded Spill
	fsd	fs1, 0(sp)                      # 8-byte Folded Spill
	li	a2, -1025
...
```

https://github.com/llvm/llvm-project/pull/119359


More information about the llvm-commits mailing list