[llvm] r296665 - NewGVN: Add debug counter for value numbering

Daniel Berlin via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 1 11:59:26 PST 2017


Author: dannyb
Date: Wed Mar  1 13:59:26 2017
New Revision: 296665

URL: http://llvm.org/viewvc/llvm-project?rev=296665&view=rev
Log:
NewGVN: Add debug counter for value numbering

Added:
    llvm/trunk/test/Other/debugcounter-newgvn.ll
    llvm/trunk/test/Other/debugcounter-predicateinfo.ll
      - copied, changed from r296569, llvm/trunk/test/Other/debugcounter.ll
Removed:
    llvm/trunk/test/Other/debugcounter.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=296665&r1=296664&r2=296665&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Wed Mar  1 13:59:26 2017
@@ -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(NumGVNAvoidedSortedLeaderChang
 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(Memory
 // 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(Inst
     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
     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);

Added: llvm/trunk/test/Other/debugcounter-newgvn.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/debugcounter-newgvn.ll?rev=296665&view=auto
==============================================================================
--- llvm/trunk/test/Other/debugcounter-newgvn.ll (added)
+++ llvm/trunk/test/Other/debugcounter-newgvn.ll Wed Mar  1 13:59:26 2017
@@ -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
+}
+
+
+

Copied: llvm/trunk/test/Other/debugcounter-predicateinfo.ll (from r296569, llvm/trunk/test/Other/debugcounter.ll)
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/debugcounter-predicateinfo.ll?p2=llvm/trunk/test/Other/debugcounter-predicateinfo.ll&p1=llvm/trunk/test/Other/debugcounter.ll&r1=296569&r2=296665&rev=296665&view=diff
==============================================================================
--- llvm/trunk/test/Other/debugcounter.ll (original)
+++ llvm/trunk/test/Other/debugcounter-predicateinfo.ll Wed Mar  1 13:59:26 2017
@@ -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:
 bb35:                                             ; preds = %bb33, %bb29, %bb22
   unreachable
 }
-

Removed: llvm/trunk/test/Other/debugcounter.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/debugcounter.ll?rev=296664&view=auto
==============================================================================
--- llvm/trunk/test/Other/debugcounter.ll (original)
+++ llvm/trunk/test/Other/debugcounter.ll (removed)
@@ -1,40 +0,0 @@
-; 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
-; RUN: opt -debug-counter=predicateinfo-rename-skip=1,predicateinfo-rename-count=1 -print-predicateinfo -analyze  < %s 2>&1 | FileCheck %s
-define fastcc void @barney() {
-; CHECK-LABEL: @barney(
-; CHECK-NEXT:  bb:
-; CHECK-NEXT:    br label [[BB22:%.*]]
-; CHECK:       bb22:
-; CHECK-NEXT:    [[TMP23:%.*]] = icmp eq i32 undef, 2
-; CHECK:         [[TMP23_0:%.*]] = call i1 @llvm.ssa.copy.i1(i1 [[TMP23]])
-; CHECK-NEXT:    br i1 [[TMP23]], label [[BB29:%.*]], label [[BB35:%.*]]
-; CHECK:       bb29:
-; CHECK:         [[TMP23_0_1:%.*]] = call i1 @llvm.ssa.copy.i1(i1 [[TMP23_0]])
-; CHECK-NEXT:    br i1 [[TMP23]], label [[BB33:%.*]], label [[BB35]]
-; CHECK:       bb33:
-; CHECK-NEXT:    br i1 [[TMP23_0_1]], label [[BB35]], label [[BB35]]
-; CHECK:       bb35:
-; CHECK-NEXT:    unreachable
-;
-bb:
-  br label %bb22
-bb22:                                             ; preds = %bb21
-  %tmp23 = icmp eq i32 undef, 2
-  br i1 %tmp23, label %bb29, label %bb35
-
-
-bb29:                                             ; preds = %bb28
-;; We will not rename this one (we will still generate a copy of a copy for the next one)
-  br i1 %tmp23, label %bb33, label %bb35
-
-
-bb33:                                             ; preds = %bb31
-;; We will rename this one
-  br i1 %tmp23, label %bb35, label %bb35
-
-bb35:                                             ; preds = %bb33, %bb29, %bb22
-  unreachable
-}
-




More information about the llvm-commits mailing list