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

spirv-opt: fix copy-propagate-arrays index opti on structs. #4891

Merged
merged 2 commits into from
Aug 16, 2022

Conversation

Keenuts
Copy link
Contributor

@Keenuts Keenuts commented Aug 11, 2022

Copy-propagate-arrays optimization pass would create unused constants,
even if the optimization not completed.
This was caused by the way we handled OpAccessChain squashing: we
only referenced constants, and had to create them upfront.

For now, I couldn't find a path to reproduce this. (Might have one involving RuntimeArrays, but couldn't generate one).
This however will be more visible once #4887 is fixed since we would need to abort while computing the final OpAccessChain.

Signed-off-by: Nathan Gauër brioche@google.com

@Keenuts Keenuts requested a review from s-perron August 11, 2022 12:50
@Keenuts Keenuts marked this pull request as draft August 11, 2022 12:58
@Keenuts Keenuts removed the request for review from s-perron August 11, 2022 12:58
@s-perron s-perron self-requested a review August 11, 2022 13:21
result->GetMember(components);
return result;
if (!result) {
return nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good change putting this fisrt.

@s-perron s-perron self-requested a review August 11, 2022 13:31
@Keenuts Keenuts force-pushed the fix-4887-alt branch 2 times, most recently from 907d042 to 1d91d65 Compare August 11, 2022 13:59
@Keenuts Keenuts changed the title spirv-opt: prevent creation of unused instructions spirv-opt: fix copy-propagate-arrays index opti on structs. Aug 11, 2022
@Keenuts Keenuts marked this pull request as ready for review August 11, 2022 15:09
Copy-propagate-arrays optimization pass would create unused constants,
even if the optimization not completed.
This was caused by the way we handled OpAccessChain squashing: we
only referenced constants, and had to create them upfront.

Signed-off-by: Nathan Gauër <brioche@google.com>
test/opt/copy_prop_array_test.cpp Show resolved Hide resolved
test/opt/copy_prop_array_test.cpp Show resolved Hide resolved
Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

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

Looks goot. Just a minor nit. The array size in the comment.

test/opt/copy_prop_array_test.cpp Outdated Show resolved Hide resolved
As per SPIR-V spec:
OpAccessChain indices must be OpConstant when indexing into a structure.

This optimization tried to remove load cascade. But in some scenario
failed:

```c
cbuffer MyStruct {
    uint my_field;
};

uint main(uint index) {
    const uint my_array[1] = { my_field };
    return my_array[index]
}
```

This is valid as the struct is indexed with a constant index, and then
the array is indexed using a dynamic index.
The optimization would consider the local array to be useless and
generated a load directly into the struct.

Fixes KhronosGroup#4887

Signed-off-by: Nathan Gauër <brioche@google.com>
@s-perron
Copy link
Collaborator

Looks good, but do not merge until Kokoro runs the presubmits. It seems to be slow today.

@Keenuts
Copy link
Contributor Author

Keenuts commented Aug 15, 2022

Thanks for the review!
Kokoro has finished :) (But I do not have push permissions, so cannot press submit)

@Keenuts Keenuts merged commit 1728c1d into KhronosGroup:master Aug 16, 2022
@Keenuts Keenuts deleted the fix-4887-alt branch August 16, 2022 14:05
@s-perron
Copy link
Collaborator

s-perron commented Aug 16, 2022

I don't think the tests ran. When they run, there are 20 checks. This only has 2.

Edit: I check the continuous build, and it does not look like anything is failing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants