Skip to content

[mlir] Use dyn_cast instead of cast in MathToVCIX conversion #134047

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
Apr 2, 2025

Conversation

CoTinker
Copy link
Contributor

@CoTinker CoTinker commented Apr 2, 2025

Fixes #131093.

@CoTinker CoTinker requested review from joker-eph and chsigg April 2, 2025 08:21
@llvmbot llvmbot added the mlir label Apr 2, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 2, 2025

@llvm/pr-subscribers-mlir

Author: Longsheng Mou (CoTinker)

Changes

Fixes #131093.


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

2 Files Affected:

  • (modified) mlir/test/Conversion/MathToVCIX/math-to-vcix.mlir (+11)
  • (modified) mlir/test/lib/Conversion/MathToVCIX/TestMathToVCIXConversion.cpp (+1-1)
diff --git a/mlir/test/Conversion/MathToVCIX/math-to-vcix.mlir b/mlir/test/Conversion/MathToVCIX/math-to-vcix.mlir
index 3563b2c1cf810..9d4bf7bdb5655 100644
--- a/mlir/test/Conversion/MathToVCIX/math-to-vcix.mlir
+++ b/mlir/test/Conversion/MathToVCIX/math-to-vcix.mlir
@@ -191,3 +191,14 @@ func.func @log_fixed(%a: vector<8 x f32>, %rvl: i64) -> vector<8 x f32> {
   %res = math.log %a : vector<8 x f32>
   return %res : vector<8 x f32>
 }
+
+// -----
+
+// Ensure this case exit gracefully
+
+// CHECK-LABEL:   func.func @no_vector_type
+// CHECK:           math.cos
+func.func @no_vector_type(%arg0: f32) -> f32 {
+  %0 = math.cos %arg0 : f32
+  return %0 : f32
+}
diff --git a/mlir/test/lib/Conversion/MathToVCIX/TestMathToVCIXConversion.cpp b/mlir/test/lib/Conversion/MathToVCIX/TestMathToVCIXConversion.cpp
index 1e45ab57ebcc7..8a01a0af59b22 100644
--- a/mlir/test/lib/Conversion/MathToVCIX/TestMathToVCIXConversion.cpp
+++ b/mlir/test/lib/Conversion/MathToVCIX/TestMathToVCIXConversion.cpp
@@ -25,7 +25,7 @@ namespace {
 /// according to LLVM's encoding:
 /// https://lists.llvm.org/pipermail/llvm-dev/2020-October/145850.html
 static std::pair<unsigned, VectorType> legalizeVectorType(const Type &type) {
-  VectorType vt = cast<VectorType>(type);
+  VectorType vt = dyn_cast<VectorType>(type);
   // To simplify test pass, avoid multi-dimensional vectors.
   if (!vt || vt.getRank() != 1)
     return {0, nullptr};

@joker-eph joker-eph changed the title [mlir] Use dyn_cast instead of cast [mlir] Use dyn_cast instead of cast in MathToVCIX conversion Apr 2, 2025
@CoTinker CoTinker merged commit 7d441d9 into llvm:main Apr 2, 2025
13 checks passed
@CoTinker CoTinker deleted the cast branch April 2, 2025 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[MLIR] crashed on legalizeVectorType() with assertion failure: `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"'
3 participants