-
Notifications
You must be signed in to change notification settings - Fork 13.7k
[mlir][memref] Revert #140730 #141406
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 pr 8000 ivacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
[mlir][memref] Revert #140730 #141406
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!
@llvm/pr-subscribers-mlir Author: Andrzej Warzyński (banach-space) ChangesReverts #140730 - that turned out not to be an NFC as we originally Full diff: https://github.com/llvm/llvm-project/pull/141406.diff 2 Files Affected:
diff --git a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
index 339f8a61136fc..ade4e4d3de8ec 100644
--- a/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
+++ b/mlir/lib/Conversion/MemRefToLLVM/MemRefToLLVM.cpp
@@ -1721,10 +1721,6 @@ 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());
@@ -1747,6 +1743,10 @@ 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) {
diff --git a/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir b/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
index 5538ddf8e4c3c..ffa8a76ba03e1 100644
--- a/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
+++ b/mlir/test/Conversion/MemRefToLLVM/memref-to-llvm.mlir
@@ -1,10 +1,10 @@
-// RUN: mlir-opt -finalize-memref-to-llvm %s -split-input-file | FileCheck %s
+// RUN: mlir-opt -finalize-memref-to-llvm %s -split-input-file | FileCheck --check-prefixes=ALL,CHECK %s
// RUN: mlir-opt -finalize-memref-to-llvm='index-bitwidth=32' %s -split-input-file | FileCheck --check-prefix=CHECK32 %s
// Same below, but using the `ConvertToLLVMPatternInterface` entry point
// and the generic `convert-to-llvm` pass. This produces slightly different IR
// because the conversion target is set up differently.
-// RUN: mlir-opt --convert-to-llvm="filter-dialects=memref" --split-input-file %s | FileCheck --check-prefix=CHECK-INTERFACE %s
+// RUN: mlir-opt --convert-to-llvm="filter-dialects=memref" --split-input-file %s | FileCheck --check-prefixes=ALL,CHECK-INTERFACE %s
// CHECK-LABEL: func @view(
// CHECK: %[[ARG0F:.*]]: index, %[[ARG1F:.*]]: index, %[[ARG2F:.*]]: index
@@ -132,6 +132,28 @@ func.func @view_empty_memref(%offset: index, %mem: memref<0xi8>) {
// -----
+// ALL-LABEL: func.func @view_memref_as_rank0(
+// ALL-SAME: %[[ARG0:.*]]: index,
+// ALL-SAME: %[[ARG1:.*]]: memref<2xi8>) {
+func.func @view_memref_as_rank0(%offset: index, %mem: memref<2xi8>) {
+
+ // ALL: %[[VAL_0:.*]] = builtin.unrealized_conversion_cast %[[ARG0]] : index to i64
+ // ALL: %[[VAL_1:.*]] = builtin.unrealized_conversion_cast %[[ARG1]] : memref<2xi8> to !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+ // ALL: %[[VAL_2:.*]] = llvm.mlir.poison : !llvm.struct<(ptr, ptr, i64)>
+ // ALL: %[[VAL_3:.*]] = llvm.extractvalue %[[VAL_1]][0] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+ // ALL: %[[VAL_4:.*]] = llvm.insertvalue %[[VAL_3]], %[[VAL_2]][0] : !llvm.struct<(ptr, ptr, i64)>
+ // ALL: %[[VAL_5:.*]] = llvm.extractvalue %[[VAL_1]][1] : !llvm.struct<(ptr, ptr, i64, array<1 x i64>, array<1 x i64>)>
+ // ALL: %[[VAL_6:.*]] = llvm.getelementptr %[[VAL_5]]{{\[}}%[[VAL_0]]] : (!llvm.ptr, i64) -> !llvm.ptr, i8
+ // ALL: %[[VAL_7:.*]] = llvm.insertvalue %[[VAL_6]], %[[VAL_4]][1] : !llvm.struct<(ptr, ptr, i64)>
+ // ALL: %[[VAL_8:.*]] = llvm.mlir.constant(0 : index) : i64
+ // ALL: %[[VAL_9:.*]] = llvm.insertvalue %[[VAL_8]], %[[VAL_7]][2] : !llvm.struct<(ptr, ptr, i64)>
+ %memref_view_bf16 = memref.view %mem[%offset][] : memref<2xi8> to memref<bf16>
+
+ return
+}
+
+// -----
+
// Subviews needs to be expanded outside of the memref-to-llvm pass.
// CHECK-LABEL: func @subview(
// CHECK: %[[MEMREF:.*]]: memref<{{.*}}>,
|
joker-eph
approved these changes
May 25, 2025
Add a TODO to re-use check lines, remove LIT variables (for consistency with existing examples)
Thanks a lot! |
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Jun 3, 2025
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! 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 } ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: