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

Fix sroa replace constant with non constant in entry block #6591

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

pow2clk
Copy link
Member

@pow2clk pow2clk commented May 6, 2024

A variation on #6556 that I'm not sure generates the right code just yet. The first commit slurps up the tests from #6556. The HLSL test passes without crashing, this change preserves the memcpy replacement so the .ll test doesn't pass. The concern is with the resulting copy seeming to be pointless.

amaiorano and others added 3 commits April 24, 2024 14:18
ReplaceConstantWithInst(C, V) replaces uses of C in the current function with V.
If such a use C is an instruction I, the it replaces uses of C in I with V.
However, this function did not make sure to only perform this replacement if V
dominates I. As a result, it may end up replacing uses of C in instructions
before the definition of V.

The fix is to lazily compute the dominator tree in ReplaceConstantWithInst so
that we can guard the replacement with that dominance check.
In order to replace memcpy instances, sometimes constants need to be
replaced with instructions. Rather than place them wherever is
immediately convenient, placing them in the entry block after the
allocas ensures they have access to the allocas while making sure they
dominate any uses, increasing the chances that the associated memcpy can
be replaced rather than potentially introducing a domination issue that
would prevent the memcpy replace.
We try to keep the allocas at the top of the entry block. This
initialization code placed the init instruction just after the alloca it
was initializing, which left it in the middle of the allocas. This
disrupted future attempts to find the end of the allocas and potentially
put instructions referencing allocas before the relevant alloca.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: New
Development

Successfully merging this pull request may close these issues.

2 participants