Skip to content

[mlir][Vector] Fix an assertion on failing cast in vector-transfer-flatten-patterns #86030

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 6 commits into from
Mar 25, 2024

Conversation

bviyer
Copy link
Contributor

@bviyer bviyer commented Mar 20, 2024

When the result is not a vectorType, there is an assert. This patch will do the check
and bail when the result is not a VectorType.

When the result is not a vectorType, there is an assert.
This patch will do the check and bail when the result is
not a VectorType.
@llvmbot
Copy link
Member

llvmbot commented Mar 20, 2024

@llvm/pr-subscribers-mlir-vector

@llvm/pr-subscribers-mlir

Author: Balaji V. Iyer. (bviyer)

Changes

When the result is not a vectorType, there is an assert. This patch will do the check
and bail when the result is not a VectorType.


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp (+2-2)
diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp
index 7ca03537049812..38536de43f13f2 100644
--- a/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp
@@ -22,9 +22,9 @@ using namespace mlir;
 static bool isLessThanTargetBitWidth(Operation *op, unsigned targetBitWidth) {
   auto resultTypes = op->getResultTypes();
   for (auto resType : resultTypes) {
-    VectorType vecType = cast<VectorType>(resType);
+    VectorType vecType = dyn_cast<VectorType>(resType);
     // Reject index since getElementTypeBitWidth will abort for Index types.
-    if (vecType.getElementType().isIndex())
+    if (!vecType || vecType.getElementType().isIndex())
       return false;
     unsigned trailingVecDimBitWidth =
         vecType.getShape().back() * vecType.getElementTypeBitWidth();

@joker-eph
Copy link
Collaborator

Thanks for the fix!

Can you add a test that shows how the assert is triggered?

@dcaballe dcaballe changed the title Added a dynamic check for VectorType. [mlir][Vector] Added a dynamic check for VectorType. Mar 21, 2024
@bviyer
Copy link
Contributor Author

bviyer commented Mar 21, 2024

@joker-eph I added a test that will fail without the fix.

@banach-space
Copy link
Contributor

@joker-eph I added a test that will fail without the fix.

I don't hit the assert when LLVM_ENABLE_ASSERTIONS are ON. How do you trigger it?

@joker-eph
Copy link
Collaborator

I'm confused, the test does not match the code change: did you try running the test at HEAD and confirm it is crashing?

@joker-eph joker-eph changed the title [mlir][Vector] Added a dynamic check for VectorType. [mlir][Vector] Fix assertion on failing cast in vector-transfer-flatten-patterns Mar 22, 2024
@joker-eph joker-eph changed the title [mlir][Vector] Fix assertion on failing cast in vector-transfer-flatten-patterns [mlir][Vector] Fix an assertion on failing cast in vector-transfer-flatten-patterns Mar 22, 2024
@banach-space banach-space self-requested a review March 22, 2024 08:00
Copy link

✅ With the latest revision this PR passed the Python code formatter.

Copy link

✅ With the latest revision this PR passed the C/C++ code formatter.

@bviyer
Copy link
Contributor Author

bviyer commented Mar 22, 2024

I'm confused, the test does not match the code change: did you try running the test at HEAD and confirm it is crashing?

@joker-eph and @banach-space The test was correct one but I accidentally put in the wrong file. Very sorry about the mess/confusion.

Now, if you revert this check-in (afc2639) and then run check-mlir it would show 1 crash, the newly added test. With this above-mentioned check-in the whole thing should pass.

Copy link
Contributor

@dcaballe dcaballe left a comment

Choose a reason for hiding this comment

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

LG, thanks!

@bviyer
Copy link
Contributor Author

bviyer commented Mar 25, 2024

Hi @joker-eph and @banach-space, Please let me know if you have any more questions. I would like to land the patch by Monday (March 25th 2024) evening if I don't hear any objections.

Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

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

I would like to land the patch by Monday (March 25th 2024) evening if I don't hear any objections.

Thanks for the update. I've made a suggestion how to improve the test - I'd like that to be addressed before this is merged.

@bviyer bviyer requested a review from banach-space March 25, 2024 16:44
Copy link
Contributor

@banach-space banach-space left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for addressing my comments!

@bviyer bviyer merged commit 5f1f9cf into llvm:main Mar 25, 2024
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.

5 participants