From 10e2d9c7c532c204f26bb2c9f383f21b121b2ff2 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Mon, 27 Feb 2023 23:42:06 -0500 Subject: More fixes for reverse-mode on complicated loops (#2675) * Multiple fixes to get various loop tests to pass. * Create reverse-nested-loop.slang * Fix for variables becoming inaccessible during cfg normalization * Removed comments and moved break-branch-normalization to eliminateMultiLevelBreaks * Fix. * Override liveness tests --- source/slang/slang-ir-loop-unroll.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source/slang/slang-ir-loop-unroll.cpp') diff --git a/source/slang/slang-ir-loop-unroll.cpp b/source/slang/slang-ir-loop-unroll.cpp index 2f689ebde..4f9b8d272 100644 --- a/source/slang/slang-ir-loop-unroll.cpp +++ b/source/slang/slang-ir-loop-unroll.cpp @@ -603,6 +603,16 @@ void eliminateContinueBlocks(IRModule* module, IRLoop* loopInst) builder.setInsertInto(innerBreakableRegionBreakBlock); _moveParams(innerBreakableRegionBreakBlock, continueBlock); builder.emitBranch(continueBlock); + + // If the original loop can be executed up to N times, the new loop may be executed + // upto N+1 times (although most insts are skipped in the last traversal) + // + if (auto maxItersDecoration = loopInst->findDecoration()) + { + auto maxIters = maxItersDecoration->getMaxIters(); + maxItersDecoration->removeAndDeallocate(); + builder.addLoopMaxItersDecoration(loopInst, maxIters + 1); + } } void eliminateContinueBlocksInFunc(IRModule* module, IRGlobalValueWithCode* func) -- cgit v1.2.3