-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[MLIR][SCF] fix loop pipelining pass use of uninitialized value #146991
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
[MLIR][SCF] fix loop pipelining pass use of uninitialized value #146991
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-mlir-scf @llvm/pr-subscribers-mlir Author: Hu Yufan (Hyffer) Changesfix issue #146990 Full diff: https://github.com/llvm/llvm-project/pull/146991.diff 1 Files Affected:
diff --git a/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp b/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp
index 4aacbe739ca5d..018ac729de8f9 100644
--- a/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp
+++ b/mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp
@@ -106,6 +106,20 @@ bool LoopPipelinerInternal::initializeLoopInfo(
lb = forOp.getLowerBound();
step = forOp.getStep();
+ std::vector<std::pair<Operation *, unsigned>> schedule;
+ options.getScheduleFn(forOp, schedule);
+ if (schedule.empty()) {
+ LDBG("--empty schedule -> BAIL");
+ return false;
+ }
+
+ opOrder.reserve(schedule.size());
+ for (auto &opSchedule : schedule) {
+ maxStage = std::max(maxStage, opSchedule.second);
+ stages[opSchedule.first] = opSchedule.second;
+ opOrder.push_back(opSchedule.first);
+ }
+
dynamicLoop = true;
auto upperBoundCst = getConstantIntValue(ub);
auto lowerBoundCst = getConstantIntValue(lb);
@@ -137,19 +151,6 @@ bool LoopPipelinerInternal::initializeLoopInfo(
LDBG("--no epilogue or predicate set -> BAIL");
return false;
}
- std::vector<std::pair<Operation *, unsigned>> schedule;
- options.getScheduleFn(forOp, schedule);
- if (schedule.empty()) {
- LDBG("--empty schedule -> BAIL");
- return false;
- }
-
- opOrder.reserve(schedule.size());
- for (auto &opSchedule : schedule) {
- maxStage = std::max(maxStage, opSchedule.second);
- stages[opSchedule.first] = opSchedule.second;
- opOrder.push_back(opSchedule.first);
- }
// All operations need to have a stage.
for (Operation &op : forOp.getBody()->without_terminator()) {
|
|
This is my first time contribute to llvm, I have went through contributing guide. And I have followed https://mlir.llvm.org/getting_started/TestingGuide/, test results: It seems those three just fail on main branch. |
|
Thanks for fixing this. Most likely the lit tests in |
130d637 to
09e8fca
Compare
|
The two failed cases in Test |
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.
Pull Request Overview
This PR fixes the use of an uninitialized scheduling value in the loop pipelining pass by moving and deduplicating schedule initialization, and tightens the iteration-vs-stage comparison.
- Moved schedule fetching and processing to the top of
initializeLoopInfoand removed the duplicate block. - Updated the boundary check from
>to>=when comparingnumIterationandmaxStage.
Comments suppressed due to low confidence (1)
mlir/lib/Dialect/SCF/Transforms/LoopPipelining.cpp:141
- Add a unit test case covering the boundary condition where
numIteration == maxStageto verify thatdynamicLoopis correctly set tofalsein this scenario.
if (numIteration >= maxStage) {
Copilot
AI
Jul 4, 2025
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.
Before reserving and populating opOrder and stages, ensure both containers are cleared (e.g., opOrder.clear(); stages.clear();) to avoid carrying over any stale entries when initializeLoopInfo is called multiple times.
makes sense. Could you add a lit test for the case it changes (when we detect dynamicLoop=false)? |
fc6f29d to
f537b8e
Compare
Sorry but I don't get the point. Currently most test cases in I added a test case that checks when a static loop does not satisfy |
right, sorry that's what I meant |
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.
LGTM
|
@Hyffer 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! |
fix issue #146990