-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
optimizer: Handle path-excluded Core.ifelse arguments
#50312
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -742,6 +742,57 @@ let m = Meta.@lower 1 + 1 | |
| @test Core.Compiler.verify_ir(ir) === nothing | ||
| end | ||
|
|
||
| # A lifted Core.ifelse with an eliminated branch (#50276) | ||
| let m = Meta.@lower 1 + 1 | ||
| @assert Meta.isexpr(m, :thunk) | ||
| src = m.args[1]::CodeInfo | ||
| src.code = Any[ | ||
| # block 1 | ||
| #= %1: =# Core.Argument(2), | ||
| # block 2 | ||
| #= %2: =# Expr(:call, Core.ifelse, SSAValue(1), true, missing), | ||
| #= %3: =# GotoIfNot(SSAValue(2), 11), | ||
| # block 3 | ||
| #= %4: =# PiNode(SSAValue(2), Bool), # <-- This PiNode is the trigger of the bug, since it | ||
| # means that only one branch of the Core.ifelse | ||
| # is lifted. | ||
| #= %5: =# GotoIfNot(false, 8), | ||
| # block 2 | ||
| #= %6: =# nothing, | ||
| #= %7: =# GotoNode(8), | ||
| # block 4 | ||
| #= %8: =# PhiNode(Int32[5, 7], Any[SSAValue(4), SSAValue(6)]), | ||
| # ^-- N.B. This PhiNode also needs to have a Union{ ... } type in order | ||
| # for lifting to be performed (it is skipped for e.g. `Bool`) | ||
| # | ||
| #= %9: =# Expr(:call, isa, SSAValue(8), Missing), | ||
| #= %10: =# ReturnNode(SSAValue(9)), | ||
| # block 5 | ||
| #= %11: =# ReturnNode(false), | ||
|
Comment on lines
+750
to
+771
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice 👍 |
||
| ] | ||
| src.ssavaluetypes = Any[ | ||
| Any, | ||
| Union{Missing, Bool}, | ||
| Any, | ||
| Bool, | ||
| Any, | ||
| Missing, | ||
| Any, | ||
| Union{Nothing, Bool}, | ||
| Bool, | ||
| Any, | ||
| Any | ||
| ] | ||
| nstmts = length(src.code) | ||
| src.codelocs = fill(one(Int32), nstmts) | ||
| src.ssaflags = fill(one(Int32), nstmts) | ||
| src.slotflags = fill(zero(UInt8), 3) | ||
| ir = Core.Compiler.inflate_ir(src) | ||
| @test Core.Compiler.verify_ir(ir) === nothing | ||
| ir = @test_nowarn Core.Compiler.sroa_pass!(ir) | ||
| @test Core.Compiler.verify_ir(ir) === nothing | ||
| end | ||
|
|
||
| # Issue #31546 - missing widenconst in SROA | ||
| function f_31546(x) | ||
| (a, b) = x == "r" ? (false, false) : | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
On second look, this bypasses the count removal of the cond. This probably needs to be:
Possibly also consider turning on the oracle check for the tests, which would have caught this.