summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-ir-remove-unused-generic-param.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-ir-remove-unused-generic-param.cpp')
-rw-r--r--source/slang/slang-ir-remove-unused-generic-param.cpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/source/slang/slang-ir-remove-unused-generic-param.cpp b/source/slang/slang-ir-remove-unused-generic-param.cpp
index dd4efeddd..c79e236b8 100644
--- a/source/slang/slang-ir-remove-unused-generic-param.cpp
+++ b/source/slang/slang-ir-remove-unused-generic-param.cpp
@@ -72,17 +72,38 @@ struct RemoveUnusedGenericParamContext : InstPassBase
child = next;
}
SLANG_ASSERT(returnVal);
- List<IRUse*> uses;
+
+ // Collect all specialize uses that we might optimize
+ List<IRUse*> specializeUses;
for (auto use = genInst->firstUse; use; use = use->nextUse)
- uses.add(use);
- for (auto use : uses)
{
if (use->getUser()->getOp() == kIROp_Specialize &&
use == use->getUser()->getOperands())
{
- use->getUser()->replaceUsesWith(returnVal);
+ specializeUses.add(use);
+ }
+ }
+
+ // Check if any of these specialize uses are used by witness tables
+ // If so, we cannot apply the optimization because witness tables are immutable
+ for (auto use : specializeUses)
+ {
+ for (auto specializeUse = use->getUser()->firstUse; specializeUse;
+ specializeUse = specializeUse->nextUse)
+ {
+ auto userOp = specializeUse->getUser()->getOp();
+ if (userOp == kIROp_WitnessTable)
+ {
+ goto skipOptimization;
+ }
}
}
+
+ // Apply the optimization: replace all specialize uses with the return value
+ for (auto use : specializeUses)
+ {
+ use->getUser()->replaceUsesWith(returnVal);
+ }
genInst->replaceUsesWith(returnVal);
genInst->removeAndDeallocate();
}
@@ -118,6 +139,7 @@ struct RemoveUnusedGenericParamContext : InstPassBase
for (auto param : paramsToRemove)
param->removeAndDeallocate();
}
+ skipOptimization:;
}
}
return changed;