Skip to content

Conversation

@MasonProtter
Copy link
Contributor

Backport of PR #60442

…Lang#60442)

~~(I wrote this with assistance from Gemini since I'm not very used to
writing LLVM IR)~~ No longer using that code

This is an attempt to fix
JuliaLang#60441. After bumbling around a
bit, it seems that the problem is that `invoke(f, ::CodeInstance,
args...)` calls are not turned into `Expr(:invoke` statements in the IR,
but remains as `:call`s to the `invoke` builtin which ends up going
through the runtime.

~~There's probably a better way to do this, but the way I found was to
just detect these builtin calls in the LLVM IR, and send them to
`emit_invoke`.~~ I'm now detecting `InvokeCICallInfo`s in the inlining
step of the optimizer and turning those into `Expr(:invoke`s.

It appears to resolve the issue:
```julia
using BenchmarkTools

mysin(x::Float64) = sin(x)
@Assert mysin(1.0) == sin(1.0)
const mysin_ci = Base.specialize_method(Base._which(Tuple{typeof(mysin), Float64})).cache
```
Before this PR:
```julia
julia> @Btime invoke(mysin, mysin_ci, x) setup=(x=rand())
  24.952 ns (2 allocations: 32 bytes)
0.7024964043721993
```
After this PR:
```julia
julia> @Btime invoke(mysin, mysin_ci, x) setup=(x=rand())
  4.748 ns (0 allocations: 0 bytes)
0.32283046823183426
```
@MasonProtter
Copy link
Contributor Author

Already backported in 00737ca

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

Successfully merging this pull request may close these issues.

2 participants