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

Align meaning for effects and IR flags #50313

Merged
merged 1 commit into from
Jun 28, 2023
Merged

Conversation

Keno
Copy link
Member

@Keno Keno commented Jun 27, 2023

This fixes a longstanding todo where the IR_FLAG_EFFECT_FREE flag actually required both :effect_free and :nothrow. After this PR, it is equivalent to :effect_free only. The mismatch in meaning here caused #50311. Symbol(::String) is :effect_free, but not :nothrow. As a result, setting IR_FLAG_EFFECT_FREE on it was not legal. Later, irinterp did discover that it was nothrow and set IR_FLAG_NOTHROW, but did not have sufficient information to know that it was also :effect_free, so it could not set that flag. With this PR, IR_FLAG_EFFECT_FREE is set early in inference, so once irinterp discovers IR_FLAG_NOTHROW, the call becomes DCE-eligible as desired. Fixes #50311.

This fixes a longstanding todo where the IR_FLAG_EFFECT_FREE flag
actually required both :effect_free and :nothrow. After this PR,
it is equivalent to :effect_free only. The mismatch in meaning here
caused #50311. `Symbol(::String)` is :effect_free, but not :nothrow.
As a result, setting IR_FLAG_EFFECT_FREE on it was not legal. Later,
irinterp did discover that it was nothrow and set IR_FLAG_NOTHROW,
but did not have sufficient information to know that it was also
:effect_free, so it could not set that flag. With this PR,
IR_FLAG_EFFECT_FREE is set early in inference, so once irinterp
discovers IR_FLAG_NOTHROW, the call becomes DCE-eligible as
desired. Fixes #50311.
@Keno Keno added the compiler:optimizer Optimization passes (mostly in base/compiler/ssair/) label Jun 27, 2023
@@ -510,9 +510,11 @@ end)

function Symbol(s::String)
@_foldable_meta
@noinline
Copy link
Member

Choose a reason for hiding this comment

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

why is this @noinline?

Copy link
Member Author

Choose a reason for hiding this comment

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

There's rarely a good reason to inline a ccall and in this case if you inline it, you lose the ability to consteval it, because the effect flags only attach to the function as a whole.

@Keno Keno merged commit 014f8de into master Jun 28, 2023
2 checks passed
@Keno Keno deleted the kf/effectsflagsalignment branch June 28, 2023 03:44
oxinabox added a commit to JuliaDiff/Diffractor.jl that referenced this pull request Jun 28, 2023
Copy link
Sponsor Member

@aviatesk aviatesk left a comment

Choose a reason for hiding this comment

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

LGTM.

@@ -1650,7 +1651,7 @@ function inline_const_if_inlineable!(inst::Instruction)
inst[:inst] = quoted(rt.val)
return true
end
inst[:flag] |= IR_FLAG_EFFECT_FREE
inst[:flag] |= IR_FLAG_EFFECT_FREE | IR_FLAG_NOTHROW
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

Maybe better to define

const IR_FLAG_REMOVAL_IF_UNUSED

.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure

oxinabox added a commit to JuliaDiff/Diffractor.jl that referenced this pull request Jun 28, 2023
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 this pull request may close these issues.

Symbol(::String) not eliminated by irinterp
3 participants