-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[mlir][memref][nfc] push early-exit to earlier #140730
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
|
@llvm/pr-subscribers-mlir Author: Javed Absar (javedabsar1) ChangesFull diff: https://github.com/llvm/llvm-project/pull/140730.diff 1 Files Affected:
diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index 7f45904fab7e1..d78de25f3e0ff 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -1711,6 +1711,10 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<memref::ViewOp> {
MemRefDescriptor sourceMemRef(adaptor.getSource());
auto targetMemRef = MemRefDescriptor::poison(rewriter, loc, targetDescTy);
+ // Early exit for 0-D corner case.
+ if (viewMemRefType.getRank() == 0)
+ return rewriter.replaceOp(viewOp, {targetMemRef}), success();
+
// Field 1: Copy the allocated pointer, used for malloc/free.
Value allocatedPtr = sourceMemRef.allocatedPtr(rewriter, loc);
auto srcMemRefType = cast<MemRefType>(viewOp.getSource().getType());
@@ -1733,10 +1737,6 @@ struct ViewOpLowering : public ConvertOpToLLVMPattern<memref::ViewOp> {
rewriter, loc,
createIndexAttrConstant(rewriter, loc, indexType, offset));
- // Early exit for 0-D corner case.
- if (viewMemRefType.getRank() == 0)
- return rewriter.replaceOp(viewOp, {targetMemRef}), success();
-
// Fields 4 and 5: Update sizes and strides.
Value stride = nullptr, nextSize = nullptr;
for (int i = viewMemRefType.getRank() - 1; i >= 0; --i) {
|
banach-space
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.
I am not familiar with this code, but the change is quite straightforward and a clear improvement. Thanks, LGTM!
|
What was the rationale behind this change? I see that now for the following snippet after --finalize-memref-to-llvm IR looks as so no flow from %12 to memref_i8 which seems to be wrong |
|
Hey @Garra1980 , thanks for posting this and apologies if you're experiencing issues due to this PR.
Early exits are encouraged in LLVM and this looked like (and still does) like an NFC.
It's not quite clear to me what is wrong 😅 Could you compare before and after IR? If after is indeed incorrect, we should include your example as a test and revert this change. |
Ah, my bad! You're right, before it was like this: |
Reverts llvm#140730 - that turned out not to be an NFC as we originally thought. See the attached test for an example. Many thanks to @Garra1980 for reporting!
|
Thanks @Garra1980 , here's a revert with a minimal test: |
Add a TODO to re-use check lines, remove LIT variables (for consistency with existing examples)
Reverts #140730 - that turned out not to be an NFC as we originally thought. See the attached test for an example. Many thanks to @Garra1980 for reporting! Note, without this change, the newly added test would be incorrectly converted to: ```mlir func.func @view_memref_as_rank0(%arg0: index, %arg1: memref<2xi8>) { %0 = llvm.mlir.poison : !llvm.struct<(ptr, ptr, i64)> return } ```
No description provided.