[llvm] f7ba2bd - [LLVM][SLSR] Add a debug counter (#119981)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Dec 21 09:37:48 PST 2024
Author: GrumpyPigSkin
Date: 2024-12-21T12:37:44-05:00
New Revision: f7ba2bdf863b589140cb97a3fafb2f4688532456
URL: https://github.com/llvm/llvm-project/commit/f7ba2bdf863b589140cb97a3fafb2f4688532456
DIFF: https://github.com/llvm/llvm-project/commit/f7ba2bdf863b589140cb97a3fafb2f4688532456.diff
LOG: [LLVM][SLSR] Add a debug counter (#119981)
Added debug counter and test for SLSR.
Fixes: https://github.com/llvm/llvm-project/issues/119770
Added:
llvm/test/Other/debugcounter-slsr.ll
Modified:
llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
index 75585fcc802667..7d017095c88ce6 100644
--- a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
@@ -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"
@@ -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 {
@@ -268,8 +272,8 @@ 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).
+ // 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()) &&
@@ -610,6 +614,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
diff --git a/llvm/test/Other/debugcounter-slsr.ll b/llvm/test/Other/debugcounter-slsr.ll
new file mode 100644
index 00000000000000..a9ca45222a5ccb
--- /dev/null
+++ b/llvm/test/Other/debugcounter-slsr.ll
@@ -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)
+
More information about the llvm-commits
mailing list