From 4c9e4de4b68f2612a39e8783e9da89605ecf54e0 Mon Sep 17 00:00:00 2001 From: Yong He Date: Mon, 26 Jun 2023 15:18:06 -0700 Subject: Fix DCE on mutable calls in a loop. (#2943) * Fix DCE on mutable calls in a loop. * More accurate in-loop test. * code review fixes. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-ir.cpp | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'source/slang/slang-ir.cpp') diff --git a/source/slang/slang-ir.cpp b/source/slang/slang-ir.cpp index 0a001892a..cac49f5f7 100644 --- a/source/slang/slang-ir.cpp +++ b/source/slang/slang-ir.cpp @@ -5,6 +5,8 @@ #include "../core/slang-basic.h" +#include "slang-ir-dominators.h" + #include "slang-mangle.h" namespace Slang @@ -4067,6 +4069,20 @@ namespace Slang return module; } + IRDominatorTree* IRModule::findOrCreateDominatorTree(IRGlobalValueWithCode* func) + { + IRAnalysis* analysis = m_mapInstToAnalysis.tryGetValue(func); + if (analysis) + return analysis->getDominatorTree(); + else + { + m_mapInstToAnalysis[func] = IRAnalysis(); + analysis = m_mapInstToAnalysis.tryGetValue(func); + } + analysis->domTree = computeDominatorTree(func); + return analysis->getDominatorTree(); + } + void addGlobalValue( IRBuilder* builder, IRInst* value) @@ -7082,6 +7098,8 @@ namespace Slang module->getDeduplicationContext()->getConstantMap().remove(IRConstantKey{ constInst }); } module->getDeduplicationContext()->getInstReplacementMap().remove(this); + if (auto func = as(this)) + module->invalidateAnalysisForInst(func); } removeArguments(); removeFromParent(); @@ -7153,10 +7171,6 @@ namespace Slang // common subexpression elimination, etc. // auto call = cast(this); - // If the call has been marked as no-side-effect, we - // will treat it so, by-passing all other checks. - if (call->findDecoration()) - return false; return !isSideEffectFreeFunctionalCall(call); } break; @@ -7610,6 +7624,11 @@ namespace Slang return inst; } + IRDominatorTree* IRAnalysis::getDominatorTree() + { + return static_cast(domTree.get()); + } + } // namespace Slang #if SLANG_VC -- cgit v1.2.3