Skip to content

[mlir] fix affine-loop-fusion crash #76351

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 2 commits into from
Dec 29, 2023
Merged

Conversation

lipracer
Copy link
Member

@lipracer lipracer commented Dec 25, 2023

If user not lies in Region findAncestorOpInRegion will return nullptr.

Fixes #76281.

@llvmbot
Copy link
Member

llvmbot commented Dec 25, 2023

@llvm/pr-subscribers-mlir

@llvm/pr-subscribers-mlir-affine

Author: long.chen (lipracer)

Changes

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

1 Files Affected:

  • (modified) mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp (+2-1)
diff --git a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
index 66d921b4889f59..2140ff66b1a676 100644
--- a/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
+++ b/mlir/lib/Dialect/Affine/Transforms/LoopFusion.cpp
@@ -205,7 +205,8 @@ static bool isEscapingMemref(Value memref, Block *block) {
   // (e.g., call ops, alias creating ops, etc.).
   return llvm::any_of(memref.getUsers(), [&](Operation *user) {
     // Ignore users outside of `block`.
-    if (block->getParent()->findAncestorOpInRegion(*user)->getBlock() != block)
+    auto ancestorOp = block->getParent()->findAncestorOpInRegion(*user);
+    if (!ancestorOp || ancestorOp->getBlock() != block)
       return false;
     return !isa<AffineMapAccessInterface>(*user);
   });

@rikhuijzer
Copy link
Member

Can you add a test which shows that #76281 is fixed? Preferably, also simplify the code from #76281 a bit so that the test is relatively simple. Without such a test, we might need to fix this issue again in the future.

Also, add fixes #76281 to your description in the first message on this PR. That will ensure that the linked issue is closed automatically when this PR is merged.

Copy link
Member

@rikhuijzer rikhuijzer left a comment

Choose a reason for hiding this comment

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

Apart from the suggestion and assuming the buildkite tests pass, this LGTM. Thanks for fixing the bug.

@rikhuijzer
Copy link
Member

rikhuijzer commented Dec 28, 2023

I've added Fixes #76281 to the first message so that this PR is linked to #76281. Once this PR is merged, #76281 will automatically be closed (https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).

@rikhuijzer rikhuijzer changed the title [mlir] fix affine-loop-fusion has a crash (#76281) [mlir] fix affine-loop-fusion crash Dec 28, 2023
@lipracer lipracer merged commit eaa32d2 into llvm:main Dec 29, 2023
@lipracer lipracer deleted the dev-fix-fusion branch December 29, 2023 11:18
qiaojbao pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Jan 26, 2024
…0dd27ca83

Local branch amd-gfx 7be0dd2 Merged main:52770d83bf00fc56e9496e32f083f0f940bf7315 into amd-gfx:a59cc49ff7ab
Remote branch main eaa32d2 [mlir] fix affine-loop-fusion crash (llvm#76351)
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.

[mlir] --affine-loop-fusion causes the Segmentation Fault.
3 participants