From: Daniel Berlin Date: Wed, 1 Mar 2017 19:59:26 +0000 (+0000) Subject: NewGVN: Add debug counter for value numbering X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=894edf66427e4d524a143963c0b1a630dc0d3158;p=llvm NewGVN: Add debug counter for value numbering git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296665 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/NewGVN.cpp b/lib/Transforms/Scalar/NewGVN.cpp index b7914ba54bd..6c4ee6eafb8 100644 --- a/lib/Transforms/Scalar/NewGVN.cpp +++ b/lib/Transforms/Scalar/NewGVN.cpp @@ -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 InstructionsToErase; + // The set of things we gave unknown expressions to due to debug counting. + SmallPtrSet 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 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(&I)) { auto *CurrentVal = ValueToClass.lookup(&I); diff --git a/test/Other/debugcounter-newgvn.ll b/test/Other/debugcounter-newgvn.ll new file mode 100644 index 00000000000..cfe043c8455 --- /dev/null +++ b/test/Other/debugcounter-newgvn.ll @@ -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 +} + + + diff --git a/test/Other/debugcounter.ll b/test/Other/debugcounter-predicateinfo.ll similarity index 99% rename from test/Other/debugcounter.ll rename to test/Other/debugcounter-predicateinfo.ll index d9ab9abd73f..eb2ec09802f 100644 --- a/test/Other/debugcounter.ll +++ b/test/Other/debugcounter-predicateinfo.ll @@ -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 } -