codegen: shrink-wrap the GC shadow-stack frame #61596
@nanosoldier runtests()
The package evaluation job you requested has completed - possible new issues were detected.
The full report is available.
<details><summary>Report summary</summary>
❗ Packages that crashed
3 packages crashed only on the current version.
- The process was aborted: 1 packages
- An internal error was encountered: 1 packages
- A segmentation fault happened: 1 packages
452 packages crashed on the previous version too.
✖ Packages that failed
17 packages failed only on the current version.
- Package has test failures: 1 packages
- Package tests unexpectedly errored: 1 packages
- Tests became inactive: 2 packages
- Test duration exceeded the time limit: 13 packages
3918 packages failed on the previous version too.
✔ Packages that passed tests
17 packages passed tests only on the current version.
- Other: 17 packages
5893 packages passed tests on the previous version too.
➖ Packages that were skipped altogether
1412 packages were skipped on the previous version too.
</details>
Bump!
Claude Fable was mad about this failing an assertion if the input has any unreachable blocks in the CFG (it gives julia<lower_intrinsics;no_enable_early_simplifications;no_enable_scalar_optimizations;no_enable_loop_optimizations;no_enable_vector_pipeline> as an example of a pipeline that won't run SimplifyCFG first). I think we always run SimplifyCFG in any of the -On levels, so I'm fine leaving it either way.
This is a little sketchy to me, since what we actually need is to addUser every basic block containing a store or load to an alloca that has a tracked store. I had Fable make an attempt at creating a Julia reproducer for this but it flailed; I think we avoid it by chance. If we ever made the getfield with boundscheck off generate better code, I think it would be possible to get AllocOpt create an alloca used in this way and trigger the problem from Julia.
xal-0
gbaraldi
This sadly doesn't do as much as I wanted it to because swiftself seems to interact badly with the backend. It forces spills of the swiftself arg even where it's not needed. So a second thing might be to disable swiftcc and just pass the ptls as a normal argument
Summary
The GC frame is allocated and pushed unconditionally at function entry.
For many functions it's only needed in a subsection of the CFG — the
cold branch of a diamond, a loop body that occasionally takes a rare
branch, or the throw path of a boundscheck — and the fast paths pay
the memset + shadow-stack push for nothing.
LateLowerGCFrame now picks a sink block (NCD of the BBs that actually
use the frame, hoisted out of loops) and places
julia.push_gc_framethere instead of at entry. Pops are inserted before in-sink returns
and on split CFG edges that leave the sink region. Functions that call
jl_enter_handler/jl_pop_handler[_noexcept]are skipped, since asunk push/pop must bracket the same enter/leave set.
FinalLowerGC keeps the backing alloca in the entry block (LLVM static
alloca) and only emits the memset plus
llvm.lifetime.startat thepossibly-sunk call site.
llvm.lifetime.endis emitted after each pop.Modeled on LLVM's ShrinkWrap pass.
Test plan
test/llvmpasses/late-lower-gc-shrink-wrap.jlcovers five patterns: early-exit diamond, loop preheader, boundscheck throw, hot-path regression guard, try/catch EH bailout.parse, dict with tuple values, generators) run correctly.This pull request was written with the assistance of generative AI (Claude Opus 4.7).