diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -57,6 +57,7 @@ #include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/DebugCounter.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" @@ -80,6 +81,9 @@ STATISTIC(NumCompletePartials, "Number of stores dead by later partials"); STATISTIC(NumModifiedStores, "Number of stores modified"); +DEBUG_COUNTER(MemorySSACounter, "dse-memoryssa", + "Controls which MemoryDefs are eliminated."); + static cl::opt EnablePartialOverwriteTracking("enable-dse-partial-overwrite-tracking", cl::init(true), cl::Hidden, @@ -1734,6 +1738,9 @@ break; } + if (!DebugCounter::shouldExecute(MemorySSACounter)) + break; + // Get what type of overwrite this might be int64_t InstWriteOffset, DepWriteOffset; OverwriteResult OR = isOverwrite(NILoc, SILoc, DL, TLI, DepWriteOffset, diff --git a/llvm/test/Transforms/DeadStoreElimination/MSSA/memoryssa-debugcounter.ll b/llvm/test/Transforms/DeadStoreElimination/MSSA/memoryssa-debugcounter.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/DeadStoreElimination/MSSA/memoryssa-debugcounter.ll @@ -0,0 +1,85 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py +; RUN: opt < %s -basicaa -dse -enable-dse-memoryssa -S | FileCheck --check-prefix=NO-COUNTER %s +; RUN: opt < %s -basicaa -dse -enable-dse-memoryssa -S \ +; RUN: -debug-counter=dse-memoryssa-skip=2,dse-memoryssa-count=10 | FileCheck --check-prefix=SKIP-2 %s +; RUN: opt < %s -basicaa -dse -enable-dse-memoryssa -S -debug-counter=dse-memoryssa-skip=0,dse-memoryssa-count=1 | FileCheck --check-prefix=COUNT-1 %s +; RUN: opt < %s -basicaa -dse -enable-dse-memoryssa -S -debug-counter=dse-memoryssa-skip=0,dse-memoryssa-count=0 | FileCheck --check-prefix=COUNT-0 %s +; RUN: opt < %s -basicaa -dse -enable-dse-memoryssa -S -debug-counter=dse-memoryssa-skip=1,dse-memoryssa-count=1 | FileCheck --check-prefix=SKIP-1-COUNT-1 %s + +target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64" + + +define void @test2(i32* noalias %P, i32* noalias %Q, i32* noalias %R) { +; NO-COUNTER-LABEL: @test2( +; NO-COUNTER-NEXT: br i1 true, label [[BB1:%.*]], label [[BB2:%.*]] +; NO-COUNTER: bb1: +; NO-COUNTER-NEXT: br label [[BB3:%.*]] +; NO-COUNTER: bb2: +; NO-COUNTER-NEXT: br label [[BB3]] +; NO-COUNTER: bb3: +; NO-COUNTER-NEXT: store i32 0, i32* [[Q:%.*]] +; NO-COUNTER-NEXT: store i32 0, i32* [[P:%.*]] +; NO-COUNTER-NEXT: ret void +; +; SKIP-2-LABEL: @test2( +; SKIP-2-NEXT: store i32 1, i32* [[P:%.*]] +; SKIP-2-NEXT: br i1 true, label [[BB1:%.*]], label [[BB2:%.*]] +; SKIP-2: bb1: +; SKIP-2-NEXT: br label [[BB3:%.*]] +; SKIP-2: bb2: +; SKIP-2-NEXT: br label [[BB3]] +; SKIP-2: bb3: +; SKIP-2-NEXT: store i32 0, i32* [[Q:%.*]] +; SKIP-2-NEXT: store i32 0, i32* [[Q]] +; SKIP-2-NEXT: store i32 0, i32* [[P]] +; SKIP-2-NEXT: ret void +; +; COUNT-1-LABEL: @test2( +; COUNT-1-NEXT: store i32 1, i32* [[P:%.*]] +; COUNT-1-NEXT: br i1 true, label [[BB1:%.*]], label [[BB2:%.*]] +; COUNT-1: bb1: +; COUNT-1-NEXT: br label [[BB3:%.*]] +; COUNT-1: bb2: +; COUNT-1-NEXT: br label [[BB3]] +; COUNT-1: bb3: +; COUNT-1-NEXT: store i32 0, i32* [[Q:%.*]] +; COUNT-1-NEXT: store i32 0, i32* [[P]] +; COUNT-1-NEXT: ret void +; +; COUNT-0-LABEL: @test2( +; COUNT-0-NEXT: store i32 1, i32* [[P:%.*]] +; COUNT-0-NEXT: br i1 true, label [[BB1:%.*]], label [[BB2:%.*]] +; COUNT-0: bb1: +; COUNT-0-NEXT: br label [[BB3:%.*]] +; COUNT-0: bb2: +; COUNT-0-NEXT: br label [[BB3]] +; COUNT-0: bb3: +; COUNT-0-NEXT: store i32 0, i32* [[Q:%.*]] +; COUNT-0-NEXT: store i32 0, i32* [[Q]] +; COUNT-0-NEXT: store i32 0, i32* [[P]] +; COUNT-0-NEXT: ret void +; +; SKIP-1-COUNT-1-LABEL: @test2( +; SKIP-1-COUNT-1-NEXT: br i1 true, label [[BB1:%.*]], label [[BB2:%.*]] +; SKIP-1-COUNT-1: bb1: +; SKIP-1-COUNT-1-NEXT: br label [[BB3:%.*]] +; SKIP-1-COUNT-1: bb2: +; SKIP-1-COUNT-1-NEXT: br label [[BB3]] +; SKIP-1-COUNT-1: bb3: +; SKIP-1-COUNT-1-NEXT: store i32 0, i32* [[Q:%.*]] +; SKIP-1-COUNT-1-NEXT: store i32 0, i32* [[Q]] +; SKIP-1-COUNT-1-NEXT: store i32 0, i32* [[P:%.*]] +; SKIP-1-COUNT-1-NEXT: ret void +; + store i32 1, i32* %P + br i1 true, label %bb1, label %bb2 +bb1: + br label %bb3 +bb2: + br label %bb3 +bb3: + store i32 0, i32* %Q + store i32 0, i32* %Q + store i32 0, i32* %P + ret void +}