-
Notifications
You must be signed in to change notification settings - Fork 597
[OPT] prevent private_to_local_pass optimizing double pointer #6161
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
Conversation
Fixes KhronosGroup#6156 before this fix the pass will optimize the following code: ``` %v = OpVariable %_ptr_Private_uint Private %uint_0 %load_thread_local = OpFunction %void None %function_type__1561_ %37 = OpLabel %31 = OpVariable %_ptr_Function__ptr_Private_uint Function %32 = OpVariable %_ptr_Function_uint Function %33 = OpVariable %_ptr_Function_uint Function OpStore %31 %v %34 = OpLoad %_ptr_Private_uint %31 %35 = OpLoad %uint %34 OpStore %32 %35 %36 = OpLoad %uint %v OpStore %33 %36 OpReturn OpFunctionEnd ``` to this: ``` %load_thread_local = OpFunction %void None %function_type__1561_ %37 = OpLabel %v = OpVariable %_ptr_Function_uint Function %uint_0 %31 = OpVariable %_ptr_Function__ptr_Private_uint Function %32 = OpVariable %_ptr_Function_uint Function %33 = OpVariable %_ptr_Function_uint Function OpStore %31 %v OpStore %32 %uint_0 OpStore %33 %uint_0 OpReturn OpFunctionEnd ``` resulting in the following error: ``` error: line 81: OpStore Pointer <id> '31[%31]'s type does not match Object <id> '47[%v]'s type. OpStore %31 %v ``` private_to_local_pass does not update the storage class of the double pointer %31 correctly. It currently doesn't have enough context to tell if %31 is later loaded from and used to store with. For now, just prevent the optimization if the address of the private variable is used as the object operand of the OpStore instruction. with this commit, the spirv code is optimized to this: ``` %v = OpVariable %_ptr_Private_uint Private %uint_0 %load_thread_local = OpFunction %void None %function_type__1561_ %37 = OpLabel %31 = OpVariable %_ptr_Function__ptr_Private_uint Function %32 = OpVariable %_ptr_Function_uint Function %33 = OpVariable %_ptr_Function_uint Function OpStore %31 %v %35 = OpLoad %uint %v OpStore %32 %35 %36 = OpLoad %uint %v OpStore %33 %36 OpReturn OpFunctionEnd ```
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.
The changes to the code look good. It just needs a test. Here is an example you can follow.
I don't know why the tests failed with the previous code. Before when I made the test, I locally assembled the binary with spirv-as and done an spirv-opt & spirv-val over it but i guess i had to configured the tests to be more aggressive or something? |
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.
The test looks good now. I think you were doing a Match test with not checks in the source. I think that will fail.
Fixes #6156
before this fix the pass will optimize the following code:
to this:
resulting in the following error:
private_to_local_pass does not update the storage class of the double pointer %31 correctly. It currently doesn't have enough context to tell if %31 is later loaded from and used to store with. For now, just prevent the optimization if the address of the private variable is used as the object operand of the OpStore instruction.
with this commit, the spirv code is optimized to this: