Skip to content

[MLIR] Add missing memory read effect on memref.reshape #117130

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

Merged
merged 1 commit into from
Nov 22, 2024

Conversation

bondhugula
Copy link
Contributor

@bondhugula bondhugula commented Nov 21, 2024

The memory read effect on a memref.reshape argument was missing. This in turn led to
analyses relying on memory effects making incorrect conclusions.

Add missing memory read effect on memref.reshape. This in turn leads to
analyses relying on memory effects making incorrect conclusions.
@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2024

@llvm/pr-subscribers-mlir

Author: Uday Bondhugula (bondhugula)

Changes

Add missing memory read effect on memref.reshape. This in turn leads to
analyses relying on memory effects making incorrect conclusions.


Full diff: https://github.com/llvm/llvm-project/pull/117130.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td (+2-1)
diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
index c50df6ccd9aa56..a0d8d34f38237a 100644
--- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
+++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
@@ -1529,7 +1529,8 @@ def MemRef_ReshapeOp: MemRef_Op<"reshape", [
   }];
 
   let arguments = (ins AnyRankedOrUnrankedMemRef:$source,
-                       MemRefRankOf<[AnySignlessInteger, Index], [1]>:$shape);
+                       Arg<MemRefRankOf<[AnySignlessInteger, Index], [1]>,
+                       "dynamically-sized shape", [MemRead]>:$shape);
   let results = (outs AnyRankedOrUnrankedMemRef:$result);
 
   let builders = [OpBuilder<

@llvmbot
Copy link
Member

llvmbot commented Nov 21, 2024

@llvm/pr-subscribers-mlir-memref

Author: Uday Bondhugula (bondhugula)

Changes

Add missing memory read effect on memref.reshape. This in turn leads to
analyses relying on memory effects making incorrect conclusions.


Full diff: https://github.com/llvm/llvm-project/pull/117130.diff

1 Files Affected:

  • (modified) mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td (+2-1)
diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
index c50df6ccd9aa56..a0d8d34f38237a 100644
--- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
+++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
@@ -1529,7 +1529,8 @@ def MemRef_ReshapeOp: MemRef_Op<"reshape", [
   }];
 
   let arguments = (ins AnyRankedOrUnrankedMemRef:$source,
-                       MemRefRankOf<[AnySignlessInteger, Index], [1]>:$shape);
+                       Arg<MemRefRankOf<[AnySignlessInteger, Index], [1]>,
+                       "dynamically-sized shape", [MemRead]>:$shape);
   let results = (outs AnyRankedOrUnrankedMemRef:$result);
 
   let builders = [OpBuilder<

Copy link
Contributor

@cxy-1993 cxy-1993 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this.

@bondhugula bondhugula merged commit 454398a into llvm:main Nov 22, 2024
11 checks passed
@joker-eph
Copy link
Collaborator

That should be testable I think? We don't have a transformation where this can be visible?

@bondhugula
Copy link
Contributor Author

That should be testable I think? We don't have a transformation where this can be visible?

Yes, this should be testable. There are multiple affine analysis utilities that check for ops with mem read effects:

lib/Dialect/Affine/Transforms/AffineLoopInvariantCodeMotion.cpp:          (hasEffect<MemoryEffects::Read>(user, memref) &&
lib/Dialect/Affine/Utils/Utils.cpp:mlir::affine::hasNoInterveningEffect<mlir::MemoryEffects::Read,
lib/Dialect/Affine/Utils/Utils.cpp:    if (!affine::hasNoInterveningEffect<MemoryEffects::Read>(writeA, writeB,

Any of the passes relying on these utilities (affine-scalrep and affine-licm) will be able to exercise this. I can construct a test case.

affine.store ..., %M[...]  // S1.
memref.reshape %x, %M
affine.store ..., %M[...]  // S2.

Now, S1 should not be dead if the read effect is properly defined on memref.reshape.

@ftynse
Copy link
Member

ftynse commented Dec 5, 2024

I suppose the intent of the question was to say that we should have a test to avoid regressing this behavior.

@joker-eph
Copy link
Collaborator

I suppose the intent of the question was to say that we should have a test to avoid regressing this behavior.

Yes: @bondhugula can you actually add a test for this change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants