summaryrefslogtreecommitdiff
path: root/source/slang/slang-ir-transform-params-to-constref.cpp
diff options
context:
space:
mode:
authorJay Kwak <82421531+jkwak-work@users.noreply.github.com>2025-09-23 23:47:30 -0700
committerGitHub <noreply@github.com>2025-09-24 06:47:30 +0000
commit9c2024a7509baae921083d49a56e1321c51f00ec (patch)
tree1f66721d16ee032893418b8ef4f7e23a1714c034 /source/slang/slang-ir-transform-params-to-constref.cpp
parent979e16a34ef9ff2806476b809e2dcba5a96c40d4 (diff)
Remove unnecessary Load and Store pair (#8433)
This commit removes unnecessary Load and Store pairs in IR. When the IR is like ``` let %1 = var let %2 = load(%ptr) store(%1 %2) ``` This PR will replace all uses of %1 with %ptr. And the load and store instructions will be removed. But I found that there can be cases where %2 might be still used later in other IRs. For these cases, the removal of load instruction relies on DCE. --------- Co-authored-by: slangbot <ellieh+slangbot@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-transform-params-to-constref.cpp')
-rw-r--r--source/slang/slang-ir-transform-params-to-constref.cpp17
1 files changed, 4 insertions, 13 deletions
diff --git a/source/slang/slang-ir-transform-params-to-constref.cpp b/source/slang/slang-ir-transform-params-to-constref.cpp
index 8f4bcd037..9328a1de1 100644
--- a/source/slang/slang-ir-transform-params-to-constref.cpp
+++ b/source/slang/slang-ir-transform-params-to-constref.cpp
@@ -60,7 +60,7 @@ struct TransformParamsToConstRefContext
case kIROp_FieldExtract:
{
// Transform the IRFieldExtract into a IRFieldAddress
- auto fieldExtract = as<IRFieldExtract>(use->getUser());
+ auto fieldExtract = as<IRFieldExtract>(user);
builder.setInsertBefore(fieldExtract);
auto fieldAddr = builder.emitFieldAddress(
fieldExtract->getBase(),
@@ -73,8 +73,7 @@ struct TransformParamsToConstRefContext
case kIROp_GetElement:
{
// Transform the IRGetElement into a IRGetElementPtr
- auto getElement = as<IRGetElement>(use->getUser());
-
+ auto getElement = as<IRGetElement>(user);
builder.setInsertBefore(getElement);
auto elemAddr = builder.emitElementAddress(
getElement->getBase(),
@@ -111,14 +110,8 @@ struct TransformParamsToConstRefContext
List<IRInst*> newArgs;
// Transform arguments to match the updated-parameter
- IRParam* param = func->getFirstParam();
UInt i = 0;
- auto iterate = [&]()
- {
- param = param->getNextParam();
- i++;
- };
- for (; param; iterate())
+ for (IRParam* param = func->getFirstParam(); param; param = param->getNextParam(), i++)
{
auto arg = call->getArg(i);
if (!updatedParams.contains(param))
@@ -183,7 +176,6 @@ struct TransformParamsToConstRefContext
void processFunc(IRFunc* func)
{
HashSet<IRParam*> updatedParams;
- bool hasTransformedParams = false;
// First pass: Transform parameter types
for (auto param = func->getFirstParam(); param; param = param->getNextParam())
@@ -203,13 +195,12 @@ struct TransformParamsToConstRefContext
auto constRefType = builder.getConstRefType(paramType, AddressSpace::ThreadLocal);
param->setFullType(constRefType);
- hasTransformedParams = true;
changed = true;
updatedParams.add(param);
}
}
- if (!hasTransformedParams)
+ if (updatedParams.getCount() == 0)
{
return;
}