-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[MLIR][Affine] Fix fusion crash for non-int/fp memref elt types #126829
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
bondhugula
merged 1 commit into
llvm:main
from
bondhugula:uday/fix_fusion_private_memref_elt_type_crash
Feb 12, 2025
Merged
[MLIR][Affine] Fix fusion crash for non-int/fp memref elt types #126829
bondhugula
merged 1 commit into
llvm:main
from
bondhugula:uday/fix_fusion_private_memref_elt_type_crash
Feb 12, 2025
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
@llvm/pr-subscribers-mlir @llvm/pr-subscribers-mlir-affine Author: Uday Bondhugula (bondhugula) ChangesFix assumption on memref elt types being int or float during private Full diff: https://github.com/llvm/llvm-project/pull/126829.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
index b38dd8effe669..1f4c1c0c39f6d 100644
--- a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
@@ -759,6 +759,9 @@ struct GreedyFusion {
const DenseSet<Value> &srcEscapingMemRefs,
unsigned producerId, unsigned consumerId,
bool removeSrcNode) {
+ // We can't generate private memrefs if their size can't be computed.
+ if (!cast<MemRefType>(memref.getType()).getElementType().isIntOrFloat())
+ return false;
const Node *consumerNode = mdg->getNode(consumerId);
// If `memref` is an escaping one, do not create a private memref
// for the below scenarios, since doing so will leave the escaping
diff --git a/mlir/test/Dialect/Affine/loop-fusion-4.mlir b/mlir/test/Dialect/Affine/loop-fusion-4.mlir
index 2830235431c76..07d2d06f1451d 100644
--- a/mlir/test/Dialect/Affine/loop-fusion-4.mlir
+++ b/mlir/test/Dialect/Affine/loop-fusion-4.mlir
@@ -1,4 +1,5 @@
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(affine-loop-fusion{mode=producer}))' -split-input-file | FileCheck %s --check-prefix=PRODUCER-CONSUMER
+// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(affine-loop-fusion{mode=producer fusion-maximal}))' -split-input-file | FileCheck %s --check-prefix=PRODUCER-CONSUMER-MAXIMAL
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(func.func(affine-loop-fusion{fusion-maximal mode=sibling}))' -split-input-file | FileCheck %s --check-prefix=SIBLING-MAXIMAL
// RUN: mlir-opt -allow-unregistered-dialect %s -pass-pipeline='builtin.module(spirv.func(affine-loop-fusion{mode=producer}))' -split-input-file | FileCheck %s --check-prefix=SPIRV
@@ -345,3 +346,37 @@ func.func @same_memref_load_multiple_stores(%producer : memref<32xf32>, %produce
// PRODUCER-CONSUMER-NEXT: }
return
}
+
+#map = affine_map<()[s0] -> (s0 + 5)>
+#map1 = affine_map<()[s0] -> (s0 + 17)>
+
+// Test with non-int/float memref types.
+
+// PRODUCER-CONSUMER-MAXIMAL-LABEL: func @memref_index_type
+func.func @memref_index_type() {
+ %0 = llvm.mlir.constant(2 : index) : i64
+ %2 = llvm.mlir.constant(0 : index) : i64
+ %3 = builtin.unrealized_conversion_cast %2 : i64 to index
+ %alloc = memref.alloc() {alignment = 64 : i64} : memref<8x18xf32>
+ %alloc_1 = memref.alloc() {alignment = 64 : i64} : memref<3xf32>
+ %alloc_2 = memref.alloc() {alignment = 64 : i64} : memref<3xindex>
+ affine.for %arg3 = 0 to 3 {
+ %4 = affine.load %alloc_2[%arg3] : memref<3xindex>
+ %5 = builtin.unrealized_conversion_cast %4 : index to i64
+ %6 = llvm.sub %0, %5 : i64
+ %7 = builtin.unrealized_conversion_cast %6 : i64 to index
+ affine.store %7, %alloc_2[%arg3] : memref<3xindex>
+ }
+ affine.for %arg3 = 0 to 3 {
+ %4 = affine.load %alloc_2[%arg3] : memref<3xindex>
+ %5 = affine.apply #map()[%4]
+ %6 = affine.apply #map1()[%3]
+ %7 = memref.load %alloc[%5, %6] : memref<8x18xf32>
+ affine.store %7, %alloc_1[%arg3] : memref<3xf32>
+ }
+ // Expect fusion.
+ // PRODUCER-CONSUMER-MAXIMAL: affine.for
+ // PRODUCER-CONSUMER-MAXIMAL-NOT: affine.for
+ // PRODUCER-CONSUMER-MAXIMAL: return
+ return
+}
|
2e5b8d4
to
b6eeea9
Compare
Fix assumption on memref elt types being int or float during private memref creation in affine fusion. Fixes: llvm#121020
b6eeea9
to
18ba665
Compare
Obvious fix for a reported crash. Merging. |
flovent
pushed a commit
to flovent/llvm-project
that referenced
this pull request
Feb 13, 2025
…#126829) Fix assumption on memref elt types being int or float during private memref creation in affine fusion. Fixes: llvm#121020
joaosaffran
pushed a commit
to joaosaffran/llvm-project
that referenced
this pull request
Feb 14, 2025
…#126829) Fix assumption on memref elt types being int or float during private memref creation in affine fusion. Fixes: llvm#121020
sivan-shani
pushed a commit
to sivan-shani/llvm-project
that referenced
this pull request
Feb 24, 2025
…#126829) Fix assumption on memref elt types being int or float during private memref creation in affine fusion. Fixes: llvm#121020
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.
Fix assumption on memref elt types being int or float during private
memref creation in affine fusion.
Fixes: #121020