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

    <tr>
        <th>Summary</th>
        <td>
            [mlir] --async-parallel-for crashed with assertion failure "Invalid index!"
        </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: 83888a5404d46667647fe36d6fa510d075ed57ea

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

reproduced with: ```mlir-opt --async-parallel-for a.mlir```

a.mlir:
```
llvm.func @func1() {
  %c0 = arith.constant 0 : index
  %c22 = arith.constant 22 : index
  %c1 = arith.constant 1 : index
  %53 = tensor.empty() : tensor<22xf32>
  %54 = bufferization.to_memref %53 : memref<22xf32>
 %alloc_4 = memref.alloc() {alignment = 64 : i64} : memref<22xf32>
 scf.parallel (%arg0) = (%c0) to (%c22) step (%c1) {
    %81 = memref.load %54[%arg0] : memref<22xf32>
    memref.store %81, %alloc_4[%arg0] : memref<22xf32>
  }
 llvm.return
}
```

trace:
```
mlir-opt: /data/bin/llvm-project/llvm/include/llvm/ADT/ArrayRef.h:257: const T& llvm::ArrayRef<T>::operator[](size_t) const [with T = mlir::StringAttr; size_t = long unsigned int]: Assertion `Index < Length && "Invalid index!"' 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 --async-parallel-for a.mlir
 #0 0x0000561304d3284f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x15dd84f)
 #1 0x0000561304d2f8a4 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f9f6e293420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f9f6dd7e00b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f9f6dd5d859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f9f6dd5d729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f9f6dd6efd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x000056130533b605 (/data/bin/llvm-project/build/bin/mlir-opt+0x1be6605)
 #8 0x000056130533b74f mlir::func::FuncOp::getAttributeNameForIndex(mlir::OperationName, unsigned int) (.constprop.0) FuncOps.cpp:0:0
 #9 0x000056130533d98e mlir::func::FuncOp::build(mlir::OpBuilder&, mlir::OperationState&, llvm::StringRef, mlir::FunctionType, llvm::ArrayRef<mlir::NamedAttribute>, llvm::ArrayRef<mlir::DictionaryAttr>) (/data/bin/llvm-project/build/bin/mlir-opt+0x1be898e)
#10 0x000056130534c262 mlir::func::FuncOp::create(mlir::Location, llvm::StringRef, mlir::FunctionType, llvm::ArrayRef<mlir::NamedAttribute>) (/data/bin/llvm-project/build/bin/mlir-opt+0x1bf7262)
#11 0x0000561305176d34 createParallelComputeFunction(mlir::scf::ParallelOp, (anonymous namespace)::ParallelComputeFunctionBounds const&, unsigned int, mlir::PatternRewriter&) AsyncParallelFor.cpp:0:0
#12 0x000056130517a007 (anonymous namespace)::AsyncParallelForRewrite::matchAndRewrite(mlir::scf::ParallelOp, mlir::PatternRewriter&) const::'lambda0'(mlir::OpBuilder&, mlir::Location)::operator()(mlir::OpBuilder&, mlir::Location) const AsyncParallelFor.cpp:0:0
#13 0x00005613063626eb mlir::scf::IfOp::build(mlir::OpBuilder&, mlir::OperationState&, mlir::Value, llvm::function_ref<void (mlir::OpBuilder&, mlir::Location)>, llvm::function_ref<void (mlir::OpBuilder&, mlir::Location)>) (/data/bin/llvm-project/build/bin/mlir-opt+0x2c0d6eb)
#14 0x00005613051763bf (anonymous namespace)::AsyncParallelForRewrite::matchAndRewrite(mlir::scf::ParallelOp, mlir::PatternRewriter&) const AsyncParallelFor.cpp:0:0
#15 0x000056130a5d0b68 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+0x6e7bb68)
#16 0x00005613079768ac (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#17 0x000056130797ad1b mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/bin/llvm-project/build/bin/mlir-opt+0x4225d1b)
#18 0x000056130516f42c (anonymous namespace)::AsyncParallelForPass::runOnOperation() AsyncParallelFor.cpp:0:0
#19 0x00005613078c12ee mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x416c2ee)
#20 0x00005613078c17ca 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+0x416c7ca)
#21 0x00005613078c1ff4 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x416cff4)
#22 0x00005613078b2d7b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#23 0x00005613078b4234 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
#24 0x00005613078b43e4 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
#25 0x00005613079b33a4 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+0x425e3a4)
#26 0x00005613078ace97 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+0x4157e97)
#27 0x00005613078b4531 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x415f531)
#28 0x00005613078b4996 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x415f996)
#29 0x0000561304c69dcb main (/data/bin/llvm-project/build/bin/mlir-opt+0x1514dcb)
#30 0x00007f9f6dd5f083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#31 0x0000561304d02e1e _start (/data/bin/llvm-project/build/bin/mlir-opt+0x15ade1e)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWl9z46oV_zTKCxMPAv19yIMSr9vMbJrMJm0fPUggmy4GFdDe-H76Dki2JcVZe-O9t9vubBIbDodzfucvQsQYvpKM3QTxbRDPr0hr10rfEKnkdqNa83D3fFUqur1ZcQu-MW24kgEuQIazLCNxBCMaJUmSJlFaM5zQpCZxCClMY0bjlJEAzgNYdL_N1li2cauDBHb__1620rYAwRmMZgn4_PIMApQtVEUEWChjSIDyPfGQl2aNVrStGAW_cbseMd0Irq9VY8H1NTFbWV03RBMhmLiulQZk5uaPMu2ncP91QiPEt82sbmUFggi6v2GAsgDlIEhvOwoAAhRXEAR4Dojmdj2rlDSWSAvcYAG4pOx1SIvQMWI_eoQ6PEYcHqWNsae1TBqlZ2zT2O1OWlz0wwG-Q-i1xijAn4ZLI7-0bOuaaf47sVzJmVXLDdtoVu-ZF6AbOMIlQDERQlXLjlNHN_NDB8iI4Cu5YdJ6miTq1EiiIJ1_n7up6tnOosDzi4lewU63eT9S-e9W7b4i5L4by5rdSDgxndc9C4cSC0Voh4iLjn6b-IR4AOyWG6s067gG6G6Ayo9wC9J5_9H7n2a21bL3z93UUWe2mlTsPV_ehYiPG7SgxJIALUouA7Rw-1w3Wv2LVbb_GqAFl5VoKTsMFPMX91trsv3C6pkLQRSnjqF3TfASoMTL7GTAxY4wwHcvTj0_qBqmiVW6Sz4Bygz_nS2ts0zHJIhvXXiDl84sfXTi4tlqLleFtTrAt6Bb5UmEkivQSp_UKODSOr64AIUxTDtPdmni3gULCPAd-Mzkyq5BgBInbYDQvfxGBKd9PKEwcI6TgppwweisA-_p86fi-RMwbbnhFhBQtiugWaO0dQ63trYxTkq0CNBixe26LWeV2hyQmwDMjWmZCdACEOk29jgDu2ag0sSsQUmqr96Y_fbPllRfAW03zd66cAb8vyetVppsANGr1oWWOcO-ZcsF3U-elTt3UY4hgK8QQhgnIYYRxSiL6oHNzdZ0H540l9bL_eK9EmUHIk1-Wyp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