diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-04-21 19:48:29 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-21 09:48:29 -0700 |
| commit | 0f6ba14765bf19464a2d05fc02f596b9db6c7025 (patch) | |
| tree | 50b536c603a1c3fb63842cf211cd488b89bc580a /source | |
| parent | 043278a527ab5744674417a08d924c67a60a486b (diff) | |
Allow simplifying self-referential Phi parameters (#6870)
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-ir-simplify-cfg.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/source/slang/slang-ir-simplify-cfg.cpp b/source/slang/slang-ir-simplify-cfg.cpp index 280874f74..2310a5cce 100644 --- a/source/slang/slang-ir-simplify-cfg.cpp +++ b/source/slang/slang-ir-simplify-cfg.cpp @@ -728,9 +728,9 @@ static bool simplifyBoolPhiParams(IRBlock* block) static bool removeTrivialPhiParams(IRBlock* block) { - // We can remove a phi parmeter if: - // 1. all arguments to a parameter is the same (not really a phi). - // 2. the arguments to the parameter is always the same as arguments to another existing + // We can remove a phi parameter if: + // 1. all non-self-referential arguments to a parameter are the same (not really a phi). + // 2. the arguments to the parameter are always the same as arguments to another existing // parameter (duplicate phi). bool changed = false; @@ -765,7 +765,10 @@ static bool removeTrivialPhiParams(IRBlock* block) termInsts.add(termInst); for (UInt i = 0; i < termInst->getArgCount(); i++) { - if (args[i].areKnownValueSame) + // Self-referential parameters can be skipped, as they cannot + // introduce a new value. The phi can only have multiple different + // values if non-self-referential arguments differ. + if (args[i].areKnownValueSame && termInst->getArg(i) != params[i]) { if (args[i].knownValue == nullptr) args[i].knownValue = termInst->getArg(i); |
