diff options
| author | ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> | 2025-08-08 13:07:00 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-08 20:07:00 +0000 |
| commit | 719772c01a8ee8afa81cded249d6a51e33e17d8d (patch) | |
| tree | 2bbee35f93dafb452589466f3535da54a49c1501 /source/slang | |
| parent | 5d1ba37be64980d80e5106f8664a654d907ebaf4 (diff) | |
Initial copy elision pass regression fix (#8126)
when we have `GetElementPtr -> load -> GetElement` in our use-chain, the
final `GetElement` may use the `load` as a `Index`, not a base.
This is a non-issue with `getFieldExtract` since a field is a StructKey.
We will still add this check to ensure no bugs down the line.
---------
Co-authored-by: Harsh Aggarwal <haaggarwal@nvidia.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: slangbot <ellieh+slangbot@nvidia.com>
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Diffstat (limited to 'source/slang')
| -rw-r--r-- | source/slang/slang-ir-redundancy-removal.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/source/slang/slang-ir-redundancy-removal.cpp b/source/slang/slang-ir-redundancy-removal.cpp index 1feab47dd..c52ab7bca 100644 --- a/source/slang/slang-ir-redundancy-removal.cpp +++ b/source/slang/slang-ir-redundancy-removal.cpp @@ -446,6 +446,11 @@ bool eliminateRedundantLoadStore(IRGlobalValueWithCode* func) load, [&](IRGetElement* getElement) { + // Only optimize if the load + // is the base + if (getElement->getBase() != load) + return; + IRBuilder builder(getElement); builder.setInsertBefore(getElement); auto newGetElementPtr = builder.emitElementAddress( @@ -476,6 +481,15 @@ bool eliminateRedundantLoadStore(IRGlobalValueWithCode* func) load, [&](IRFieldExtract* fieldExtract) { + // Only optimize if the load + // is the base; not strictly + // needed for field extract, + // but it will prevent future + // regressions if a field ever + // becomes a non-struct-key + if (fieldExtract->getBase() != load) + return; + IRBuilder builder(fieldExtract); builder.setInsertBefore(fieldExtract); auto newGetFieldAddress = builder.emitFieldAddress( |
