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

    <tr>
        <th>Summary</th>
        <td>
            [MLIR]-pass-pipeline="builtin.module(func.func(convert-affine-for-to-gpu{gpu-block-dims=1 gpu-thread-dims=0}))" triggers Assertion Failure `use_empty() && "Cannot destroy a value that still has uses!"'
        </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/38fffa630ee80163dc65e759392ad29798905679
steps to reproduce:
```
mlir-opt test.mlir -pass-pipeline="builtin.module(func.func(convert-affine-for-to-gpu{gpu-block-dims=1 gpu-thread-dims=0}))"
```
test case:
```
module {
  func.func @main() {
    %alloca = memref.alloca() : memref<1024xf32>
    %c10 = arith.constant 10 : index
    %cst = arith.constant 0.000000e+00 : f32
 %1 = affine.for %arg0 = 0 to %c10 iter_args(%arg1 = %cst) -> (f32) {
 %6 = affine.load %alloca[%arg0] : memref<1024xf32>
      %7 = arith.addf %arg1, %6 : f32
      affine.yield %7 : f32
    }
 return
  }
}
```
crash trace:
```
mlir-opt: /home/workdir/llvm-project-19/mlir/include/mlir/IR/UseDefLists.h:198: mlir::IRObjectWithUseList<mlir::OpOperand>::~IRObjectWithUseList() [OperandType = mlir::OpOperand]: Assertion `use_empty() && "Cannot destroy a value that still has uses!"' 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/test.mlir "-pass-pipeline=builtin.module(func.func(convert-affine-for-to-gpu{gpu-block-dims=1 gpu-thread-dims=0}))"
 #0 0x000055f467484258 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (./mlir-opt+0x1068258)
 #1 0x000055f467481d7e llvm::sys::RunSignalHandlers() (./mlir-opt+0x1065d7e)
 #2 0x000055f467484c68 SignalHandler(int) Signals.cpp:0:0
 #3 0x000073597db55520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000073597dba99fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000073597db55476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000073597db3b7f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000073597db3b71b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000073597db4ce96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000055f46a7973a7 mlir::Block::~Block() (./mlir-opt+0x437b3a7)
#10 0x000055f46a86b0a6 llvm::iplist_impl<llvm::simple_ilist<mlir::Block>, llvm::ilist_traits<mlir::Block>>::erase(llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Block, true, false, void, false, void>, false, false>) (./mlir-opt+0x444f0a6)
#11 0x000055f46a869b9b mlir::Region::~Region() (./mlir-opt+0x444db9b)
#12 0x000055f46a8565a8 mlir::Operation::~Operation() (./mlir-opt+0x443a5a8)
#13 0x000055f46a85e7f2 llvm::iplist_impl<llvm::simple_ilist<mlir::Operation>, llvm::ilist_traits<mlir::Operation>>::erase(llvm::ilist_iterator<llvm::ilist_detail::node_options<mlir::Operation, true, false, void, false, void>, false, false>) (./mlir-opt+0x44427f2)
#14 0x000055f469fe3691 mlir::convertAffineLoopNestToGPULaunch(mlir::affine::AffineForOp, unsigned int, unsigned int) (./mlir-opt+0x3bc7691)
#15 0x000055f469fe1f01 (anonymous namespace)::ForLoopMapper::runOnOperation() SCFToGPUPass.cpp:0:0
#16 0x000055f46a6b7b1f mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x429bb1f)
#17 0x000055f46a6b8302 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x429c302)
#18 0x000055f46a6bda1e auto void mlir::parallelForEach<__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0>(mlir::MLIRContext*, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, __gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>, mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::$_0&&)::'lambda'(__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>&&)::operator()<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&>(__gnu_cxx::__normal_iterator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo*, std::vector<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo, std::allocator<mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo>>>&&) const Pass.cpp:0:0
#19 0x000055f46a6b9b0b mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (./mlir-opt+0x429db0b)
#20 0x000055f46a6b7c7c mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (./mlir-opt+0x429bc7c)
#21 0x000055f46a6b8302 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (./mlir-opt+0x429c302)
#22 0x000055f46a6baaae mlir::PassManager::run(mlir::Operation*) (./mlir-opt+0x429eaae)
#23 0x000055f46a6b35d2 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#24 0x000055f46a6b323b 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 0x000055f46a75cf25 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+0x4340f25)
#26 0x000055f46a6ae432 mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (./mlir-opt+0x4292432)
#27 0x000055f46a6ae6e3 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42926e3)
#28 0x000055f46a6ae8f2 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (./mlir-opt+0x42928f2)
#29 0x000055f467463477 main (./mlir-opt+0x1047477)
#30 0x000073597db3cd90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#31 0x000073597db3ce40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#32 0x000055f467462fe5 _start (./mlir-opt+0x1046fe5)
Aborted (core dumped)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWstu3DjWfhp6Q1RBInVdeFG-1P8HiMeGk8YsC5R4pOKEIjUklbY38-wDSqqyJFel455c0I0YTixR5Dnf-c6FlEhmragVwCWKr1B8c8E6t9fm8klYpurgotD8-fIjWIe1wqVuGuEQ3eC9c61FdIPIFpFtLdy-K9albhDZSvn58GfVGv0vKB0i23Eo2dKsqiqW0AAgC8KE8jKJIY1zmhPGSZ7mWR7ESZqj4AYFG-ugtdhpbKA1mncleKX9I5QE429_20hhVrp12IF1a3-HVy2zdtWKFqRQgOgNIqTohHRCrRvNOwmIZFWnyrX_D5Gs1OozGLdiVSUUrCptVk6v6rZD6VXddqtC6vLTiovGInoTYt_k9gYYP7QFKL1BJO9_yUmYHh0umT1vRw8Mo_RquMf4iBCjKGiYUIhkiOTTLhgjEjMpdckwoje4gcZAtR5aDt3pZmxH9DoMSPRUUYLo7UxGGQa9AGaE269LraxjyuG-dY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