Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/DebugCounter.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Transforms/Scalar.h"
#include "llvm/Transforms/Utils/Local.h"
Expand All @@ -93,6 +94,9 @@ using namespace PatternMatch;
static const unsigned UnknownAddressSpace =
std::numeric_limits<unsigned>::max();

DEBUG_COUNTER(StraightLineStrengthReduceCounter, "slsr-counter",
"Controls whether rewriteCandidateWithBasis is executed.");

namespace {

class StraightLineStrengthReduceLegacyPass : public FunctionPass {
Expand Down Expand Up @@ -267,9 +271,10 @@ FunctionPass *llvm::createStraightLineStrengthReducePass() {

bool StraightLineStrengthReduce::isBasisFor(const Candidate &Basis,
const Candidate &C) {
return (Basis.Ins != C.Ins && // skip the same instruction
// They must have the same type too. Basis.Base == C.Base doesn't
// guarantee their types are the same (PR23975).
return (Basis.Ins !=
C.Ins && // skip the same instruction
// They must have the same type too. Basis.Base == C.Base
// doesn't guarantee their types are the same (PR23975).
Basis.Ins->getType() == C.Ins->getType() &&
// Basis must dominate C in order to rewrite C with respect to Basis.
DT->dominates(Basis.Ins->getParent(), C.Ins->getParent()) &&
Expand Down Expand Up @@ -610,6 +615,9 @@ Value *StraightLineStrengthReduce::emitBump(const Candidate &Basis,

void StraightLineStrengthReduce::rewriteCandidateWithBasis(
const Candidate &C, const Candidate &Basis) {
if (!DebugCounter::shouldExecute(StraightLineStrengthReduceCounter))
return;

assert(C.CandidateKind == Basis.CandidateKind && C.Base == Basis.Base &&
C.Stride == Basis.Stride);
// We run rewriteCandidateWithBasis on all candidates in a post-order, so the
Expand Down
26 changes: 26 additions & 0 deletions llvm/test/Other/debugcounter-slsr.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
; REQUIRES: asserts
; RUN: opt -passes=slsr -S -debug-counter=slsr-counter=1 < %s | FileCheck %s

; Test that, with debug counters on, we will skip the first slsr opportunity.

define void @stride_is_2s(i32 %b, i32 %s) {
; CHECK-LABEL: @stride_is_2s(
; CHECK-NEXT: %s2 = shl i32 %s, 1
; CHECK-NEXT: %t1 = add i32 %b, %s2
; CHECK-NEXT: call void @foo(i32 %t1)
; CHECK-NEXT: %s4 = shl i32 %s, 2
; CHECK-NEXT: %t2 = add i32 %b, %s4
; CHECK-NEXT: call void @foo(i32 %t2)
; CHECK-NEXT: ret void
;
%s2 = shl i32 %s, 1
%t1 = add i32 %b, %s2
call void @foo(i32 %t1)
%s4 = shl i32 %s, 2
%t2 = add i32 %b, %s4
call void @foo(i32 %t2)
ret void
}

declare void @foo(i32)

Loading