<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/119364>119364</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [mlir] --canonicalize crashes
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          Emilyaxe
      </td>
    </tr>
</table>

<pre>
    git version: 953838dceaf

system: `Ubuntu 18.04.6 LTS`

reproduce with: `mlir-opt --canonicalize  a.mlir`


a.mlir: 
``` 
  func.func @func2(%arg0: tensor<1x20x1xi32>, %arg1: tensor<1x20x1xi32>, %arg2: tensor<1x20x1xi32>) {
    %0 = "tosa.const"() <{value = dense<[0, 2, 1]> : tensor<3xi32>}> : () -> tensor<3xi32>
    %4 = "tosa.const"() <{value = dense<-3060> : tensor<1x20x1xi32>}> : () -> tensor<1x20x1xi32>
    %47 = tosa.cast %4 : (tensor<1x20x1xi32>) -> tensor<1x20x1xf32>
    %48 = tosa.transpose %47, %0 : (tensor<1x20x1xf32>, tensor<3xi32>) -> tensor<1x1x20xi32>
    %49 = tosa.matmul %47, %48 : (tensor<1x20x1xf32>, tensor<1x1x20xi32>) -> tensor<1x20x20xi32>
    return 
  }
``` 
stack trace:

``` 
mlir-opt: /data/szy/MLIR/llvm-release/llvm-project/mlir/lib/IR/BuiltinAttributes.cpp:961: static DenseElementsAttr mlir::DenseElementsAttr::get(ShapedType, ArrayRef<Attribute>): Assertion `floatAttr.getType() == eltType && "expected float attribute type to equal element type"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt a.mlir --canonicalize
 #0 0x0000563c1d119158 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1136158)
 #1 0x0000563c1d116c6e llvm::sys::RunSignalHandlers() (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1133c6e)
 #2 0x0000563c1d119aed SignalHandler(int) Signals.cpp:0:0
 #3 0x00007ff262216420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #4 0x00007ff26185300b raise /build/glibc-LcI20x/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #5 0x00007ff261832859 abort /build/glibc-LcI20x/glibc-2.31/stdlib/abort.c:81:7
 #6 0x00007ff261832729 get_sysdep_segment_value /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:509:8
 #7 0x00007ff261832729 _nl_load_domain /build/glibc-LcI20x/glibc-2.31/intl/loadmsgcat.c:970:34
 #8 0x00007ff261843fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #9 0x0000563c2064c7e4 mlir::DenseElementsAttr::get(mlir::ShapedType, llvm::ArrayRef<mlir::Attribute>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x46697e4)
#10 0x0000563c1f7591c6 mlir::tosa::ReshapeOp::fold(mlir::tosa::ReshapeOpGenericAdaptor<llvm::ArrayRef<mlir::Attribute>>) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x37761c6)
#11 0x0000563c1f72d93f llvm::LogicalResult mlir::Op<mlir::tosa::ReshapeOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::RankedTensorType>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::OneOperand, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::InferTypeOpInterface::Trait, mlir::InferShapedTypeOpInterface::Trait, mlir::OpTrait::InferShapedTypeOpAdaptor, mlir::OpTrait::InferTensorType, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::AlwaysSpeculatableImplTrait, mlir::MemoryEffectOpInterface::Trait, mlir::tosa::TosaOp::Trait>::foldSingleResultHook<mlir::tosa::ReshapeOp>(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x374a93f)
#12 0x0000563c1f72c570 mlir::RegisteredOperationName::Model<mlir::tosa::ReshapeOp>::foldHook(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x3749570)
#13 0x0000563c206ffadd mlir::Operation::fold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x471cadd)
#14 0x0000563c206ffe83 mlir::Operation::fold(llvm::SmallVectorImpl<mlir::OpFoldResult>&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x471ce83)
#15 0x0000563c205d4314 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#16 0x0000563c205d162f mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45ee62f)
#17 0x0000563c20577acb (anonymous namespace)::Canonicalizer::runOnOperation() Canonicalizer.cpp:0:0
#18 0x0000563c2055a2b6 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x45772b6)
#19 0x0000563c2055abe0 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x4577be0)
#20 0x0000563c2055d1b2 mlir::PassManager::run(mlir::Operation*) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x457a1b2)
#21 0x0000563c20555a5a performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#22 0x0000563c205556ad llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>::callback_fn<mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&)::$_0>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#23 0x0000563c20601b25 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x461eb25)
#24 0x0000563c2054f695 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x456c695)
#25 0x0000563c2054f93f mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x456c93f)
#26 0x0000563c2054fc6e mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x456cc6e)
#27 0x0000563c1d0f9c47 main (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x1116c47)
#28 0x00007ff261834083 __libc_start_main /build/glibc-LcI20x/glibc-2.31/csu/../csu/libc-start.c:342:3
#29 0x0000563c1d0f97be _start (/data/szy/MLIR/llvm-release/llvm-project/build/bin/mlir-opt+0x11167be)

``` 
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWllz47gR_jX0C8oqErzEBz_Ih3ZdNY5d9iSpyosKBJo0MhDABUCPtb8-BZASD5-zWWWzOzWWTbKB7u_rAw1CxBheS4CzID0P0ssT0tpHpc-utlzsyDOclIrtzmpu0RNow5UM4hUq0ngZLxkFUgXhKghXZmcsbN2jIAv_XrbStihaLsJkkaEvXx-CLOzkNDRasZYC-s7tYy-_FVyfqsai01NKpJKcEsF_BYTIwj06DA7CVX_HjQtX7oH_7y4QqlpJF-4DBUnofuMALwOcEl2HboQFaZQO4ovoGYfP0TOPcRBfBfgCdULRZ4Twe0IFCvJzbwty4iEK4ksUYGyVIQuqpLEB7owqUBBfBPn5ExEteDEG0oC7mZ6HTh12H1GQXgbxFZoojff68sOzfs5Td_1S7mBQ8lsMOo3DLHxhxBT5B5ZMhQdzcq-oM4YYuzfRz_I2x6_OXc3nXg5zW02kaZSBTmnvzPAtTdXB5S-pfEW9H_UCWjGo3xK7bcVEt7fus8qnKl4nYG6CBttq2eWF884sWYwl9BuymlAI4j61JgL7lOysXDNiSYDX5tddgNc3X67vA7wW4ml7qkEAMbC_bLT6N1Ab4LVPU7wWvAzw2suft1xYLlfWal62FsyCNk0Qr4rMJ56xxHKKLl3UXQnYgrTGyaI-4YN49eJZd7sGG-DlwyNpgH3dNeDIW2lNdvdQBfHFQWHHntO1Mga05Uq66lMJRawTWtRgu_F9Plw6F4LwN1GAswBnLnnguQFqgSE_EpH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