From 719772c01a8ee8afa81cded249d6a51e33e17d8d Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Fri, 8 Aug 2025 13:07:00 -0700 Subject: 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 Co-authored-by: Claude Co-authored-by: slangbot Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-ir-redundancy-removal.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source') 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( -- cgit v1.2.3