[SimplifyCFG] Sanity assert in iterativelySimplifyCFG
authorMax Kazantsev <mkazantsev@azul.com>
Mon, 25 Oct 2021 09:43:11 +0000 (16:43 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Mon, 25 Oct 2021 10:10:17 +0000 (17:10 +0700)
We observe a hang within iterativelySimplifyCFG due to infinite
loop execution. Currently, there is no limit to this loop, so
in case of bug it just works forever. This patch adds an assert
that will break it after 1000 iterations if it didn't converge.

llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp

index c499d51..86d3620 100644 (file)
@@ -224,7 +224,11 @@ static bool iterativelySimplifyCFG(Function &F, const TargetTransformInfo &TTI,
   SmallVector<WeakVH, 16> LoopHeaders(UniqueLoopHeaders.begin(),
                                       UniqueLoopHeaders.end());
 
+  unsigned IterCnt = 0;
+  (void)IterCnt;
   while (LocalChange) {
+    assert(IterCnt++ < 1000 &&
+           "Sanity: iterative simplification didn't converge!");
     LocalChange = false;
 
     // Loop over all of the basic blocks and remove them if they are unneeded.