[llvm] r310638 - [InstCombine] Add a DEBUG_COUNTER to InstCombine to limit how many instructions are visited for debug

Craig Topper via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 10 10:48:13 PDT 2017

Author: ctopper
Date: Thu Aug 10 10:48:12 2017
New Revision: 310638

URL: http://llvm.org/viewvc/llvm-project?rev=310638&view=rev
[InstCombine] Add a DEBUG_COUNTER to InstCombine to limit how many instructions are visited for debug

Sometimes it would be nice to stop InstCombine mid way through its combining to see the current IR. By using a debug counter we can place an upper limit on how many instructions to process.

This will also allow skipping the first X combines, but that has the potential to change later combines since earlier canonicalizations might have been skipped.

Differential Revision: https://reviews.llvm.org/D36553


Modified: llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp?rev=310638&r1=310637&r2=310638&view=diff
--- llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstructionCombining.cpp Thu Aug 10 10:48:12 2017
@@ -60,6 +60,7 @@
 #include "llvm/IR/ValueHandle.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/DebugCounter.h"
 #include "llvm/Support/KnownBits.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Transforms/InstCombine/InstCombine.h"
@@ -79,6 +80,8 @@ STATISTIC(NumSunkInst , "Number of instr
 STATISTIC(NumExpand,    "Number of expansions");
 STATISTIC(NumFactor   , "Number of factorizations");
 STATISTIC(NumReassoc  , "Number of reassociations");
+DEBUG_COUNTER(VisitCounter, "instcombine-visit",
+              "Controls which instructions are visited");
 static cl::opt<bool>
@@ -2882,6 +2885,9 @@ bool InstCombiner::run() {
+    if (!DebugCounter::shouldExecute(VisitCounter))
+      continue;
     // Instruction isn't dead, see if we can constant propagate it.
     if (!I->use_empty() &&
         (I->getNumOperands() == 0 || isa<Constant>(I->getOperand(0)))) {

More information about the llvm-commits mailing list