diff options
| author | Yong He <yonghe@outlook.com> | 2023-03-16 23:46:14 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-16 23:46:14 -0700 |
| commit | 9476d4543f4336a66308e55f722b0b0b2bd69dd2 (patch) | |
| tree | ff3a0514249f5c3975177bf053c5cb038e37acc8 /source/slang/slang-ir-peephole.cpp | |
| parent | 77d3630eef4ea1c4b0424a46526a6be476a89230 (diff) | |
Fix Phi simplification bug. (#2710)
* Fix Phi simplification bug.
* Fix up.
* Fix.
* Fix.
* Fix.
* Fix.
* Fix.
* Fix test.
* Fix test.
---------
Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-ir-peephole.cpp')
| -rw-r--r-- | source/slang/slang-ir-peephole.cpp | 38 |
1 files changed, 34 insertions, 4 deletions
diff --git a/source/slang/slang-ir-peephole.cpp b/source/slang/slang-ir-peephole.cpp index 5d5a41726..65b5d2f45 100644 --- a/source/slang/slang-ir-peephole.cpp +++ b/source/slang/slang-ir-peephole.cpp @@ -1,6 +1,8 @@ #include "slang-ir-peephole.h" #include "slang-ir-inst-pass-base.h" #include "slang-ir-sccp.h" +#include "slang-ir-dominators.h" +#include "slang-ir-util.h" namespace Slang { @@ -290,6 +292,9 @@ struct PeepholeContext : InstPassBase return false; } + RefPtr<IRDominatorTree> domTree; + IRGlobalValueWithCode* domTreeFunc = nullptr; + void processInst(IRInst* inst) { if (as<IRGlobalValueWithCode>(inst)) @@ -679,9 +684,35 @@ struct PeepholeContext : InstPassBase { if (inst->hasUses()) { - inst->replaceUsesWith(argValue); - // Never remove param inst. - changed = true; + // Is argValue a global constant? + if (isChildInstOf(inst, argValue->getParent())) + { + inst->replaceUsesWith(argValue); + // Never remove param inst. + changed = true; + } + else + { + // If argValue is defined locally, + // we can replace only if argVal dominates inst. + auto parentFunc = getParentFunc(inst); + if (!parentFunc) + break; + if (domTreeFunc != parentFunc) + { + domTree = computeDominatorTree(parentFunc); + domTreeFunc = parentFunc; + } + if (!domTree) + break; + + if (domTree->dominates(argValue, inst)) + { + inst->replaceUsesWith(argValue); + // Never remove param inst. + changed = true; + } + } } } } @@ -694,7 +725,6 @@ struct PeepholeContext : InstPassBase bool processFunc(IRInst* func) { bool result = false; - for (;;) { changed = false; |
