Issue 73547
Summary [mlir] --canonicalize crashed with assertion failure "expected 'op' to have no uses"
Labels mlir
Assignees
Reporter anonymousMCS
    git version: 5bd643e1456bd2acc53ac0bf594d285be89a44fe

system: Ubuntu 20.04.6 LTS (Focal Fossa)

reproduced with: ```mlir-opt --canonicalize a.mlir```

a.mlir:
```
#map = affine_map<(d0, d1, d2) -> (d0, d1, d2)>
#map2 = affine_map<(d0, d1) -> (d0, d1)>
#map8 = affine_map<(d0, d1, d2) -> (d1)>
func.func @func2(%arg0: memref<?xf32>, %arg1: tensor<6xi32>) {
  %c1_12 = arith.constant 1 : index
  %c2 = arith.constant 2 : index
  %c6 = arith.constant 6 : index
  %c9 = arith.constant 9 : index
  %c12 = arith.constant 12 : index
  %c15 = arith.constant 15 : index
  %c22_15 = arith.constant 22 : index
  %c23 = arith.constant 23 : index
  %c31 = arith.constant 31 : index
 %alloc_25 = memref.alloc(%c6) {alignment = 64 : i64} : memref<?x6xf32>
 %9 = bufferization.to_tensor %alloc_25 : memref<?x6xf32>
  %18 = index.shru %c22_15, %c15
  %20 = index.divs %18, %c31
  %cst_63 = arith.constant 1.27479398E+18 : f32
  %c1_68 = arith.constant 1 : index
  %54 = tosa.reduce_sum %9 {axis = 0 : i32} : (tensor<?x6xf32>) -> tensor<1x6xf32>
  %56 = linalg.generic {indexing_maps = [#map2, #map2], iterator_types = ["parallel", "parallel"]} ins(%54 : tensor<1x6xf32>) outs(%54 : tensor<1x6xf32>) {
  ^bb0(%in: f32, %out: f32):
    %124 = math.log2 %in : f32
    linalg.yield %124 : f32
  } -> tensor<1x6xf32>
  %alloc_71 = memref.alloc() : memref<14x27x4xf32>
 %59 = memref.atomic_rmw assign %cst_63, %alloc_71[%20, %c9, %c1_12] : (f32, memref<14x27x4xf32>) -> f32
  %78 = index.shru %c12, %20
  %79 = index.ceildivu %c23, %c1_68
  %83 = math.sqrt %59 : f32
  %cst_83 = arith.constant 0x7F800000 : f32
  %alloc_86 = memref.alloc(%79) {alignment = 64 : i64} : memref<14x?x4xf32>
  %98 = bufferization.to_tensor %alloc_86 : memref<14x?x4xf32>
  %alloc_87 = memref.alloc(%78) {alignment = 64 : i64} : memref<?xf32>
  %99 = bufferization.to_tensor %alloc_87 : memref<?xf32>
  %alloc_88 = memref.alloc(%20) : memref<?xf32>
 %alloc_89 = memref.alloc(%c2) {alignment = 64 : i64} : memref<14x?x4xf32>
 %100 = bufferization.to_tensor %alloc_89 : memref<14x?x4xf32>
  %101 = linalg.generic {indexing_maps = [#map, #map8, #map8, #map], iterator_types = ["parallel", "parallel", "parallel"]} ins(%98, %99, %alloc_88 : tensor<14x?x4xf32>, tensor<?xf32>, memref<?xf32>) outs(%100 : tensor<14x?x4xf32>) {
  ^bb0(%in: f32, %in_100: f32, %in_101: f32, %out: f32):
    linalg.yield %cst_83 : f32
  } -> tensor<14x?x4xf32>
 %111 = linalg.generic {indexing_maps = [#map, #map], iterator_types = ["parallel", "parallel", "parallel"]} ins(%98 : tensor<14x?x4xf32>) outs(%101 : tensor<14x?x4xf32>) {
  ^bb0(%in: f32, %out: f32):
    %124 = math.absf %83 : f32
    linalg.yield %124 : f32
  } -> tensor<14x?x4xf32>
 return
}
```


trace:
```
mlir-opt: /data/bin/llvm-project/mlir/lib/IR/PatternMatch.cpp:307: virtual void mlir::RewriterBase::eraseOp(mlir::Operation*): Assertion `op->use_empty() && "expected 'op' to have no 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: /data/bin/llvm-project/build/bin/mlir-opt --canonicalize a.mlir
 #0 0x000055644e81222f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x161922f)
 #1 0x000055644e80f284 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f8324c36420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007f832472100b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007f8324700859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007f8324700729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007f8324711fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000556451644569 mlir::RewriterBase::eraseOp(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x444b569)
 #8 0x000055644f01e307 (anonymous namespace)::EraseDeadLinalgOp::matchAndRewrite(mlir::linalg::LinalgOp, mlir::PatternRewriter&) const LinalgOps.cpp:0:0
 #9 0x000055645414c7a8 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+0x6f537a8)
#10 0x00005564514db45c (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#11 0x00005564514df8cb mlir::applyPatternsAndFoldGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (/data/bin/llvm-project/build/bin/mlir-opt+0x42e68cb)
#12 0x0000556451444b9a (anonymous namespace)::Canonicalizer::runOnOperation() Canonicalizer.cpp:0:0
#13 0x0000556451425aee mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x422caee)
#14 0x0000556451425fca 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+0x422cfca)
#15 0x00005564514267f4 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x422d7f4)
#16 0x0000556451417563 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#17 0x0000556451418a34 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
#18 0x0000556451418be4 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
#19 0x0000556451517ed4 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+0x431eed4)
#20 0x0000556451411447 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+0x4218447)
#21 0x0000556451418d31 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x421fd31)
#22 0x0000556451419196 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x4220196)
#23 0x000055644e74997b main (/data/bin/llvm-project/build/bin/mlir-opt+0x155097b)
#24 0x00007f8324702083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#25 0x000055644e7e258e _start (/data/bin/llvm-project/build/bin/mlir-opt+0x15e958e)
Aborted (core dumped)
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to