diff options
| author | Jakub Kuderski <kubak@google.com> | 2019-12-20 16:08:52 -0500 |
|---|---|---|
| committer | Jakub Kuderski <kubak@google.com> | 2019-12-20 16:15:04 -0500 |
| commit | c431c407ebcbbb526f4af93a549fa5b260a9b193 (patch) | |
| tree | 9b1d68931a128f68a2288125ccda17f91e92efc9 /llvm/lib/Transforms | |
| parent | 494b1318ca77927e919bbf9a61749a58553d738c (diff) | |
| download | bcm5719-llvm-c431c407ebcbbb526f4af93a549fa5b260a9b193.tar.gz bcm5719-llvm-c431c407ebcbbb526f4af93a549fa5b260a9b193.zip | |
[InstCombine] Improve infinite loop detection
Summary:
This patch limits the default number of iterations performed by InstCombine. It also exposes a new option that allows to specify how many iterations is considered getting stuck in an infinite loop.
Based on experiments performed on real-world C++ programs, InstCombine seems to perform at most ~8-20 iterations, so treating 1000 iterations as an infinite loop seems like a safe choice. See D71145 for details.
The two limits can be specified via command line options.
Reviewers: spatel, lebedev.ri, nikic, xbolva00, grosser
Reviewed By: spatel
Subscribers: hiraditya, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D71673
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstructionCombining.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp index c894a06ed25..d423c38ce5b 100644 --- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp +++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp @@ -122,7 +122,8 @@ STATISTIC(NumReassoc , "Number of reassociations"); DEBUG_COUNTER(VisitCounter, "instcombine-visit", "Controls which instructions are visited"); -static constexpr unsigned InstCombineDefaultMaxIterations = UINT_MAX - 1; +static constexpr unsigned InstCombineDefaultMaxIterations = 1000; +static constexpr unsigned InstCombineDefaultInfiniteLoopThreshold = 1000; static cl::opt<bool> EnableCodeSinking("instcombine-code-sinking", cl::desc("Enable code sinking"), @@ -137,6 +138,12 @@ static cl::opt<unsigned> LimitMaxIterations( cl::desc("Limit the maximum number of instruction combining iterations"), cl::init(InstCombineDefaultMaxIterations)); +static cl::opt<unsigned> InfiniteLoopDetectionThreshold( + "instcombine-infinite-loop-threshold", + cl::desc("Number of instruction combining iterations considered an " + "infinite loop"), + cl::init(InstCombineDefaultInfiniteLoopThreshold), cl::Hidden); + static cl::opt<unsigned> MaxArraySize("instcombine-maxarray-size", cl::init(1024), cl::desc("Maximum array size considered when doing a combine")); @@ -3571,13 +3578,17 @@ static bool combineInstructionsOverFunction( unsigned Iteration = 0; while (true) { ++Iteration; + + if (Iteration > InfiniteLoopDetectionThreshold) { + report_fatal_error( + "Instruction Combining seems stuck in an infinite loop after " + + Twine(InfiniteLoopDetectionThreshold) + " iterations."); + } + if (Iteration > MaxIterations) { LLVM_DEBUG(dbgs() << "\n\n[IC] Iteration limit #" << MaxIterations << " on " << F.getName() << " reached; stopping before reaching a fixpoint\n"); - LLVM_DEBUG(dbgs().flush()); - assert(Iteration <= InstCombineDefaultMaxIterations && - "InstCombine stuck in an infinite loop?"); break; } |

