The given test fails due to error below.
The following error is why the test is failing. One memref.store and two memref.load are consumers of the loop index for which I do RAUW. memref.store is first in the list. If I RAUW on this the loop of llvm::make early inc range(threadIdx.getUsers()) does not return two memref.load as users. They remain unchanged. I'm not really certain why.
This change applies RAUW after collecting the users. If a better solution exists, I would be happy to implement it.
mlir-opt: ...llvm-project/mlir/include/mlir/IR/UseDefLists.h:175: 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.
nit: for (OpOperand *operand : uses) would be simpler