From 0f6ba14765bf19464a2d05fc02f596b9db6c7025 Mon Sep 17 00:00:00 2001 From: Julius Ikkala Date: Mon, 21 Apr 2025 19:48:29 +0300 Subject: Allow simplifying self-referential Phi parameters (#6870) --- source/slang/slang-ir-simplify-cfg.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source') 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); -- cgit v1.2.3