llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[mlir][bug][Vector] extract-through-rank-zero transpose builds an empty permutation map

Open Kiritobl opened this issue 1 month ago • 2 comments

Version

LLVM/MLIR 24.0.0git, commit c275ebd64bf5b05e36a3a8e8b8daa32ba9a52aac (optimized build with assertions).

Bug Description

Observed failure: extract-through-rank-zero transpose builds an empty permutation map. The input passes verification without the pass, but the command below crashes.

Likely Cause

vector.extract [] on the result of a legal rank-zero vector.transpose [] enters ExtractOp::fold's transpose handling. It calls AffineMap::getPermutationMap with an empty permutation; that API asserts because it requires a non-empty list. The folding path needs to handle the rank-zero case.

Steps to Reproduce

mlir-opt --allow-unregistered-dialect '--pass-pipeline=builtin.module(func.func(convert-vector-to-scf{full-unroll=true lower-scalable=true}))' reproducer.mlir -o /dev/null

Reproducer (reproducer.mlir)

module {
  func.func @main(%arg: vector<f32>) -> f32 {
    %t = vector.transpose %arg, [] : vector<f32> to vector<f32>
    %x = vector.extract %t[] : f32 from vector<f32>
    return %x : f32
  }
}

Stack Dump (full stderr)

mlir-opt: mlir/lib/IR/AffineMap.cpp:262: static mlir::AffineMap mlir::AffineMap::getPermutationMap(llvm::ArrayRef<unsigned int>, mlir::MLIRContext*): Assertion `!permutation.empty() && "Cannot create permutation map from empty permutation vector"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: mlir-opt --allow-unregistered-dialect "--pass-pipeline=builtin.module(func.func(convert-vector-to-scf{full-unroll=true lower-scalable=true}))" reproducer.mlir -o /dev/null
 #0 0x000055c509746699 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (mlir-opt+0x1fa0699)
 #1 0x000055c509742e9c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f9ce9c)
 #2 0x000055c509743006 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x00007f7e18812520 (libc.so.6+0x42520)
 #4 0x00007f7e188669bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f7e188669bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #6 0x00007f7e188669bc pthread_kill ./nptl/pthread_kill.c:89:10
 #7 0x00007f7e18812476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #8 0x00007f7e187f87f3 abort ./stdlib/abort.c:81:7
 #9 0x00007f7e187f871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#10 0x00007f7e18809e96 (libc.so.6+0x39e96)
#11 0x000055c511eb897d (mlir-opt+0xa71297d)
#12 0x000055c511eb8a73 mlir::AffineMap::getPermutationMap(llvm::ArrayRef<long>, mlir::MLIRContext*) (mlir-opt+0xa712a73)
#13 0x000055c510489deb mlir::vector::ExtractOp::fold(mlir::vector::ExtractOpGenericAdaptor<llvm::ArrayRef<mlir::Attribute>>) (mlir-opt+0x8ce3deb)
#14 0x000055c51048b0df mlir::RegisteredOperationName::Model<mlir::vector::ExtractOp>::foldHook(mlir::Operation*, llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (mlir-opt+0x8ce50df)
#15 0x000055c511fbce34 mlir::Operation::fold(llvm::ArrayRef<mlir::Attribute>, llvm::SmallVectorImpl<mlir::OpFoldResult>&) (mlir-opt+0xa816e34)
#16 0x000055c511fbd2db mlir::Operation::fold(llvm::SmallVectorImpl<mlir::OpFoldResult>&) (mlir-opt+0xa8172db)
#17 0x000055c511ba7421 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#18 0x000055c511bab336 mlir::applyPatternsGreedily(mlir::Region&, mlir::FrozenRewritePatternSet const&, mlir::GreedyRewriteConfig, bool*) (mlir-opt+0xa405336)
#19 0x000055c50fca5802 (anonymous namespace)::ConvertVectorToSCFPass::runOnOperation() VectorToSCF.cpp:0:0
#20 0x000055c511c45449 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f449)
#21 0x000055c511c457b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#22 0x000055c511c46026 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda12'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&) const Pass.cpp:0:0
#23 0x000055c511c4439c mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (mlir-opt+0xa49e39c)
#24 0x000055c511c45321 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f321)
#25 0x000055c511c457b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#26 0x000055c511c476f2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (mlir-opt+0xa4a16f2)
#27 0x000055c511c486c9 mlir::PassManager::run(mlir::Operation*) (mlir-opt+0xa4a26c9)
#28 0x000055c50980c9b3 performActions(llvm::raw_ostream&, std::shared_ptr<llvm::SourceMgr> const&, mlir::MLIRContext*, mlir::MlirOptMainConfig const&) MlirOptMain.cpp:0:0
#29 0x000055c50980d2de processBuffer(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&, mlir::DialectRegistry&, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#30 0x000055c50980d521 llvm::LogicalResult llvm::function_ref<llvm::LogicalResult (std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, 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::MemoryBufferRef, llvm::raw_ostream&)>(long, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, llvm::MemoryBufferRef const&, llvm::raw_ostream&) MlirOptMain.cpp:0:0
#31 0x000055c512017a2d 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::MemoryBufferRef const&, llvm::raw_ostream&)>, llvm::raw_ostream&, llvm::StringRef, llvm::StringRef) (mlir-opt+0xa871a2d)
#32 0x000055c5098082da mlir::MlirOptMain(llvm::raw_ostream&, std::unique_ptr<llvm::MemoryBuffer, std::default_delete<llvm::MemoryBuffer>>, mlir::DialectRegistry&, mlir::MlirOptMainConfig const&) (.part.0) MlirOptMain.cpp:0:0
#33 0x000055c50980daf8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2067af8)
#34 0x000055c50980dd54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&) (mlir-opt+0x2067d54)
#35 0x000055c5096ba5cc main (mlir-opt+0x1f145cc)
#36 0x00007f7e187f9d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#37 0x00007f7e187f9e40 call_init ./csu/../csu/libc-start.c:128:20
#38 0x00007f7e187f9e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#39 0x000055c509725f35 _start (mlir-opt+0x1f7ff35)

Kiritobl avatar Oct 14 '26 08:10 Kiritobl

@llvm/issue-subscribers-mlir

Author: Kirito (Kiritobl)

#### Version

LLVM/MLIR 24.0.0git, commit c275ebd64bf5b05e36a3a8e8b8daa32ba9a52aac (optimized build with assertions).

Bug Description

Observed failure: extract-through-rank-zero transpose builds an empty permutation map. The input passes verification without the pass, but the command below crashes.

Likely Cause

vector.extract [] on the result of a legal rank-zero vector.transpose [] enters ExtractOp::fold's transpose handling. It calls AffineMap::getPermutationMap with an empty permutation; that API asserts because it requires a non-empty list. The folding path needs to handle the rank-zero case.

Steps to Reproduce

mlir-opt --allow-unregistered-dialect '--pass-pipeline=builtin.module(func.func(convert-vector-to-scf{full-unroll=true lower-scalable=true}))' reproducer.mlir -o /dev/null

Reproducer (reproducer.mlir)

module {
  func.func @<!-- -->main(%arg: vector&lt;f32&gt;) -&gt; f32 {
    %t = vector.transpose %arg, [] : vector&lt;f32&gt; to vector&lt;f32&gt;
    %x = vector.extract %t[] : f32 from vector&lt;f32&gt;
    return %x : f32
  }
}

Stack Dump (full stderr)

mlir-opt: mlir/lib/IR/AffineMap.cpp:262: static mlir::AffineMap mlir::AffineMap::getPermutationMap(llvm::ArrayRef&lt;unsigned int&gt;, mlir::MLIRContext*): Assertion `!permutation.empty() &amp;&amp; "Cannot create permutation map from empty permutation vector"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: mlir-opt --allow-unregistered-dialect "--pass-pipeline=builtin.module(func.func(convert-vector-to-scf{full-unroll=true lower-scalable=true}))" reproducer.mlir -o /dev/null
 #<!-- -->0 0x000055c509746699 llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (mlir-opt+0x1fa0699)
 #<!-- -->1 0x000055c509742e9c llvm::sys::RunSignalHandlers() (mlir-opt+0x1f9ce9c)
 #<!-- -->2 0x000055c509743006 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #<!-- -->3 0x00007f7e18812520 (libc.so.6+0x42520)
 #<!-- -->4 0x00007f7e188669bc __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #<!-- -->5 0x00007f7e188669bc __pthread_kill_internal ./nptl/pthread_kill.c:78:10
 #<!-- -->6 0x00007f7e188669bc pthread_kill ./nptl/pthread_kill.c:89:10
 #<!-- -->7 0x00007f7e18812476 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #<!-- -->8 0x00007f7e187f87f3 abort ./stdlib/abort.c:81:7
 #<!-- -->9 0x00007f7e187f871b _nl_load_domain ./intl/loadmsgcat.c:1177:9
#<!-- -->10 0x00007f7e18809e96 (libc.so.6+0x39e96)
#<!-- -->11 0x000055c511eb897d (mlir-opt+0xa71297d)
#<!-- -->12 0x000055c511eb8a73 mlir::AffineMap::getPermutationMap(llvm::ArrayRef&lt;long&gt;, mlir::MLIRContext*) (mlir-opt+0xa712a73)
#<!-- -->13 0x000055c510489deb mlir::vector::ExtractOp::fold(mlir::vector::ExtractOpGenericAdaptor&lt;llvm::ArrayRef&lt;mlir::Attribute&gt;&gt;) (mlir-opt+0x8ce3deb)
#<!-- -->14 0x000055c51048b0df mlir::RegisteredOperationName::Model&lt;mlir::vector::ExtractOp&gt;::foldHook(mlir::Operation*, llvm::ArrayRef&lt;mlir::Attribute&gt;, llvm::SmallVectorImpl&lt;mlir::OpFoldResult&gt;&amp;) (mlir-opt+0x8ce50df)
#<!-- -->15 0x000055c511fbce34 mlir::Operation::fold(llvm::ArrayRef&lt;mlir::Attribute&gt;, llvm::SmallVectorImpl&lt;mlir::OpFoldResult&gt;&amp;) (mlir-opt+0xa816e34)
#<!-- -->16 0x000055c511fbd2db mlir::Operation::fold(llvm::SmallVectorImpl&lt;mlir::OpFoldResult&gt;&amp;) (mlir-opt+0xa8172db)
#<!-- -->17 0x000055c511ba7421 (anonymous namespace)::GreedyPatternRewriteDriver::processWorklist() GreedyPatternRewriteDriver.cpp:0:0
#<!-- -->18 0x000055c511bab336 mlir::applyPatternsGreedily(mlir::Region&amp;, mlir::FrozenRewritePatternSet const&amp;, mlir::GreedyRewriteConfig, bool*) (mlir-opt+0xa405336)
#<!-- -->19 0x000055c50fca5802 (anonymous namespace)::ConvertVectorToSCFPass::runOnOperation() VectorToSCF.cpp:0:0
#<!-- -->20 0x000055c511c45449 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f449)
#<!-- -->21 0x000055c511c457b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#<!-- -->22 0x000055c511c46026 mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::'lambda12'(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&amp;)::operator()(mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool)::OpPMInfo&amp;) const Pass.cpp:0:0
#<!-- -->23 0x000055c511c4439c mlir::detail::OpToOpPassAdaptor::runOnOperationAsyncImpl(bool) (mlir-opt+0xa49e39c)
#<!-- -->24 0x000055c511c45321 mlir::detail::OpToOpPassAdaptor::run(mlir::Pass*, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int) (mlir-opt+0xa49f321)
#<!-- -->25 0x000055c511c457b4 mlir::detail::OpToOpPassAdaptor::runPipeline(mlir::OpPassManager&amp;, mlir::Operation*, mlir::AnalysisManager, bool, unsigned int, mlir::PassInstrumentor*, mlir::PassInstrumentation::PipelineParentInfo const*) (mlir-opt+0xa49f7b4)
#<!-- -->26 0x000055c511c476f2 mlir::PassManager::runPasses(mlir::Operation*, mlir::AnalysisManager) (mlir-opt+0xa4a16f2)
#<!-- -->27 0x000055c511c486c9 mlir::PassManager::run(mlir::Operation*) (mlir-opt+0xa4a26c9)
#<!-- -->28 0x000055c50980c9b3 performActions(llvm::raw_ostream&amp;, std::shared_ptr&lt;llvm::SourceMgr&gt; const&amp;, mlir::MLIRContext*, mlir::MlirOptMainConfig const&amp;) MlirOptMain.cpp:0:0
#<!-- -->29 0x000055c50980d2de processBuffer(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef, mlir::MlirOptMainConfig const&amp;, mlir::DialectRegistry&amp;, mlir::SourceMgrDiagnosticVerifierHandler*, llvm::ThreadPoolInterface*) MlirOptMain.cpp:0:0
#<!-- -->30 0x000055c50980d521 llvm::LogicalResult llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;::callback_fn&lt;mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;)::'lambda'(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef, llvm::raw_ostream&amp;)&gt;(long, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;) MlirOptMain.cpp:0:0
#<!-- -->31 0x000055c512017a2d mlir::splitAndProcessBuffer(std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::function_ref&lt;llvm::LogicalResult (std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, llvm::MemoryBufferRef const&amp;, llvm::raw_ostream&amp;)&gt;, llvm::raw_ostream&amp;, llvm::StringRef, llvm::StringRef) (mlir-opt+0xa871a2d)
#<!-- -->32 0x000055c5098082da mlir::MlirOptMain(llvm::raw_ostream&amp;, std::unique_ptr&lt;llvm::MemoryBuffer, std::default_delete&lt;llvm::MemoryBuffer&gt;&gt;, mlir::DialectRegistry&amp;, mlir::MlirOptMainConfig const&amp;) (.part.0) MlirOptMain.cpp:0:0
#<!-- -->33 0x000055c50980daf8 mlir::MlirOptMain(int, char**, llvm::StringRef, llvm::StringRef, mlir::DialectRegistry&amp;) (mlir-opt+0x2067af8)
#<!-- -->34 0x000055c50980dd54 mlir::MlirOptMain(int, char**, llvm::StringRef, mlir::DialectRegistry&amp;) (mlir-opt+0x2067d54)
#<!-- -->35 0x000055c5096ba5cc main (mlir-opt+0x1f145cc)
#<!-- -->36 0x00007f7e187f9d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#<!-- -->37 0x00007f7e187f9e40 call_init ./csu/../csu/libc-start.c:128:20
#<!-- -->38 0x00007f7e187f9e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#<!-- -->39 0x000055c509725f35 _start (mlir-opt+0x1f7ff35)

looking into this

StarOne01 avatar Oct 14 '26 09:10 StarOne01