[llvm] 5f7a535 - [SCEV] Cap the number of instructions scanned when infering flags

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 3 16:16:01 PDT 2021


Author: Philip Reames
Date: 2021-10-03T16:14:06-07:00
New Revision: 5f7a5353301b776ffb0e5fb048992898507bf7ee

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

LOG: [SCEV] Cap the number of instructions scanned when infering flags

This addresses a comment from review on D109845.  The concern was raised that an unbounded scan would be expensive.  Long term plan is to cache this search - likely reusing the existing mechanism for loop side effects - but let's be simple and conservative for now.

Added: 
    

Modified: 
    llvm/lib/Analysis/ScalarEvolution.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index f9d7ff2ca276..b51e8a74fdd5 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -6597,9 +6597,19 @@ const Instruction *ScalarEvolution::getDefiningScopeBound(const SCEV *S) {
 static bool
 isGuaranteedToTransferExecutionToSuccessor(BasicBlock::const_iterator Begin,
                                            BasicBlock::const_iterator End) {
-  return llvm::all_of( make_range(Begin, End), [](const Instruction &I) {
-    return isGuaranteedToTransferExecutionToSuccessor(&I);
-  });
+  // Limit number of instructions we look at, to avoid scanning through large
+  // blocks. The current limit is chosen arbitrarily.
+  unsigned ScanLimit = 32;
+  for (const Instruction &I : make_range(Begin, End)) {
+    if (isa<DbgInfoIntrinsic>(I))
+        continue;
+    if (--ScanLimit == 0)
+      return false;
+
+    if (!isGuaranteedToTransferExecutionToSuccessor(&I))
+      return false;
+  }
+  return true;
 }
 
 bool ScalarEvolution::isGuaranteedToTransferExecutionTo(const Instruction *A,


        


More information about the llvm-commits mailing list