-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[LLVM][SLSR] Add a debug counter #119981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LLVM][SLSR] Add a debug counter #119981
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-llvm-transforms Author: None (GrumpyPigSkin) ChangesAdded debug counter and test for slsr pass fixes: #119770 Full diff: https://github.com/llvm/llvm-project/pull/119981.diff 2 Files Affected:
diff --git a/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/StraightLineStrengthReduce.cpp
index 75585fcc802667..4d4bea3113cec7 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 {
@@ -690,7 +694,8 @@ bool StraightLineStrengthReduce::runOnFunction(Function &F) {
while (!Candidates.empty()) {
const Candidate &C = Candidates.back();
if (C.Basis != nullptr) {
- rewriteCandidateWithBasis(C, *C.Basis);
+ if (DebugCounter::shouldExecute(StraightLineStrengthReduceCounter))
+ rewriteCandidateWithBasis(C, *C.Basis);
}
Candidates.pop_back();
}
diff --git a/llvm/test/Other/debugcounter-slsr.ll b/llvm/test/Other/debugcounter-slsr.ll
new file mode 100644
index 00000000000000..facfc38f9e0c54
--- /dev/null
+++ b/llvm/test/Other/debugcounter-slsr.ll
@@ -0,0 +1,30 @@
+; REQUIRES: asserts
+; RUN: opt -passes=slsr,gvn -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: %t2 = add i32 %t1, %s2
+; CHECK-NEXT: call void @foo(i32 %t2)
+; CHECK-NEXT: %s6 = mul i32 %s, 6
+; CHECK-NEXT: %t3 = add i32 %b, %s6
+; CHECK-NEXT: call void @foo(i32 %t3)
+; 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)
+ %s6 = mul i32 %s, 6
+ %t3 = add i32 %b, %s6
+ call void @foo(i32 %t3)
+ ret void
+}
+
+declare void @foo(i32)
\ No newline at end of file
|
|
@justinfargnoli I can't add you to the reviewers for some reason so giving you a mention here. Let me know if I need to make any changes. |
justinfargnoli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, this looks great!
Leaving a few small "touch-up" comments.
|
@justinfargnoli, I have resolved all the comments. I had more of an issue adding a newline to the end of the file than anything 🙄 It Looks like the pull request has picked up the changes, let me know if there are any issues :) |
justinfargnoli
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on this @GrumpyPigSkin! LGTM :)
|
Merging on the author's behalf because they don't have commit access. |
|
@GrumpyPigSkin Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our build bots. If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of LLVM development. You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/45/builds/7358 Here is the relevant piece of the build log for the reference |
This looks like an infra failure and is likely unrelated to this PR. |
Added debug counter and test for slsr pass
fixes: #119770