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

Relax constraints on the PHI block #50308

Merged
merged 1 commit into from
Jun 29, 2023
Merged

Relax constraints on the PHI block #50308

merged 1 commit into from
Jun 29, 2023

Conversation

Keno
Copy link
Member

@Keno Keno commented Jun 27, 2023

In #50158, I tought the verifier to reject code that has invalid statements in the original PHI block. In #50235, this required irinterp to stop folding PhiNodes to the respective constants. I said at the time that a subsequent compact would fix it, but it turns out that we don't actually have the logic for that. I might still add that logic, but on the other hand it just seems kinda silly that PhiNodes need to be a special case here.

This PR relaxes the semantics of the PHI block, to allow any value-position constant to appear in the PHI block and undoes the irinterp change from #50235. Only the interpreter really cares about the semantics of the phi block, so the primary change is there.

Of note, SSAValue forwards are not allowed in the phi block. This is because of the following:

loop:
 %1 = %(...)
 %2 = %1
 %3 = %(top => %1)

The two phi values %1 and %2 have different semantics: %1 gets the current iteration of the loop, while %3 gets the previous value. As a result, any pass that wants to move SSAValues out of PhiNode uses would have to be aware of these semantics anyway, and there's no simplicitly benefits to allowing SSAValues in the middle of a phi block.

@Keno Keno force-pushed the kf/relaxphiblock branch from 04fec61 to 147f6c8 Compare June 27, 2023 21:15
In #50158, I tought the verifier to reject code that has invalid
statements in the original PHI block. In #50235, this required
irinterp to stop folding PhiNodes to the respective constants.
I said at the time that a subsequent compact would fix it, but
it turns out that we don't actually have the logic for that.
I might still add that logic, but on the other hand it just
seems kinda silly that PhiNodes need to be a special case here.

This PR relaxes the semantics of the PHI block, to allow any
value-position constant to appear in the PHI block and undoes
the irinterp change from #50235. Only the interpreter really
cares about the semantics of the phi block, so the primary change
is there.

Of note, SSAValue forwards are not allowed in the phi block. This
is because of the following:

```
loop:
 %1 = %(...)
 %2 = %1
 %3 = %(top => %1)
```

The two phi values %1 and %2 have different semantics: %1 gets
the *current* iteration of the loop, while %3 gets the *previous*
value. As a result, any pass that wants to move SSAValues out of
PhiNode uses would have to be aware of these semantics anyway,
and there's no simplicitly benefits to allowing SSAValues in the
middle of a phi block.
@Keno Keno force-pushed the kf/relaxphiblock branch from 147f6c8 to 0a1d0c3 Compare June 28, 2023 15:18
@Keno Keno merged commit e4600c5 into master Jun 29, 2023
@Keno Keno deleted the kf/relaxphiblock branch June 29, 2023 13:06
Keno added a commit that referenced this pull request Nov 28, 2023
This restriction has been in there since this code was added in #44557.
Unfortunately, I can't tell from the commit history why this restriction
was added. It's possible that it was trying to avoid putting things into
statement position that were not allowed in the phi block, but we have
cleaned that up since (#50308 and related), so let's see if this restriction
is still required, since I was seeing some suboptimial optimization results
because of this.
aviatesk pushed a commit that referenced this pull request Dec 1, 2023
This restriction has been in there since this code was added in #44557.
Unfortunately, I can't tell from the commit history why this restriction
was added. It's possible that it was trying to avoid putting things into
statement position that were not allowed in the phi block, but we have
cleaned that up since (#50308 and related), so let's see if this restriction
is still required, since I was seeing some suboptimial optimization results
because of this.
Keno added a commit that referenced this pull request Dec 7, 2023
…52338)

This restriction has been in there since this code was added in #44557.
Unfortunately, I can't tell from the commit history why this restriction
was added. It's possible that it was trying to avoid putting things into
statement position that were not allowed in the phi block, but we have
cleaned that up since (#50308 and related), so let's see if this
restriction is still required, since I was seeing some suboptimial
optimization results because of this.

---------

Co-authored-by: Shuhei Kadowaki <[email protected]>
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.

1 participant