From bd6306cdaa4a49344658bd026721b6532e103d09 Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 24 Feb 2023 10:01:47 -0800 Subject: More control flow simplifications. (#2673) * More control flow and Phi param simplifications. * Fix. * Fix gcc error. * Fix. * More IR cleanup. * Fix bug in phi param dce + ifelse simplify. * Propagate and DCE side-effect-free functions. * Enhance CFG simplifcation to remove loops with no side effects. * Fix. * Fixes. * Fix tests. Add [__AlwaysFoldIntoUseSite] for rayPayloadLocation. * More cleanup. * Fixes. * Fix. --------- Co-authored-by: Yong He --- source/slang/slang-ir-ssa-simplification.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'source/slang/slang-ir-ssa-simplification.cpp') diff --git a/source/slang/slang-ir-ssa-simplification.cpp b/source/slang/slang-ir-ssa-simplification.cpp index f06fafcb3..beaaae065 100644 --- a/source/slang/slang-ir-ssa-simplification.cpp +++ b/source/slang/slang-ir-ssa-simplification.cpp @@ -10,6 +10,7 @@ #include "slang-ir-deduplicate-generic-children.h" #include "slang-ir-remove-unused-generic-param.h" #include "slang-ir-redundancy-removal.h" +#include "slang-ir-propagate-func-properties.h" namespace Slang { @@ -29,6 +30,7 @@ namespace Slang changed |= peepholeOptimize(module); changed |= removeRedundancy(module); changed |= simplifyCFG(module); + changed |= propagateFuncProperties(module); // Note: we disregard the `changed` state from dead code elimination pass since // SCCP pass could be generating temporarily evaluated constant values and never actually use them. @@ -41,6 +43,28 @@ namespace Slang } } + void simplifyNonSSAIR(IRModule* module) + { + bool changed = true; + const int kMaxIterations = 8; + int iterationCounter = 0; + while (changed && iterationCounter < kMaxIterations) + { + changed = false; + changed |= peepholeOptimize(module); + changed |= removeRedundancy(module); + changed |= simplifyCFG(module); + + // Note: we disregard the `changed` state from dead code elimination pass since + // SCCP pass could be generating temporarily evaluated constant values and never actually use them. + // DCE will always remove those nearly generated consts and always returns true here. + eliminateDeadCode(module); + + iterationCounter++; + } + } + + void simplifyFunc(IRGlobalValueWithCode* func) { bool changed = true; -- cgit v1.2.3