Skip to content

[mlir][tensor] double --eliminate-empty-tensors crashed with assertion failure "expected 'op' to have no uses" #67977

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ghost opened this issue Oct 2, 2023 · 1 comment
Assignees

Comments

@ghost
Copy link

ghost commented Oct 2, 2023

git version: 9580468

system: Ubuntu 20.04.6 LTS (Focal Fossa)

reproduced with: mlir-opt --eliminate-empty-tensors --eliminate-empty-tensors a.mlir

a.mlir:

%44 = tensor.empty() : tensor<26xi32>
%9 = tensor.empty() : tensor<26xi32>
%45 = linalg.copy ins(%9 : tensor<26xi32>) outs(%44 : tensor<26xi32>) -> tensor<26xi32>

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 --eliminate-empty-tensors --eliminate-empty-tensors a.mlir
 #0 0x0000560ba180516f llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/data/bin/llvm-project/build/bin/mlir-opt+0x158f16f)
 #1 0x0000560ba1802204 SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fc60fcc7420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #3 0x00007fc60f7b200b raise (/lib/x86_64-linux-gnu/libc.so.6+0x4300b)
 #4 0x00007fc60f791859 abort (/lib/x86_64-linux-gnu/libc.so.6+0x22859)
 #5 0x00007fc60f791729 (/lib/x86_64-linux-gnu/libc.so.6+0x22729)
 #6 0x00007fc60f7a2fd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
 #7 0x0000560ba447c939 mlir::RewriterBase::eraseOp(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x4206939)
 #8 0x0000560ba4478563 mlir::RewriterBase::replaceOp(mlir::Operation*, mlir::ValueRange) (/data/bin/llvm-project/build/bin/mlir-opt+0x4202563)
 #9 0x0000560ba1cda49b mlir::bufferization::eliminateEmptyTensors(mlir::RewriterBase&, mlir::Operation*, mlir::bufferization::OneShotAnalysisState&)::'lambda'(mlir::bufferization::SubsetInsertionOpInterface)::operator()(mlir::bufferization::SubsetInsertionOpInterface) const (.isra.0) EmptyTensorElimination.cpp:0:0
#10 0x0000560ba1cdb117 _ZN4llvm12function_refIFN4mlir10WalkResultEPNS1_9OperationEEE11callback_fnIZNS1_6detail4walkILNS1_9WalkOrderE1ENS1_15ForwardIteratorEZNS1_13bufferization21eliminateEmptyTensorsERNS1_12RewriterBaseES4_RNSC_20OneShotAnalysisStateEEUlNSC_26SubsetInsertionOpInterfaceEE_SH_S2_EENSt9enable_ifIXaantsrSt11disjunctionIJSt7is_sameIT2_S4_ESL_ISM_PNS1_6RegionEESL_ISM_PNS1_5BlockEEEE5valuesrSL_IT3_S2_E5valueESV_E4typeES4_OT1_EUlS4_E_EES2_lS4_ EmptyTensorElimination.cpp:0:0
#11 0x0000560ba1cdb66a (anonymous namespace)::EmptyTensorElimination::runOnOperation() EmptyTensorElimination.cpp:0:0
#12 0x0000560ba426117e mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (/data/bin/llvm-project/build/bin/mlir-opt+0x3feb17e)
#13 0x0000560ba426165a 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+0x3feb65a)
#14 0x0000560ba4261e84 mlir::PassManager::run(mlir::Operation*) (/data/bin/llvm-project/build/bin/mlir-opt+0x3febe84)
#15 0x0000560ba425275b performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#16 0x0000560ba4253c14 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
#17 0x0000560ba4253dc4 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
#18 0x0000560ba43522b4 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+0x40dc2b4)
#19 0x0000560ba424d1e7 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+0x3fd71e7)
#20 0x0000560ba42540eb mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (/data/bin/llvm-project/build/bin/mlir-opt+0x3fde0eb)
#21 0x0000560ba173e1cb main (/data/bin/llvm-project/build/bin/mlir-opt+0x14c81cb)
#22 0x00007fc60f793083 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x24083)
#23 0x0000560ba17d5d9e _start (/data/bin/llvm-project/build/bin/mlir-opt+0x155fd9e)
Aborted (core dumped)
@ghost ghost changed the title [mlir][tosor] double --eliminate-empty-tensors crashed with assertion failure "expected 'op' to have no uses" [mlir][tensor] double --eliminate-empty-tensors crashed with assertion failure "expected 'op' to have no uses" Oct 2, 2023
@github-actions github-actions bot added the mlir label Oct 2, 2023
lipracer added a commit to lipracer/llvm-project that referenced this issue Oct 4, 2023
1) fix empty-tensor-elimination pass crash
2) improve linlg.copy op's canonicalization pattern
3) add indentation when emit regionBuilder func
@matthias-springer matthias-springer self-assigned this Oct 5, 2023
@lipracer
Copy link
Member

lipracer commented Oct 5, 2023

simpler test:

func.func @main() -> tensor<26xi32>{
  %0 = tensor.empty() : tensor<26xi32>
  %1 = linalg.copy ins(%0 : tensor<26xi32>) outs(%0 : tensor<26xi32>) -> tensor<26xi32>
  return %1 : tensor<26xi32>
}

with command:mlir-opt --eliminate-empty-tensors a.mlir

Algebraic optimization
mlir-opt --canonicalize --eliminate-empty-tensors a.mlir
is expected to eliminate empty operations, but it seems to only take effect on buffers. I have also fixed this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants