Skip to content

codegen: slightly optimize gc-frame allocation #58794

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

Merged
merged 1 commit into from
Jun 25, 2025

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Jun 23, 2025

Try to avoid allocating frames for some very simple function that only have the safepoint on entry and don't define any values themselves.

@vtjnash vtjnash added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label Jun 23, 2025
@gbaraldi
Copy link
Member

Is this what we discussed around JuliaArrays/FixedSizeArrays.jl#142?

@giordano
Copy link
Member

There seems to be a segfault during compilation of the Compiler.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
Try to avoid allocating frames for some very simple function that only
have the safepoint on entry and don't define any values themselves.
@vtjnash vtjnash force-pushed the jn/gcframe-special-roots branch 2 times, most recently from f6ef0c1 to f76156c Compare June 24, 2025 18:27
@vtjnash vtjnash merged commit 2ed8561 into master Jun 25, 2025
7 of 10 checks passed
@vtjnash vtjnash deleted the jn/gcframe-special-roots branch June 25, 2025 18:07
@giordano
Copy link
Member

In case this was supposed to address JuliaArrays/FixedSizeArrays.jl#142, I don't think it did the job. The top block is still the same as before:

julia> code_llvm(Base.mapreduce_impl, (typeof(identity), typeof(Base.add_sum), FixedSizeVectorDefault{Float64}, Int, Int, Int); )
; Function Signature: mapreduce_impl(typeof(Base.identity), typeof(Base.add_sum), FixedSizeArrays.FixedSizeArray{Float64, 1, Memory{Float64}}, Int64, Int64, Int64)
;  @ reduce.jl:251 within `mapreduce_impl`
; Function Attrs: noinline
define double @julia_mapreduce_impl_3803(ptr nocapture noundef nonnull readonly align 8 dereferenceable(16) %"A::FixedSizeArray", ptr nocapture noundef nonnull readonly align 8 dereferenceable(8) %.roots.A, i64 signext %"ifirst::Int64", i64 signext %"ilast::Int64", i64 signext %"blksize::Int64") local_unnamed_addr #0 {
top:
  %gcframe1 = alloca [4 x ptr], align 16
  call void @llvm.memset.p0.i64(ptr align 16 %gcframe1, i8 0, i64 32, i1 true)
  %0 = getelementptr inbounds nuw i8, ptr %gcframe1, i64 24
  %1 = getelementptr inbounds nuw i8, ptr %gcframe1, i64 16
  %pgcstack = call ptr inttoptr (i64 4296883980 to ptr)(i64 4296884016) #12
  store i64 8, ptr %gcframe1, align 8
  %task.gcstack = load ptr, ptr %pgcstack, align 8
  %frame.prev = getelementptr inbounds nuw i8, ptr %gcframe1, i64 8
  store ptr %task.gcstack, ptr %frame.prev, align 8
  store ptr %gcframe1, ptr %pgcstack, align 8
  %memoryref_mem = load ptr, ptr %.roots.A, align 8
;  @ reduce.jl:253 within `mapreduce_impl`
; ┌ @ promotion.jl:637 within `==`
   %.not = icmp eq i64 %"ifirst::Int64", %"ilast::Int64"
; └
  br i1 %.not, label %L33, label %L39

; [...]
julia> code_llvm(Base.mapreduce_impl, (typeof(identity), typeof(Base.add_sum), Vector{Float64}, Int, Int, Int); )
; Function Signature: mapreduce_impl(typeof(Base.identity), typeof(Base.add_sum), Array{Float64, 1}, Int64, Int64, Int64)
;  @ reduce.jl:251 within `mapreduce_impl`
; Function Attrs: noinline
define double @julia_mapreduce_impl_3887(ptr noundef nonnull align 8 dereferenceable(24) %"A::Array", i64 signext %"ifirst::Int64", i64 signext %"ilast::Int64", i64 signext %"blksize::Int64") local_unnamed_addr #0 {
top:
;  @ reduce.jl:253 within `mapreduce_impl`
; ┌ @ promotion.jl:637 within `==`
   %.not = icmp eq i64 %"ifirst::Int64", %"ilast::Int64"
; └
  br i1 %.not, label %L18, label %L23

; [...]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants