diff options
| author | Yong He <yonghe@outlook.com> | 2023-03-23 16:59:02 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-23 16:59:02 -0700 |
| commit | 50e7d9797d9bf4b98a056d5df128c24dde6e78bd (patch) | |
| tree | 3e6e4491b1b6512280adff1d69a93ccaf50f6bb3 /source/slang/slang-ir-ssa-simplification.cpp | |
| parent | 85f005888cadeb4b1d957b57a86cbad6cc9ea313 (diff) | |
Fix optimization pass not converging. (#2725)
* Fix optimization pass not converging.
* Fix.
* Fix tests.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-ssa-simplification.cpp')
| -rw-r--r-- | source/slang/slang-ir-ssa-simplification.cpp | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/source/slang/slang-ir-ssa-simplification.cpp b/source/slang/slang-ir-ssa-simplification.cpp index a0acf5082..e6c6e353f 100644 --- a/source/slang/slang-ir-ssa-simplification.cpp +++ b/source/slang/slang-ir-ssa-simplification.cpp @@ -20,26 +20,45 @@ namespace Slang { bool changed = true; const int kMaxIterations = 8; + const int kMaxFuncIterations = 16; int iterationCounter = 0; + while (changed && iterationCounter < kMaxIterations) { changed = false; changed |= hoistConstants(module); changed |= deduplicateGenericChildren(module); - changed |= applySparseConditionalConstantPropagation(module); + changed |= propagateFuncProperties(module); + changed |= removeUnusedGenericParam(module); + changed |= applySparseConditionalConstantPropagationForGlobalScope(module); changed |= peepholeOptimize(module); - changed |= removeRedundancy(module); - changed |= simplifyCFG(module); + + for (auto inst : module->getGlobalInsts()) + { + auto func = as<IRGlobalValueWithCode>(inst); + if (!func) + continue; + bool funcChanged = true; + int funcIterationCount = 0; + while (funcChanged && funcIterationCount < kMaxFuncIterations) + { + funcChanged = false; + funcChanged |= applySparseConditionalConstantPropagation(func); + funcChanged |= peepholeOptimize(func); + funcChanged |= removeRedundancyInFunc(func); + funcChanged |= simplifyCFG(func); + eliminateDeadCode(func); + funcChanged |= constructSSA(func); + changed |= funcChanged; + funcIterationCount++; + } + } // 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); - changed |= propagateFuncProperties(module); - - changed |= constructSSA(module); - changed |= removeUnusedGenericParam(module); iterationCounter++; } } |
