-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Unnecessary GC root for select/phi #22421
Comments
Another similar case: The following code allocates a GC root slots for julia> @noinline f(a, b, c) = (a, b, c)
f (generic function with 1 method)
julia> function g(a, b, c)
return f(a, b, c ? a : b)
end
g (generic function with 1 method)
julia> @code_llvm g(Ref(1), Ref(2), true) ; Function g
; Location: REPL[2]
define %jl_value_t addrspace(10)* @julia_g_64146(%jl_value_t addrspace(10)* dereferenceable(8), %jl_value_t addrspace(10)* dereferenceable(8), i8) {
top:
%3 = alloca %jl_value_t addrspace(10)*, i32 3
%gcframe = alloca %jl_value_t addrspace(10)*, i32 3
%4 = bitcast %jl_value_t addrspace(10)** %gcframe to i8*
call void @llvm.memset.p0i8.i32(i8* %4, i8 0, i32 24, i32 0, i1 false)
%ptls_i8 = call i8* asm "movq %fs:0, $0;\0Aaddq $$-10920, $0", "=r,~{dirflag},~{fpsr},~{flags}"()
%ptls = bitcast i8* %ptls_i8 to %jl_value_t***
; Location: REPL[2]:2
%5 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %gcframe, i32 0
%6 = bitcast %jl_value_t addrspace(10)** %5 to i64*
store i64 2, i64* %6
%7 = getelementptr %jl_value_t**, %jl_value_t*** %ptls, i32 0
%8 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %gcframe, i32 1
%9 = bitcast %jl_value_t addrspace(10)** %8 to %jl_value_t***
%10 = load %jl_value_t**, %jl_value_t*** %7
store %jl_value_t** %10, %jl_value_t*** %9
%11 = bitcast %jl_value_t*** %7 to %jl_value_t addrspace(10)***
store %jl_value_t addrspace(10)** %gcframe, %jl_value_t addrspace(10)*** %11
%12 = and i8 %2, 1
%13 = icmp eq i8 %12, 0
%. = select i1 %13, %jl_value_t addrspace(10)* %1, %jl_value_t addrspace(10)* %0
%14 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %gcframe, i32 2
store %jl_value_t addrspace(10)* %., %jl_value_t addrspace(10)** %14
%15 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %3, i32 0
store %jl_value_t addrspace(10)* %0, %jl_value_t addrspace(10)** %15
%16 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %3, i32 1
store %jl_value_t addrspace(10)* %1, %jl_value_t addrspace(10)** %16
%17 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %3, i32 2
store %jl_value_t addrspace(10)* %., %jl_value_t addrspace(10)** %17
%18 = call %jl_value_t addrspace(10)* @japi1_f_64146(%jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 140585273278480 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)** %3, i32 3)
%19 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %gcframe, i32 1
%20 = load %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %19
%21 = getelementptr %jl_value_t**, %jl_value_t*** %ptls, i32 0
%22 = bitcast %jl_value_t*** %21 to %jl_value_t addrspace(10)**
store %jl_value_t addrspace(10)* %20, %jl_value_t addrspace(10)** %22
ret %jl_value_t addrspace(10)* %18
} |
Seems like the argument input addrspace may be wrong? |
No those are fine (this also happens for locally allocated objects) The issue is that the pass treats |
If both inputs are rooted then we don't need to root the result. Rename `LoadRefinements` to `Refinements` since it's not load specific anymore. Fix #22421
If both inputs are rooted then we don't need to root the result. Rename `LoadRefinements` to `Refinements` since it's not load specific anymore. Fix #22421
Seems that global constant in select isn't handled very well. The following function shouldn't need a GC root since both input of
a
are globally rooted.LLVM IR.
The text was updated successfully, but these errors were encountered: