]> granicus.if.org Git - llvm/commitdiff
NewGVN: Add debug counter for value numbering
authorDaniel Berlin <dberlin@dberlin.org>
Wed, 1 Mar 2017 19:59:26 +0000 (19:59 +0000)
committerDaniel Berlin <dberlin@dberlin.org>
Wed, 1 Mar 2017 19:59:26 +0000 (19:59 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296665 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/NewGVN.cpp
test/Other/debugcounter-newgvn.ll [new file with mode: 0644]
test/Other/debugcounter-predicateinfo.ll [moved from test/Other/debugcounter.ll with 99% similarity]

index b7914ba54bdc5d6466d346cbb3e285d0b8088b97..6c4ee6eafb8b777a9c31ad993e226dd3ee11014c 100644 (file)
@@ -76,6 +76,7 @@
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Debug.h"
+#include "llvm/Support/DebugCounter.h"
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/Transforms/Scalar/GVNExpression.h"
 #include "llvm/Transforms/Utils/BasicBlockUtils.h"
@@ -103,7 +104,8 @@ STATISTIC(NumGVNAvoidedSortedLeaderChanges,
 STATISTIC(NumGVNNotMostDominatingLeader,
           "Number of times a member dominated it's new classes' leader");
 STATISTIC(NumGVNDeadStores, "Number of redundant/dead stores eliminated");
-
+DEBUG_COUNTER(VNCounter, "newgvn-vn",
+              "Controls which instructions are value numbered")
 //===----------------------------------------------------------------------===//
 //                                GVN Pass
 //===----------------------------------------------------------------------===//
@@ -287,6 +289,8 @@ class NewGVN : public FunctionPass {
   // Deletion info.
   SmallPtrSet<Instruction *, 8> InstructionsToErase;
 
+  // The set of things we gave unknown expressions to due to debug counting.
+  SmallPtrSet<Instruction *, 8> DebugUnknownExprs;
 public:
   static char ID; // Pass identification, replacement for typeid.
   NewGVN() : FunctionPass(ID) {
@@ -1708,13 +1712,13 @@ void NewGVN::cleanupTables() {
 #endif
   InstrDFS.clear();
   InstructionsToErase.clear();
-
   DFSToInstr.clear();
   BlockInstRange.clear();
   TouchedInstructions.clear();
   DominatedInstRange.clear();
   MemoryAccessToClass.clear();
   PredicateToUsers.clear();
+  DebugUnknownExprs.clear();
 }
 
 std::pair<unsigned, unsigned> NewGVN::assignDFSNumbers(BasicBlock *B,
@@ -1796,7 +1800,6 @@ void NewGVN::valueNumberMemoryPhi(MemoryPhi *MP) {
 // congruence finding, and updating mappings.
 void NewGVN::valueNumberInstruction(Instruction *I) {
   DEBUG(dbgs() << "Processing instruction " << *I << "\n");
-
   // There's no need to call isInstructionTriviallyDead more than once on
   // an instruction. Therefore, once we know that an instruction is dead
   // we change its DFS number so that it doesn't get numbered again.
@@ -1807,7 +1810,14 @@ void NewGVN::valueNumberInstruction(Instruction *I) {
     return;
   }
   if (!I->isTerminator()) {
-    const auto *Symbolized = performSymbolicEvaluation(I);
+    const Expression *Symbolized = nullptr;
+    if (DebugCounter::shouldExecute(VNCounter)) {
+      Symbolized = performSymbolicEvaluation(I);
+    } else {
+      // Used to track which we marked unknown so we can skip verification of
+      // comparisons.
+      DebugUnknownExprs.insert(I);
+    }
     // If we couldn't come up with a symbolic expression, use the unknown
     // expression
     if (Symbolized == nullptr)
@@ -1923,7 +1933,7 @@ void NewGVN::verifyComparisons(Function &F) {
     if (!ReachableBlocks.count(&BB))
       continue;
     for (auto &I : BB) {
-      if (InstructionsToErase.count(&I))
+      if (InstructionsToErase.count(&I) || DebugUnknownExprs.count(&I))
         continue;
       if (isa<CmpInst>(&I)) {
         auto *CurrentVal = ValueToClass.lookup(&I);
diff --git a/test/Other/debugcounter-newgvn.ll b/test/Other/debugcounter-newgvn.ll
new file mode 100644 (file)
index 0000000..cfe043c
--- /dev/null
@@ -0,0 +1,22 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; REQUIRES: asserts
+; RUN: opt -S -debug-counter=newgvn-vn-skip=1,newgvn-vn-count=2 -newgvn  < %s 2>&1 | FileCheck %s
+;; Test that, with debug counters on, we don't value number the first instruction, only the second and third,
+;; which means we do not discover the return is constant.
+define i32 @vntest() {
+; CHECK-LABEL: @vntest(
+; CHECK-NEXT:  bb:
+; CHECK-NEXT:    [[A:%.*]] = add i32 1, 3
+; CHECK-NEXT:    [[D:%.*]] = add i32 8, 8
+; CHECK-NEXT:    ret i32 [[D]]
+;
+bb:
+  %a = add i32 1, 3
+  %b = add i32 %a, %a
+  %c = add i32 %a, %a
+  %d = add i32 %b, %c
+  ret i32 %d
+}
+
+
+
similarity index 99%
rename from test/Other/debugcounter.ll
rename to test/Other/debugcounter-predicateinfo.ll
index d9ab9abd73fb6f970d41c3e1f3ca155f8b24b752..eb2ec09802fedce589f282c188a3a57169b6c5be 100644 (file)
@@ -1,7 +1,7 @@
-; REQUIRES: asserts
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
-;; Test that, with debug counters on, we don't rename the first info, only the second
+; REQUIRES: asserts
 ; RUN: opt -debug-counter=predicateinfo-rename-skip=1,predicateinfo-rename-count=1 -print-predicateinfo -analyze  < %s 2>&1 | FileCheck %s
+;; Test that, with debug counters on, we don't rename the first info, only the second
 define fastcc void @barney() {
 ; CHECK-LABEL: @barney(
 ; CHECK-NEXT:  bb:
@@ -37,4 +37,3 @@ bb33:                                             ; preds = %bb31
 bb35:                                             ; preds = %bb33, %bb29, %bb22
   unreachable
 }
-