Skip to content
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

Calling jl_value_ptr has inlining cost of 20 even when its optimized out #51912

Open
Zentrik opened this issue Oct 28, 2023 · 2 comments
Open

Comments

@Zentrik
Copy link
Member

Zentrik commented Oct 28, 2023

I'm on master (#51892), but I see same results on 1.9.3 and 1.10.0-beta3.

julia> function test(d)
             return Base.pointer_from_objref(d)
       end
test (generic function with 1 method)

julia> d = IdDict((3=>5))
IdDict{Int64, Int64} with 1 entry:
  3 => 5
julia> @code_llvm test(d)
; Function Signature: test(Base.IdDict{Int64, Int64})
;  @ REPL[7]:1 within `test`
define i64 @julia_test_3355({}* noundef nonnull align 8 dereferenceable(24) %"d::IdDict") #0 {
top:
;  @ REPL[7]:2 within `test`
  %coercion = ptrtoint {}* %"d::IdDict" to i64
  ret i64 %coercion
}

julia> Base.print_statement_costs(stdout, test, Tuple{typeof(d)})
test(d) @ Main REPL[7]:1
 20 1%1 = $(Expr(:foreigncall, :(:jl_value_ptr), Ptr{Nothing}, svec(Any), 0, :(:ccall), Core.Argument(2)))::Ptr{Nothing}
  0 └──      return %1

Even though the call is optimized out there is still an inlining cost, I thought this comment said it was fixed, #41461 (comment) but I can reproduce that issue.

@Zentrik Zentrik changed the title Calling jl_value_ptr has inlining cost of 20 even when its compiled out Calling jl_value_ptr has inlining cost of 20 even when its optimized out Oct 28, 2023
@Zentrik
Copy link
Member Author

Zentrik commented Oct 28, 2023

Should jl_value_ptr be added here like jl_string_ptr?

elseif head === :foreigncall
foreigncall = ex.args[1]
if foreigncall isa QuoteNode && foreigncall.value === :jl_string_ptr
return 1
end
return 20

@vtjnash
Copy link
Sponsor Member

vtjnash commented Oct 28, 2023

Probably not. jl_value_ptr is harmful to the compiler for optimizations and correctness. The jl_string_ptr function should be removed eventually, but doesn't change compilation much since it only references constant memory.

Zentrik added a commit to Zentrik/julia that referenced this issue Oct 29, 2023
Unfortunately, cost is ~106 now so still too high, JuliaLang#51912 is tracking issue about high cost.

Lowers inlining cost of setproperty as we know rhs isa Memory{Any}
Zentrik added a commit to Zentrik/julia that referenced this issue Oct 29, 2023
Unfortunately, cost is ~106 now so still too high, JuliaLang#51912 is tracking issue about high cost.

Lowers inlining cost of setproperty as we know rhs isa Memory{Any}
Zentrik added a commit to Zentrik/julia that referenced this issue Oct 31, 2023
Unfortunately, cost is ~106 now so still too high, JuliaLang#51912 is tracking issue about high cost.

Lowers inlining cost of setproperty as we know rhs isa Memory{Any}
Zentrik added a commit to Zentrik/julia that referenced this issue Nov 14, 2023
Unfortunately, cost is ~106 now so still too high, JuliaLang#51912 is tracking issue about high cost.

Lowers inlining cost of setproperty as we know rhs isa Memory{Any}
Zentrik added a commit to Zentrik/julia that referenced this issue Feb 2, 2024
Unfortunately, cost is ~106 now so still too high, JuliaLang#51912 is tracking issue about high cost.

Lowers inlining cost of setproperty as we know rhs isa Memory{Any}
Zentrik added a commit to Zentrik/julia that referenced this issue Jul 14, 2024
Unfortunately, cost is ~106 now so still too high, JuliaLang#51912 is tracking issue about high cost.

Lowers inlining cost of setproperty as we know rhs isa Memory{Any}
giordano pushed a commit to Zentrik/julia that referenced this issue Aug 5, 2024
Unfortunately, cost is ~106 now so still too high, JuliaLang#51912 is tracking issue about high cost.

Lowers inlining cost of setproperty as we know rhs isa Memory{Any}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants