-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[MLIR] RemoveDeadValues: Allowing IRs with global constants to get dead values removed #116519
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
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 @llvm/pr-subscribers-mlir-core Author: Renat Idrisov (parsifal-47) ChangesThis change is related to discussion: I do not know the original reason to disallow the optimization on modules with global private constant. Please let me know what am I missing, I will be happy to make it better. Thank you! CC: @Wheest Full diff: https://github.com/llvm/llvm-project/pull/116519.diff 2 Files Affected:
diff --git a/mlir/lib/Transforms/RemoveDeadValues.cpp b/mlir/lib/Transforms/RemoveDeadValues.cpp
index 7e45f18b660ba7..edfb1969ab75c7 100644
--- a/mlir/lib/Transforms/RemoveDeadValues.cpp
+++ b/mlir/lib/Transforms/RemoveDeadValues.cpp
@@ -579,7 +579,6 @@ void RemoveDeadValues::runOnOperation() {
if (op == module)
return WalkResult::advance();
if (isa<BranchOpInterface>(op) ||
- (isa<SymbolOpInterface>(op) && !isa<FunctionOpInterface>(op)) ||
(isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) {
op->emitError() << "cannot optimize an IR with non-function symbol ops, "
"non-call symbol user ops or branch ops\n";
diff --git a/mlir/test/Transforms/remove-dead-values.mlir b/mlir/test/Transforms/remove-dead-values.mlir
index 9f2be3331b6b4b..b06b3320706cc8 100644
--- a/mlir/test/Transforms/remove-dead-values.mlir
+++ b/mlir/test/Transforms/remove-dead-values.mlir
@@ -1,12 +1,12 @@
// RUN: mlir-opt %s -remove-dead-values -split-input-file -verify-diagnostics | FileCheck %s
-// The IR remains untouched because of the presence of a non-function-like
-// symbol op inside the module (const @__dont_touch_unacceptable_ir).
+// The IR is updated regardless of memref.global private constant
//
module {
-// expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}}
memref.global "private" constant @__dont_touch_unacceptable_ir : memref<i32> = dense<0>
func.func @main(%arg0: i32) -> i32 {
+ %0 = tensor.empty() : tensor<10xbf16>
+ // CHECK-NOT: tensor.empty
return %arg0 : i32
}
}
|
|
@srishti-pm Can you please review this change? I am curious why the IR is not considered acceptable if it contains something like |
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.
From my perspective it should be fine if IR with named symbols like constants use this pass (my recent PR did this for named modules #109990).
A justification for keeping the existing behaviour could be: "that which has a name should be handled more carefully, and not removed unless specifically requested."
However, since this is a blocker for some of my own work, I don't support it, and think this PR should go through.
That being said, I could imagine adding this behaviour back in with --remove-dead-values="remove-user-symbols"
@@ -579,7 +579,6 @@ void RemoveDeadValues::runOnOperation() { | |||
if (op == module) | |||
return WalkResult::advance(); | |||
if (isa<BranchOpInterface>(op) || | |||
(isa<SymbolOpInterface>(op) && !isa<FunctionOpInterface>(op)) || | |||
(isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) { | |||
op->emitError() << "cannot optimize an IR with non-function symbol ops, " |
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.
So the original comment above says:
// The removal of non-live values is performed iff there are no branch ops,
// all symbol ops present in the IR are function-like, and all symbol user ops
// present in the IR are call-like.
and the error message includes non-call symbol user ops
. With this PR I believe that IR with non-call symbol user ops are no longer excluded?
Perhaps the error message/comment should be updated to reflect that.
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.
updated both the comment and error message, thank you!
// | ||
module { | ||
// expected-error @+1 {{cannot optimize an IR with non-function symbol ops, non-call symbol user ops or branch ops}} | ||
memref.global "private" constant @__dont_touch_unacceptable_ir : memref<i32> = dense<0> |
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.
is @__dont_touch_unacceptable_ir
still a meaningful name here, since we expect the IR to be updated?
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.
thank you, done!
From my perspective I'd love to see all of the |
Hello @joker-eph It appears that you have recently reviewed and committed changes to this file. Would it be possible for you to review this change? |
WalkResult acceptableIR = module->walk([&](Operation *op) { | ||
if (op == module) | ||
return WalkResult::advance(); | ||
if (isa<BranchOpInterface>(op) || | ||
(isa<SymbolOpInterface>(op) && !isa<FunctionOpInterface>(op)) || | ||
(isa<SymbolUserOpInterface>(op) && !isa<CallOpInterface>(op))) { |
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.
This last check is also not clear to me. But I'm not sure if this has all to do with some aspects of the dataflow framework?
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.
It's not clear why this check is in-place (unfortunately the comment documents the "what" and not the "why"...).
In any case we could tighten this back with motivating examples, if they show up, and I suspect the checks could be more targeted: for example instead of disabling the pass entirely, we could disable it on a per-function basis.
@joker-eph I was curious if there is anything else needed for this change to be committed? |
It is approved, and the author has commit access, so I didn't feel like committing in their place. @parsifal-47 what's up? |
hmm, I see the following: |
sorry, maybe I do not understand the workflow, the PR is approved, should I look for motivating examples? |
@joker-eph Based on my offline conversation with @parsifal-47 it appears he lacks write access. Would it be possible for you to commit and merge this change into |
@parsifal-47 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! |
…Pass (#117405) This change removes the restriction on `SymbolUserOpInterface` operators so they can be used with operators that implement `SymbolOpInterface`, example: `memref.global` implements `SymbolOpInterface` so it can be used with `memref.get_global` which implements `SymbolUserOpInterface` ``` // Define a global constant array memref.global "private" constant @global_array : memref<10xi32> = dense<[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]> : tensor<10xi32> // Access this global constant within a function func @use_global() { %0 = memref.get_global @global_array : memref<10xi32> } ``` Reference: #116519 and https://discourse.llvm.org/t/question-on-criteria-for-acceptable-ir-in-removedeadvaluespass/83131 --------- Co-authored-by: Zeeshan Siddiqui <[email protected]>
This change is related to discussion:
https://discourse.llvm.org/t/question-on-criteria-for-acceptable-ir-in-removedeadvaluespass/83131
I do not know the original reason to disallow the optimization on modules with global private constant. Please let me know what am I missing, I will be happy to make it better. Thank you!
CC: @Wheest