summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorSai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com>2023-09-26 20:50:13 -0400
committerGitHub <noreply@github.com>2023-09-26 17:50:13 -0700
commitc5c8cfbb360d9a763f549df48636effde839eacd (patch)
tree6b055d36e71749d70ace575fc180a23500331b00 /source
parenta18dca27392b257ba2cc58ceabdf15471f34ee25 (diff)
Handle the case where the parent if-else region's after-block is unreachable. (#3241)
Also added a test for this. Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-ir-autodiff-cfg-norm.cpp24
1 files changed, 24 insertions, 0 deletions
diff --git a/source/slang/slang-ir-autodiff-cfg-norm.cpp b/source/slang/slang-ir-autodiff-cfg-norm.cpp
index e7c269756..3602e77ae 100644
--- a/source/slang/slang-ir-autodiff-cfg-norm.cpp
+++ b/source/slang/slang-ir-autodiff-cfg-norm.cpp
@@ -356,6 +356,30 @@ struct CFGNormalizationPass
//
afterBaseRegion = true;
+ // One case we do check for is if the after block is 'unreachable'
+ // i.e. the terminator is an `unreachable` instruction.
+ // In this case, we can safely assume that the after block does not
+ // have anything to execute. Further, we need to re-wire the
+ // previously unreachable block to the parent break block.
+ // Note that this operation is safe because if the after block was
+ // originally unreachable, all potential paths to it must have
+ // broken out of the region.
+ //
+ if (auto unreachInst = as<IRUnreachable>(afterBlock->getTerminator()))
+ {
+ // Link it to the parentAfterBlock.
+ builder.setInsertInto(afterBlock);
+ unreachInst->removeAndDeallocate();
+
+ builder.emitBranch(parentAfterBlock);
+
+ // We can now safely assume that the after block is empty.
+ // Set 'afterBaseRegion' to false, which should lead the rest
+ // of the logic to avoid splitting the after block
+ //
+ afterBaseRegion = false;
+ }
+
// Do we need to split the after region?
if (afterBaseRegion && afterBreakRegion)
{