-
-
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
set type of statement when processing GlobalRef
s
#44200
Conversation
Because we previously didn't set the type when processing `GlobalRef`, the optimizer was inserting unnecessary `PiNode`s. Before: ```julia julia> x::Int = 1 1 julia> function f() global x = 0 while x<10 x += 1 end x end f (generic function with 1 method) julia> @code_typed f() CodeInfo( 1 ── (Main.x = 0)::Any 2 ┄─ %2 = Main.x::Any │ %3 = (isa)(%2, Int64)::Bool └─── goto #4 if not %3 3 ── %5 = π (%2, Int64) │ %6 = Base.slt_int(%5, 10)::Bool └─── goto #5 4 ── %8 = (%2 < 10)::Bool └─── goto #5 5 ┄─ %10 = φ (#3 => %6, #4 => %8)::Bool └─── goto #10 if not %10 6 ── %12 = Main.x::Any │ %13 = (isa)(%12, Int64)::Bool └─── goto #8 if not %13 7 ── %15 = π (%12, Int64) │ %16 = Base.add_int(%15, 1)::Int64 └─── goto #9 8 ── %18 = (%12 + 1)::Int64 └─── goto #9 9 ┄─ %20 = φ (#7 => %16, #8 => %18)::Int64 │ (Main.x = %20)::Any └─── goto #2 10 ─ %23 = Main.x::Any └─── return %23 ) => Int64 ``` This PR: ```julia julia> @code_typed f() CodeInfo( 1 ─ (Main.x = 0)::Any 2 ┄ %2 = Main.x::Int64 │ %3 = Base.slt_int(%2, 10)::Bool └── goto #4 if not %3 3 ─ %5 = Main.x::Int64 │ %6 = Base.add_int(%5, 1)::Int64 │ (Main.x = %6)::Any └── goto #2 4 ─ %9 = Main.x::Int64 └── return %9 ) => Int64 ```
9858c43
to
de7b7a7
Compare
Co-authored-by: Shuhei Kadowaki <[email protected]>
Inference understands julia> x::Int = 1
1
julia> function f()
global x = 0
while x<10
x += 1
end
x
end
f (generic function with 1 method)
julia> @code_typed f()
CodeInfo(
1 ─ (Main.x = 0)::Any
2 ┄ %2 = Main.x::Any
│ %3 = Base.slt_int(%2, 10)::Bool
└── goto #4 if not %3
3 ─ %5 = Main.x::Any
│ %6 = Base.add_int(%5, 1)::Int64
│ (Main.x = %6)::Any
└── goto #2
4 ─ %9 = Main.x::Any
└── return %9
) => Int64 so that test case should pass already. Though we should set types for those |
Huh, so this must have improved very recently? But you still think this change is a good idea? |
Yeah, I compared this to bfc9431 before, so apparently it must have been fixed in the last 3 days. |
Interestingly, #44095 has improved the situation -- previously the inliner computes call signature by itself (so can be affected by this change) but now it just trusts the result of inference. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't come up with a test case that demonstrates what is improved by this change, but we may want to use this type information in some new optimization pass in the future.
Is the failure on macOS buildbot a known issue? I rebuilt it multiple times, but it seems to persist. |
Let's try one more time, I really can't imagine how that would be related. |
Co-authored-by: Jameson Nash <[email protected]>
global x = 0 | ||
while x < 10 | ||
x += 1 | ||
end | ||
x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
global x = 0 | |
while x < 10 | |
x += 1 | |
end | |
x | |
global x44200 = 0 | |
while x44200 < 10 | |
x44200 += 1 | |
end | |
x44200 |
FWIW, I don't see these PiNodes on my builds, so the test does not seem to do anything for me. Could be I am looking at the wrong thing though. |
Yes, as discussed above, #44095 actually already fixed this particular test case, but I think this is worthwhile regardless. |
Co-authored-by: Shuhei Kadowaki <[email protected]> Co-authored-by: Jameson Nash <[email protected]> (cherry picked from commit 39e849a)
Co-authored-by: Shuhei Kadowaki <[email protected]> Co-authored-by: Jameson Nash <[email protected]>
Co-authored-by: Shuhei Kadowaki <[email protected]> Co-authored-by: Jameson Nash <[email protected]>
Because we previously didn't set the type when processing
GlobalRef
,the optimizer was inserting unnecessary
PiNode
s.Before:
This PR: