-
Notifications
You must be signed in to change notification settings - Fork 533
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
Conversation
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.
Co-authored-by: Natalie Chouinard <chouinard.nm@gmail.com>
Co-authored-by: Natalie Chouinard <chouinard.nm@gmail.com>
// 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)) { |
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.
I wonder if we should do this all of the time. Is there a reason not to?
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.
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.
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:
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