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

opt: prevent meld to merge block with MaximalReconvergence #5557

Merged
merged 4 commits into from
Feb 6, 2024

Conversation

Keenuts
Copy link
Contributor

@Keenuts Keenuts commented Feb 5, 2024

The extension SPV_KHR_maximal_reconvergence adds more constraints around the merge blocks, and how the control flow can be altered.

The one we address here is explained in the following part of the spec:

Note: This means that the instructions in a break block will execute as if
they were still diverged according to the loop iteration. This restricts
potential transformations an implementation may perform on the IR to match
shader author expectations. Similarly, instructions in the loop construct
cannot be moved into the continue construct unless it can be proven that
invocations are always converged.

Until the optimizer is clever enough to determine if the invocation have already converged, we shall not meld a block which branches to a merge block into it, as it might move some instructions outside of the convergence region.

This behavior being only required with the extension, this commit behavior change is gated by the extension.
This means using wave operations without the maximal reconvergence extension might lead to undefined behaviors.

Related to microsoft/DirectXShaderCompiler#6222

The extension SPV_KHR_maximal_reconvergence adds more constraints
around the merge blocks, and how the control flow can be altered.

The one we address here is explained in the following part of the spec:

  Note: This means that the instructions in a break block will execute as if
  they were still diverged according to the loop iteration. This restricts
  potential transformations an implementation may perform on the IR to match
  shader author expectations. Similarly, instructions in the loop construct
  cannot be moved into the continue construct unless it can be proven that
  invocations are always converged.

Until the optimizer is clever enough to determine if the invocation
have already converged, we shall not meld a block which branches to a
merge block into it, as it might move some instructions outside of the
convergence region.

This behavior being only required with the extension, this commit
behavior change is gated by the extension.
This means using wave operations without the maximal reconvergence
extension might lead to undefined behaviors.
source/opt/block_merge_util.cpp Outdated Show resolved Hide resolved
source/opt/block_merge_util.cpp Outdated Show resolved Hide resolved
Keenuts and others added 2 commits February 6, 2024 11:30
Co-authored-by: Natalie Chouinard <chouinard.nm@gmail.com>
Co-authored-by: Natalie Chouinard <chouinard.nm@gmail.com>
@Keenuts Keenuts enabled auto-merge (squash) February 6, 2024 10:31
@Keenuts Keenuts disabled auto-merge February 6, 2024 10:31
@Keenuts Keenuts enabled auto-merge (squash) February 6, 2024 10:31
@Keenuts Keenuts merged commit ab59dc6 into KhronosGroup:main Feb 6, 2024
24 checks passed
// cannot be moved into the continue construct unless it can be proven that
// invocations are always converged.
if (succ_is_merge && context->get_feature_mgr()->HasExtension(
kSPV_KHR_maximal_reconvergence)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should do this all of the time. Is there a reason not to?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should disallow merging with unresolve comments so auto-merge don't betrays us.

Well, the main reason is it is not disallowed by the spec. So I wanted to be conservative in the changes we do.

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.

None yet

3 participants