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

    <tr>
        <th>Summary</th>
        <td>
            [mlir][TosaToScf] --tosa-to-scf crashed with assertion failure "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>
          anonymousMCS
      </td>
    </tr>
</table>

<pre>
    git version: 3a3b84b180278207731451dfac24f47d02b50e84

system: ```Ubuntu 20.04.6 LTS (Focal Fossa)```

reproduced with: ```mlir-opt --tosa-to-scf a.mlir```

a.mlir:

```
func.func nested @func1() {
  %57 = tensor.empty() : tensor<4x31x31xf32>
  %58 = tensor.empty() : tensor<1x1xi32>
  %11 = tensor.empty() : tensor<4x31x31xf32>
  %30 = tosa.slice %11 {size = array<i64>, start = array<i64>} : (tensor<4x31x31xf32>) -> tensor<*xf32>
  %59 = tosa.scatter %30, %58, %57 : (tensor<*xf32>, tensor<1x1xi32>, tensor<4x31x31xf32>) -> tensor<4x31x31xf32>
 return
}
```

trace:

```
mlir-opt: /data/bin/llvm-project/llvm/include/llvm/Support/Casting.h:566: decltype(auto) llvm::cast(const From&) [with To = mlir::detail::TypedValue<mlir::RankedTensorType>; From = mlir::OpResult]: 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: /data/bin/llvm-project/build/bin/mlir-opt --tosa-to-scf a.mlir
 #0 0x000056176627c33f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x159633f)
 #1 0x00005617662793d4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f053960e420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f05390f900b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f05390d8859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f05390d8729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f05390e9fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000561768677a72 (anonymous namespace)::ScatterOpConverter::matchAndRewrite(mlir::tosa::ScatterOp, mlir::PatternRewriter&) const::'lambda'(mlir::OpBuilder&, mlir::Location, mlir::ValueRange, mlir::ValueRange)::operator()(mlir::OpBuilder&, mlir::Location, mlir::ValueRange, mlir::ValueRange) const TosaToSCF.cpp:0:0
 #8 0x0000561768677b2a llvm::SmallVector<mlir::Value, 6u> llvm::function_ref<llvm::SmallVector<mlir::Value, 6u> (mlir::OpBuilder&, mlir::Location, mlir::ValueRange, mlir::ValueRange)>::callback_fn<(anonymous namespace)::ScatterOpConverter::matchAndRewrite(mlir::tosa::ScatterOp, mlir::PatternRewriter&) const::'lambda'(mlir::OpBuilder&, mlir::Location, mlir::ValueRange, mlir::ValueRange)>(long, mlir::OpBuilder&, mlir::Location, mlir::ValueRange, mlir::ValueRange) TosaToSCF.cpp:0:0
 #9 0x000056176780f18c mlir::scf::buildLoopNest(mlir::OpBuilder&, mlir::Location, mlir::ValueRange, mlir::ValueRange, mlir::ValueRange, mlir::ValueRange, llvm::function_ref<llvm::SmallVector<mlir::Value, 6u> (mlir::OpBuilder&, mlir::Location, mlir::ValueRange, mlir::ValueRange)>) (/data/bin/llvm-project/build/bin/mlir-opt+0x2b2918c)
#10 0x0000561768674c1e (anonymous namespace)::ScatterOpConverter::matchAndRewrite(mlir::tosa::ScatterOp, mlir::PatternRewriter&) const TosaToSCF.cpp:0:0
#11 0x000056176b9c8038 mlir::PatternApplicator::matchAndRewrite(mlir::Operation*, mlir::PatternRewriter&, llvm::function_ref<bool (mlir::Pattern const&)>, llvm::function_ref<void (mlir::Pattern const&)>, llvm::function_ref<mlir::LogicalResult (mlir::Pattern const&)>) (/data/bin/llvm-project/build/bin/mlir-opt+0x6ce2038)
#12 0x0000561768dabc59 (anonymous namespace)::OperationLegalizer::legalize(mlir::Operation*, mlir::ConversionPatternRewriter&) DialectConversion.cpp:0:0
#13 0x0000561768dac5e7 (anonymous namespace)::OperationConverter::convertOperations(llvm::ArrayRef<mlir::Operation*>, llvm::function_ref<void (mlir::Diagnostic&)>) DialectConversion.cpp:0:0
#14 0x0000561768daea54 mlir::applyPartialConversion(mlir::Operation*, mlir::ConversionTarget const&, mlir::FrozenRewritePatternSet const&, llvm::DenseSet<mlir::Operation*, llvm::DenseMapInfo<mlir::Operation*, void>>*) (/data/bin/llvm-project/build/bin/mlir-opt+0x40c8a54)
#15 0x00005617686739f8 (anonymous namespace)::TosaToSCF::runOnOperation() TosaToSCFPass.cpp:0:0
#16 0x0000561768d03e1e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x401de1e)
#17 0x0000561768d042fa mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (/data/bin/llvm-project/build/bin/mlir-opt+0x401e2fa)
#18 0x0000561768d04b24 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x401eb24)
#19 0x0000561768cf53eb performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#20 0x0000561768cf68a4 processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, llvm::ThreadPool*) MlirOptMain.cpp:0:0
#21 0x0000561768cf6a54 mlir::LogicalResult llvm::function_ref<mlir::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&)::'lambda'(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#22 0x0000561768df4ce4 mlir::splitAndProcessBuffer(std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::function_ref<mlir::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::raw_ostream&)>, llvm::raw_ostream&, bool, bool) (/data/bin/llvm-project/build/bin/mlir-opt+0x410ece4)
#23 0x0000561768cefd27 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (/data/bin/llvm-project/build/bin/mlir-opt+0x4009d27)
#24 0x0000561768cf6d7b mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x4010d7b)
#25 0x00005617661b523b main (/data/bin/llvm-project/build/bin/mlir-opt+0x14cf23b)
#26 0x00007f05390da083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#27 0x000056176624cede _start (/data/bin/llvm-project/build/bin/mlir-opt+0x1566ede)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWltz4yj2_zTKCxUXAl0f8uA47fpPVeefVOydVxdCRw47MmgB9cT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