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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]-tosa-to-arithtriggers Assertion Failure `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"'
        </td>
    </tr>

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

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

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

<pre>
    Test on commit: (https://github.com/llvm/llvm-project/commit/18f0f709345cc7e611c4f944832edb71284caacb)
steps to reproduce:
```
mlir-opt test.mlir -tosa-to-arith
```
test case:
```
func.func @pad_determine_val_i32(%arg0: tensor<?x?xi32> {bufferization.access = "read"}, %arg1: tensor<2x2xi32> {bufferization.access = "none"}) -> tensor<?x?xi32> {
    %0 = "tosa.const"() <{value = dense_resource<__elided__> : tensor<2x2xi32>}> : () -> tensor<2x2xi32>
    %1 = tosa.pad %arg0, %0 {__inplace_operands_attr__ = ["false", "false"]} : (tensor<?x?xi32>, tensor<2x2xi32>) -> tensor<?x?xi32>
    return {__inplace_operands_attr__ = ["true"]} %1 : tensor<?x?xi32>
}
```
crash trace:
```
mlir-opt: /home/workdir/llvm-project-19/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From &) [To = mlir::DenseElementsAttr, From = mlir::Attribute]: Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible 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: ./mlir-opt /home/workdir/test5.mlir -tosa-to-arith
 #0 0x000060b08d7e8098 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x1062098)
 #1 0x000060b08d7e5bbe llvm::sys::RunSignalHandlers() (./mlir-opt+0x105fbbe)
 #2 0x000060b08d7e8aa8 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007aaf68eaf520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007aaf68f039fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007aaf68eaf476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007aaf68e957f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007aaf68e9571b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007aaf68ea6e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000060b08fd34ea5 mlir::tosa::PadOp::fold(mlir::tosa::PadOpGenericAdaptor<llvm::ArrayRef<mlir::Attribute>>) (./mlir-opt+0x35aeea5)
#10 0x000060b08fcfe5c5 llvm::LogicalResult mlir::Op<mlir::tosa::PadOp, mlir::OpTrait::ZeroRegions, mlir::OpTrait::OneResult, mlir::OpTrait::OneTypedResult<mlir::RankedTensorType>::Impl, mlir::OpTrait::ZeroSuccessors, mlir::OpTrait::AtLeastNOperands<2u>::Impl, mlir::OpTrait::OpInvariants, mlir::BytecodeOpInterface::Trait, mlir::InferShapedTypeOpInterface::Trait, mlir::OpTrait::InferShapedTypeOpAdaptor, mlir::ConditionallySpeculatable::Trait, mlir::OpTrait::AlwaysSpeculatableImplTrait, mlir::MemoryEffectOpInterface::Trait, mlir::tosa::TosaOp::Trait>::foldSingleResultHook<mlir::tosa::PadOp>(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (./mlir-opt+0x35785c5)
#11 0x000060b08fcfd585 mlir::RegisteredOperationName::Model<mlir::tosa::PadOp>::foldHook(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (./mlir-opt+0x3577585)
#12 0x000060b090bb115d mlir::Operation::fold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (./mlir-opt+0x442b15d)
#13 0x000060b090bb14f3 mlir::Operation::fold(llvm::SmallVectorImpl<mlir::OpFoldResult>&) (./mlir-opt+0x442b4f3)
#14 0x000060b090af509b mlir::OpBuilder::tryFold(mlir::Operation*, llvm::SmallVectorImpl<mlir::Value>&) (./mlir-opt+0x436f09b)
#15 0x000060b090a6f264 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#16 0x000060b090a6e677 mlir::OperationConverter::convert(mlir::ConversionPatternRewriter&, mlir::Operation*) (./mlir-opt+0x42e8677)
#17 0x000060b090a6f81f mlir::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>) (./mlir-opt+0x42e981f)
#18 0x000060b090a7712b mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, mlir::ConversionConfig) (./mlir-opt+0x42f112b)
#19 0x000060b0903b4d06 (anonymous namespace)::TosaToArith::runOnOperation() TosaToArithPass.cpp:0:0
#20 0x000060b090a1179f mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x428b79f)
#21 0x000060b090a11f82 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x428bf82)
#22 0x000060b090a1472e mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x428e72e)
#23 0x000060b090a0d252 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#24 0x000060b090a0cebb 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
#25 0x000060b090ab6725 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) (./mlir-opt+0x4330725)
#26 0x000060b090a080b2 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x42820b2)
#27 0x000060b090a08363 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x4282363)
#28 0x000060b090a08572 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x4282572)
#29 0x000060b08d7c72e7 main (./mlir-opt+0x10412e7)
#30 0x00007aaf68e96d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#31 0x00007aaf68e96e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#32 0x000060b08d7c6e55 _start (./mlir-opt+0x1040e55)
Aborted (core dumped)
```

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWl9T4zgS_zTmRUVKlv8_8BACuZ2qYaGA2od7ccl2O-hQJJ8kz5D99FeSncQKSYCt29u7mxpm4rjV_eufulstCao1WwmAqyC5DpKbC9qbF6mu3pimYoUvKtlsrp5BGyQFquV6zUwQzVFA8hd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