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

Fix condition for unreachable code in IRCode conversion #53512

Merged

Conversation

topolarity
Copy link
Member

@topolarity topolarity commented Feb 28, 2024

This is a partial back-port of #50924, where we discovered that the optimizer would ignore:

  1. must-throw %XX = SlotNumber(_) statements
  2. must-throw goto #bb if not %x statements

This is mostly harmless, except that in the case of (1) we can accidentally fall through the statically deleted (Const()-wrapped) code from inference and end up observing a control-flow edge that never existed.

If the spurious edge is to a catch block, then the edge is invalid semantically and breaks our SSA conversion.

This one-line change fixes (1) but not (2), which is enough for IR validity.

Resolves part of #53366.

@topolarity
Copy link
Member Author

topolarity commented Feb 28, 2024

Needs a test before this merges, but otherwise this should be good to go.

As far as I can tell, this bug is present on 1.9 but I believe it is being masked by a difference in our compact! behavior that causes the unused (and invalid) φ-nodes here to be cleaned up:

  21%58  = φᶜ (%85)::Base.GenericCondition{ReentrantLock}
  │           φ (#20 => %59, #2 => %1)::Base.GenericCondition{ReentrantLock}%71  = φᶜ (%86, %98)::Core.Compiler.MaybeUndef(Core.Const(nothing))
  │           φ (#20 => %73, #2 => #undef)::Core.Compiler.MaybeUndef(Union{})%76  = φᶜ (%87, %103)::Core.Compiler.MaybeUndef(Core.Const(nothing))
  │           φ (#20 => %78, #2 => #undef)::Core.Compiler.MaybeUndef(Union{})%81  = φᶜ (%88)::Core.Compiler.MaybeUndef(Union{})
  │           φ (#20 => %82, #2 => #undef)::Core.Compiler.MaybeUndef(Union{})
  └───        $(Expr(:leave, 1))

Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@topolarity topolarity force-pushed the ct/fix-bad-phi branch 2 times, most recently from c8d1ad8 to 9f3f0a3 Compare February 29, 2024 17:07
@kpamnany
Copy link
Contributor

kpamnany commented Mar 6, 2024

Maybe merge this @topolarity, while we're waiting on #53553?

This is a partial back-port of JuliaLang#50924, where we discovered that the
optimizer would ignore:
  1. must-throw `%XX = SlotNumber(_)` statements
  2. must-throw `goto #bb if not %x` statements
when re-building the CFG during IRCode conversion.

This is mostly harmless, except that in the case of (1) we can accidentally
fall through the statically deleted (`Const()`-wrapped) code from inference
and observe a control-flow edge that never should have existed, such as an
edge into a catch block. Such an edge is invalid semantically and breaks our
SSA conversion.

This one-line change fixes (1) but not (2), which is enough for IR validity.
We should follow-up with a tweak to `compute_basic_blocks` to enforce this
requirement.

The test added here is very brittle, but it's better than nothing until we
have utilities to provide hand-written (pre-optimizer) IR and pass it through
part of our pipeline.
@topolarity topolarity added the merge me PR is reviewed. Merge when all tests are passing label Mar 7, 2024
@topolarity topolarity merged commit 035d17a into JuliaLang:kc/backports-release-1.10 Mar 7, 2024
7 checks passed
Drvi pushed a commit to RelationalAI/julia that referenced this pull request Mar 8, 2024
…53512)

This is a partial back-port of JuliaLang#50924, where we discovered that the
optimizer would ignore:
  1. must-throw `%XX = SlotNumber(_)` statements
  2. must-throw `goto #bb if not %x` statements

This is mostly harmless, except that in the case of (1) we can
accidentally fall through the statically deleted (`Const()`-wrapped)
code from inference and end up observing a control-flow edge that never
existed.

If the spurious edge is to a catch block, then the edge is invalid
semantically and breaks our SSA conversion.

This one-line change fixes (1) but not (2), which is enough for IR
validity.

Resolves part of JuliaLang#53366.

(cherry picked from commit 035d17a)
@IanButterworth IanButterworth removed the merge me PR is reviewed. Merge when all tests are passing label Mar 8, 2024
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.

4 participants