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

cfg_simplify! error #52058

Closed
aviatesk opened this issue Nov 7, 2023 · 0 comments · Fixed by #52111
Closed

cfg_simplify! error #52058

aviatesk opened this issue Nov 7, 2023 · 0 comments · Fixed by #52111
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)

Comments

@aviatesk
Copy link
Sponsor Member

aviatesk commented Nov 7, 2023

MRE:

julia> ir, = Base.code_ircode() do
           while true
               i = @noinline rand(Int)
               if @noinline isodd(i)
                   return i
               end
           end
       end |> only
  1nothing::Nothing
3 2%2 = invoke Main.rand(Main.Int::Type{Int64})::Int64
4%3 = invoke Main.isodd(%2::Int64)::Bool
  └──      goto #4 if not %3
5 3return %2
7 4 ─      goto #1
   => Int64                                                                                                                                                                   

julia> Core.Compiler.cfg_simplify!(ir)
ERROR: AssertionError: label > 0
Stacktrace:
 [1] 
   @ Core.Compiler ./compiler/ssair/ir.jl:1348
 [2] cfg_simplify!(ir::Core.Compiler.IRCode)
   @ Core.Compiler ./compiler/ssair/passes.jl:2276
 [3] top-level scope
   @ REPL[8]:1
Some type information was truncated. Use `show(err)` to see complete types.

This issue particularly blocks #51960, which introduces actual use of cfg_simplify! into the base compilation pipeline. To echo what Keno mentioned in our previous Slack chat:

Keno Fischer
I'd have to look into it, but the thing that strikes me as unusual about this IR is that we loop into the entry block. I wouldn't be surprised if we accidentally used the entry as a magic value somewhere and got confused

@aviatesk aviatesk added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label Nov 7, 2023
topolarity added a commit to topolarity/julia that referenced this issue Nov 9, 2023
This code was using the sentinel value -1 as a special marker in
addition to the negative BB indices. That ambiguity was causing
`cfg_simplify!` to fail on functions that merge any BB into the
first basic block.

This change is to use `typemin(Int)` as a marker instead.

Fixes JuliaLang#52058
topolarity added a commit to topolarity/julia that referenced this issue Nov 10, 2023
This code was using the sentinel value -1 as a special marker in
addition to the negative BB indices. That ambiguity was causing
`cfg_simplify!` to fail on functions that merge any BB into the
first basic block.

This change is to use `typemin(Int)` as a marker instead.

Fixes JuliaLang#52058
aviatesk pushed a commit that referenced this issue Nov 11, 2023
This code was using the sentinel value -1 as a special marker in
addition to the negative BB indices. That ambiguity was causing
`cfg_simplify!` to fail on functions that merge any BB into the first
basic block.

This change is to use `typemin(Int)` as a marker instead.

Fixes #52058
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:optimizer Optimization passes (mostly in base/compiler/ssair/)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant