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

Optimize codegen of access functions for SimpleVector #37303

Merged
merged 1 commit into from
Sep 3, 2020

Conversation

yuyichao
Copy link
Contributor

Better alias info and GC root tracking.

This is the reason I made the observation in #37230 (comment)

@martinholters
Copy link
Member

Can you give before/after of generated code, possibly with

--- a/base/compiler/abstractinterpretation.jl
+++ b/base/compiler/abstractinterpretation.jl
@@ -982,7 +982,7 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
         return CallMeta(abstract_call_known(interp, <:, fargs, argtypes, sv).rt, false)
     elseif la == 2 && isa(argtypes[2], Const) && isa(argtypes[2].val, SimpleVector) && istopfunction(f, :length)
         # mark length(::SimpleVector) as @pure
-        return CallMeta(Const(length(argtypes[2].val)), false)
+        return CallMeta(Const(length(argtypes[2].val)), nothing)
     elseif la == 3 && isa(argtypes[2], Const) && isa(argtypes[3], Const) &&
             isa(argtypes[2].val, SimpleVector) && isa(argtypes[3].val, Int) && istopfunction(f, :getindex)
         # mark getindex(::SimpleVector, i::Int) as @pure

also applied?

Better alias info and GC root tracking.
@yuyichao
Copy link
Contributor Author

yuyichao commented Aug 31, 2020

The final LLVM IR is locally identical, the only change is a simpler julia IR and better code when interacting with other code. AFAICT, the old code inlines just fine and this does not really make inlining easier in any significant way, at least not for any of the functions I touched directly. (They inline just fine for non-constant arguments and causes a runtime dispatch for constant arguments for both length and getindex.)

I just pushed another update with better type check (only applies if someone ccall these directly) and I included a constant evaluation for length to be consistent with sizeof. With your patch that causes the original code to be inlined it does now give a constant in the LLVM IR but I think it should still be fixed in inference instead...

@JeffBezanson JeffBezanson merged commit 270a7ff into master Sep 3, 2020
@JeffBezanson JeffBezanson deleted the yyc/codegen/svec branch September 3, 2020 18:21
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.

None yet

3 participants