Skip to content

Commit 9c2ca90

Browse files
committed
Added debug counter and new test
1 parent 0032c15 commit 9c2ca90

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
#include "llvm/InitializePasses.h"
7979
#include "llvm/Pass.h"
8080
#include "llvm/Support/Casting.h"
81+
#include "llvm/Support/DebugCounter.h"
8182
#include "llvm/Support/ErrorHandling.h"
8283
#include "llvm/Transforms/Scalar.h"
8384
#include "llvm/Transforms/Utils/Local.h"
@@ -93,6 +94,9 @@ using namespace PatternMatch;
9394
static const unsigned UnknownAddressSpace =
9495
std::numeric_limits<unsigned>::max();
9596

97+
DEBUG_COUNTER(StraightLineStrengthReduceCounter, "slsr-counter",
98+
"Controls whether rewriteCandidateWithBasis is executed.");
99+
96100
namespace {
97101

98102
class StraightLineStrengthReduceLegacyPass : public FunctionPass {
@@ -690,7 +694,8 @@ bool StraightLineStrengthReduce::runOnFunction(Function &F) {
690694
while (!Candidates.empty()) {
691695
const Candidate &C = Candidates.back();
692696
if (C.Basis != nullptr) {
693-
rewriteCandidateWithBasis(C, *C.Basis);
697+
if (DebugCounter::shouldExecute(StraightLineStrengthReduceCounter))
698+
rewriteCandidateWithBasis(C, *C.Basis);
694699
}
695700
Candidates.pop_back();
696701
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; REQUIRES: asserts
2+
; RUN: opt -passes=slsr,gvn -S -debug-counter=slsr-counter=1 < %s | FileCheck %s
3+
4+
;; Test that, with debug counters on, we will skip the first slsr opportunity.
5+
6+
define void @stride_is_2s(i32 %b, i32 %s) {
7+
; CHECK-LABEL: @stride_is_2s(
8+
; CHECK-NEXT: %s2 = shl i32 %s, 1
9+
; CHECK-NEXT: %t1 = add i32 %b, %s2
10+
; CHECK-NEXT: call void @foo(i32 %t1)
11+
; CHECK-NEXT: %t2 = add i32 %t1, %s2
12+
; CHECK-NEXT: call void @foo(i32 %t2)
13+
; CHECK-NEXT: %s6 = mul i32 %s, 6
14+
; CHECK-NEXT: %t3 = add i32 %b, %s6
15+
; CHECK-NEXT: call void @foo(i32 %t3)
16+
; CHECK-NEXT: ret void
17+
;
18+
%s2 = shl i32 %s, 1
19+
%t1 = add i32 %b, %s2
20+
call void @foo(i32 %t1)
21+
%s4 = shl i32 %s, 2
22+
%t2 = add i32 %b, %s4
23+
call void @foo(i32 %t2)
24+
%s6 = mul i32 %s, 6
25+
%t3 = add i32 %b, %s6
26+
call void @foo(i32 %t3)
27+
ret void
28+
}
29+
30+
declare void @foo(i32)

0 commit comments

Comments
 (0)