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

Rework :inbounds effects tainting #48246

Merged
merged 1 commit into from
Jan 12, 2023
Merged

Rework :inbounds effects tainting #48246

merged 1 commit into from
Jan 12, 2023

Conversation

Keno
Copy link
Member

@Keno Keno commented Jan 12, 2023

This works to fix #48243, by only tanting effects if an @inbounds statement is actually reached. Further, it refines the noinbounds effect to be IPO-cached and used to track whether a particular method read the inbounds state. A :boundscheck expression now does not immediately taint consistencty, but instead, taints noinbounds only. Then, if a method that has :noinbounds tainted is called within an @inbounds region, consistency is tainted. Similarly, a tainted :noinbounds disables constant propagation at @inbounds statements or if the method propagates inbounds.

@Keno Keno requested a review from aviatesk January 12, 2023 01:14
This works to fix #48243, by only tanting effects if an `@inbounds` statement
is actually reached. Further, it refines the `noinbounds` effect to be
IPO-cached and used to track whether a particular method read the inbounds state.
A `:boundscheck` expression now does not immediately taint consistencty, but
instead, taints `noinbounds` only. Then, if a method that has `:noinbounds`
tainted is called within an `@inbounds` region, consistency is tainted.
Similarly, a tainted `:noinbounds` disables constant propagation at
`@inbounds` statements or if the method propagates inbounds.
@KristofferC KristofferC added the backport 1.9 Change should be backported to release-1.9 label Jan 12, 2023
@jakobnissen jakobnissen added the compiler:effects effect analysis label Jan 12, 2023
@Keno Keno merged commit d544e78 into master Jan 12, 2023
@Keno Keno deleted the kf/reinbounds branch January 12, 2023 21:12
Copy link
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.

@goto delay_effects_analysis
end
end
flag = sv.src.ssaflags[sv.currpc]
Copy link
Member

Choose a reason for hiding this comment

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

We can use get_curr_ssaflag(sv) for this.

noinbounds = inbounds === :on || (inbounds === :default && all(flag::UInt8->iszero(flag&IR_FLAG_INBOUNDS), src.ssaflags))
consistent = noinbounds ? ALWAYS_TRUE : ALWAYS_FALSE
ipo_effects = Effects(EFFECTS_TOTAL; consistent, noinbounds)
ipo_effects = Effects(EFFECTS_TOTAL)
Copy link
Member

Choose a reason for hiding this comment

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

EFFECTS_TOTAL

aviatesk added a commit that referenced this pull request Jan 13, 2023
aviatesk added a commit to aviatesk/JET.jl that referenced this pull request Jan 13, 2023
aviatesk added a commit that referenced this pull request Jan 13, 2023
aviatesk added a commit that referenced this pull request Jan 13, 2023
@KristofferC KristofferC mentioned this pull request Jan 13, 2023
41 tasks
Keno added a commit that referenced this pull request Jan 16, 2023
LLVM can prove this inbounds and the annotation weakens the
inferable effects for tuple iteration, which has a surprisingly
large inference performance and precision impact.

Unfortunately, my previous changes to :inbounds tainting weren't
quite strong enough yet, because `getfield` was still tainting
consistency on unknown boundscheck arguments. To fix that, we
pass through the fargs into the fetfield effects to check if
we're getting a literal `:boundscheck`, in which case the
`:noinbounds` consistency-tainting logic I added in #48246
is sufficient to not require additional consistency tainting.

Also add a test for both effects and codegen to make sure this doens't regress.
Keno added a commit that referenced this pull request Jan 16, 2023
LLVM can prove this inbounds and the annotation weakens the
inferable effects for tuple iteration, which has a surprisingly
large inference performance and precision impact.

Unfortunately, my previous changes to :inbounds tainting weren't
quite strong enough yet, because `getfield` was still tainting
consistency on unknown boundscheck arguments. To fix that, we
pass through the fargs into the fetfield effects to check if
we're getting a literal `:boundscheck`, in which case the
`:noinbounds` consistency-tainting logic I added in #48246
is sufficient to not require additional consistency tainting.

Also add a test for both effects and codegen to make sure this doens't regress.
Keno added a commit that referenced this pull request Jan 16, 2023
LLVM can prove this inbounds and the annotation weakens the
inferable effects for tuple iteration, which has a surprisingly
large inference performance and precision impact.

Unfortunately, my previous changes to :inbounds tainting weren't
quite strong enough yet, because `getfield` was still tainting
consistency on unknown boundscheck arguments. To fix that, we
pass through the fargs into the fetfield effects to check if
we're getting a literal `:boundscheck`, in which case the
`:noinbounds` consistency-tainting logic I added in #48246
is sufficient to not require additional consistency tainting.

Also add a test for both effects and codegen to make sure this doens't regress.
KristofferC pushed a commit that referenced this pull request Jan 16, 2023
This works to fix #48243, by only tanting effects if an `@inbounds` statement
is actually reached. Further, it refines the `noinbounds` effect to be
IPO-cached and used to track whether a particular method read the inbounds state.
A `:boundscheck` expression now does not immediately taint consistencty, but
instead, taints `noinbounds` only. Then, if a method that has `:noinbounds`
tainted is called within an `@inbounds` region, consistency is tainted.
Similarly, a tainted `:noinbounds` disables constant propagation at
`@inbounds` statements or if the method propagates inbounds.

(cherry picked from commit d544e78)
Keno added a commit that referenced this pull request Jan 17, 2023
* Remove @inbounds in tuple iteration

LLVM can prove this inbounds and the annotation weakens the
inferable effects for tuple iteration, which has a surprisingly
large inference performance and precision impact.

Unfortunately, my previous changes to :inbounds tainting weren't
quite strong enough yet, because `getfield` was still tainting
consistency on unknown boundscheck arguments. To fix that, we
pass through the fargs into the fetfield effects to check if
we're getting a literal `:boundscheck`, in which case the
`:noinbounds` consistency-tainting logic I added in #48246
is sufficient to not require additional consistency tainting.

Also add a test for both effects and codegen to make sure this doens't regress.

* Int64 -> Int

* fixup typo
@KristofferC KristofferC removed the backport 1.9 Change should be backported to release-1.9 label Jan 17, 2023
aviatesk added a commit that referenced this pull request Jan 18, 2023
Keno added a commit that referenced this pull request Feb 14, 2023
We used to have this hack before #48246, but I removed it because I had
hoped we don't need. Unfortunately, we weren't able to infer consistency of
```
@inbounds (1,2)[1]
```
With this hack, constprop is able to independently prove inbounded-ness,
overriding the usual consistency taintaing that happens for inbounds.
aviatesk pushed a commit that referenced this pull request Feb 15, 2023
We used to have this hack before #48246, but I removed it because I had
hoped we don't need. Unfortunately, we weren't able to infer consistency of
```
@inbounds (1,2)[1]
```
With this hack, constprop is able to independently prove inbounded-ness,
overriding the usual consistency taintaing that happens for inbounds.
KristofferC pushed a commit that referenced this pull request Feb 20, 2023
We used to have this hack before #48246, but I removed it because I had
hoped we don't need. Unfortunately, we weren't able to infer consistency of
```
@inbounds (1,2)[1]
```
With this hack, constprop is able to independently prove inbounded-ness,
overriding the usual consistency taintaing that happens for inbounds.

(cherry picked from commit 113c2f3)
KristofferC pushed a commit that referenced this pull request Feb 20, 2023
We used to have this hack before #48246, but I removed it because I had
hoped we don't need. Unfortunately, we weren't able to infer consistency of
```
@inbounds (1,2)[1]
```
With this hack, constprop is able to independently prove inbounded-ness,
overriding the usual consistency taintaing that happens for inbounds.

(cherry picked from commit 113c2f3)
KristofferC pushed a commit that referenced this pull request Feb 21, 2023
We used to have this hack before #48246, but I removed it because I had
hoped we don't need. Unfortunately, we weren't able to infer consistency of
```
@inbounds (1,2)[1]
```
With this hack, constprop is able to independently prove inbounded-ness,
overriding the usual consistency taintaing that happens for inbounds.

(cherry picked from commit 113c2f3)
KristofferC pushed a commit that referenced this pull request Feb 21, 2023
We used to have this hack before #48246, but I removed it because I had
hoped we don't need. Unfortunately, we weren't able to infer consistency of
```
@inbounds (1,2)[1]
```
With this hack, constprop is able to independently prove inbounded-ness,
overriding the usual consistency taintaing that happens for inbounds.

(cherry picked from commit 113c2f3)
KristofferC pushed a commit that referenced this pull request Feb 21, 2023
We used to have this hack before #48246, but I removed it because I had
hoped we don't need. Unfortunately, we weren't able to infer consistency of
```
@inbounds (1,2)[1]
```
With this hack, constprop is able to independently prove inbounded-ness,
overriding the usual consistency taintaing that happens for inbounds.

(cherry picked from commit 113c2f3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:effects effect analysis
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@inbounds in dead code taints consistency
4 participants