From c7ecf3039d2cc8680f1ea5f4bee2d13521ae34f7 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Thu, 24 Apr 2025 18:44:01 -0400 Subject: Handle case where either side of a conditional branch is empty (#6890) Co-authored-by: Yong He --- source/slang/slang-ir-autodiff-loop-analysis.cpp | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'source/slang') diff --git a/source/slang/slang-ir-autodiff-loop-analysis.cpp b/source/slang/slang-ir-autodiff-loop-analysis.cpp index 137ab7775..b53b014dd 100644 --- a/source/slang/slang-ir-autodiff-loop-analysis.cpp +++ b/source/slang/slang-ir-autodiff-loop-analysis.cpp @@ -707,8 +707,28 @@ StatementSet propagateUpwards( } else { - // Panic - SLANG_UNREACHABLE("Unreachable block in conditional branch"); + // It's possible that the predecessor block is the condition block itself (when + // either the true side or the false side is empty). + // + if (predecessor == ifElse->getParent() && ifElse->getFalseBlock() == current) + { + // True branch + newPredicateSet.conjunct( + tryExtractStatements(ifElse, ifElse->getFalseBlock())); + } + else if ( + predecessor == ifElse->getParent() && ifElse->getTrueBlock() == current) + { + // False branch + newPredicateSet.conjunct( + tryExtractStatements(ifElse, ifElse->getTrueBlock())); + } + else + { + + // Panic + SLANG_UNREACHABLE("Unreachable block in conditional branch"); + } } } } -- cgit v1.2.3