[llvm] a9b0776 - [SimplifyCFG] Sanity assert in iterativelySimplifyCFG

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 25 03:10:25 PDT 2021


Author: Max Kazantsev
Date: 2021-10-25T17:10:17+07:00
New Revision: a9b0776a81e84d8042716863842fe1f8adf39cad

URL: https://github.com/llvm/llvm-project/commit/a9b0776a81e84d8042716863842fe1f8adf39cad
DIFF: https://github.com/llvm/llvm-project/commit/a9b0776a81e84d8042716863842fe1f8adf39cad.diff

LOG: [SimplifyCFG] Sanity assert in iterativelySimplifyCFG

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.

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
index c499d51a39146..86d3620c312ec 100644
--- a/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
+++ b/llvm/lib/Transforms/Scalar/SimplifyCFGPass.cpp
@@ -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.


        


More information about the llvm-commits mailing list