Skip to content

Fix CB vector to scalar array translation generating invalid IR (#6777)#6800

Merged
python3kgae merged 1 commit intomicrosoft:release-1.8.2407from
python3kgae:merge_cbfix
Jul 22, 2024
Merged

Fix CB vector to scalar array translation generating invalid IR (#6777)#6800
python3kgae merged 1 commit intomicrosoft:release-1.8.2407from
python3kgae:merge_cbfix

Conversation

@python3kgae
Copy link
Copy Markdown
Contributor

In the special code to handle the memcpy pattern where a constant buffer contains a vector array that initializes a local (or static global) scalar array for use by the shader, an invalid assumption was made that if the memcpy dest was global, that the src is global as well.

This was not the case, and when expecting to generate constant expressions to index the src, these generated orphaned instructions instead, leading to invalid IR.

This fixes the issue by leveraging ReplaceConstantWithInst, and setting the insertion point for the Builder. Now, replacement could fail, if src instructions don't dominate replacement uses, so bool for replaced all is returned from replaceScalarArrayWithVectorArray.

Another issue was that it would replace the dest for the original memcpy with src along the way. Now, if we don't replace all uses, this turns the memcpy into a no-op and any remaining uses are no longer coming from src, but an undef dest instead. This was also fixed to skip this replacement, then clean up this use if all other uses have been successfully replaced.

Fixes #6510

(cherry picked from commit 5cfefc7)

…osoft#6777)

In the special code to handle the memcpy pattern where a constant buffer
contains a vector array that initializes a local (or static global)
scalar array for use by the shader, an invalid assumption was made that
if the memcpy dest was global, that the src is global as well.

This was not the case, and when expecting to generate constant
expressions to index the src, these generated orphaned instructions
instead, leading to invalid IR.

This fixes the issue by leveraging ReplaceConstantWithInst, and setting
the insertion point for the Builder. Now, replacement *could* fail, if
src instructions don't dominate replacement uses, so bool for replaced
all is returned from replaceScalarArrayWithVectorArray.

Another issue was that it would replace the dest for the original memcpy
with src along the way. Now, if we don't replace all uses, this turns
the memcpy into a no-op and any remaining uses are no longer coming from
src, but an undef dest instead. This was also fixed to skip this
replacement, then clean up this use if all other uses have been
successfully replaced.

Fixes microsoft#6510

(cherry picked from commit 5cfefc7)
@python3kgae python3kgae requested a review from a team as a code owner July 18, 2024 14:32
@python3kgae python3kgae enabled auto-merge (squash) July 18, 2024 20:17
Comment thread lib/Transforms/Scalar/ScalarReplAggregatesHLSL.cpp
@bob80905
Copy link
Copy Markdown
Collaborator

Is there a way to shrink the sizes of the 3 tests?

@python3kgae
Copy link
Copy Markdown
Contributor Author

Is there a way to shrink the sizes of the 3 tests?

We could remove the debug info.
But this is a cherry-pick PR, we should need to change in main and then cherry-pick the test update to release branch.

@python3kgae python3kgae merged commit af9a0ba into microsoft:release-1.8.2407 Jul 22, 2024
@python3kgae python3kgae deleted the merge_cbfix branch July 22, 2024 19:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants