From c701ec00ccce6dfa8094d6550ce2db929fc8cefe Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 1 Jul 2025 19:09:29 -0700 Subject: Defer immutable buffer loads when emitting spirv. (#7579) * Defer immutable buffer loads when emitting spirv. * Fix. * Fix. * Fix. * Fix tests. * Fix test. --- source/slang/slang-ir-specialize-function-call.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-ir-specialize-function-call.cpp') diff --git a/source/slang/slang-ir-specialize-function-call.cpp b/source/slang/slang-ir-specialize-function-call.cpp index 7a9fc5f6f..c03e644de 100644 --- a/source/slang/slang-ir-specialize-function-call.cpp +++ b/source/slang/slang-ir-specialize-function-call.cpp @@ -338,7 +338,9 @@ struct FunctionParameterSpecializationContext // correctly check the preconditions. // auto oldFunc = as(oldCall->getCallee()); - SLANG_ASSERT(oldFunc); + if (!oldFunc) + return; + SLANG_ASSERT(oldFunc->isDefinition()); // Our first information-gathering pass will @@ -390,6 +392,14 @@ struct FunctionParameterSpecializationContext newCall->insertBefore(oldCall); oldCall->replaceUsesWith(newCall); oldCall->removeAndDeallocate(); + + // If old func is no longer used after the specialization, + // remove it. + if (!oldFunc->hasUses()) + { + if (!shouldInstBeLiveIfParentIsLive(oldFunc, IRDeadCodeEliminationOptions{})) + oldFunc->removeAndDeallocate(); + } } // Before diving into the details on how we gather information -- cgit v1.2.3