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

[opt] -passes=inline causes Broken Module (Stride must be greater or equal than the number of rows!)

Open fraglantia opened this issue 7 months ago • 8 comments

Reproducer: https://godbolt.org/z/aKWv161cz

Stride must be greater or equal than the number of rows!
ptr @llvm.matrix.column.major.store.v6f64.i32
LLVM ERROR: Broken module found after pass "InlinerPass", compilation aborted!
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: /opt/compiler-explorer/clang-trunk/bin/opt -o /app/output.s -S -verify-each -passes=inline <source>
1.	Running pass "cgscc(inline)" on module "<source>"
 #0 0x0000000005371bd8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk/bin/opt+0x5371bd8)
 #1 0x000000000536ed14 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #2 0x00007c208fe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00007c208fe969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #4 0x00007c208fe42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #5 0x00007c208fe287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #6 0x0000000000826c9d llvm::json::operator==(llvm::json::Value const&, llvm::json::Value const&) (.cold) JSON.cpp:0:0
 #7 0x0000000002df4cd7 llvm::VerifyInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&, llvm::AnalysisManager<llvm::Module>*)::'lambda'(llvm::StringRef, llvm::Any, llvm::PreservedAnalyses const&)::operator()(llvm::StringRef, llvm::Any, llvm::PreservedAnalyses const&) const (.isra.0) StandardInstrumentations.cpp:0:0
 #8 0x0000000002df4f8d void llvm::detail::UniqueFunctionBase<void, llvm::StringRef, llvm::Any, llvm::PreservedAnalyses const&>::CallImpl<llvm::VerifyInstrumentation::registerCallbacks(llvm::PassInstrumentationCallbacks&, llvm::AnalysisManager<llvm::Module>*)::'lambda'(llvm::StringRef, llvm::Any, llvm::PreservedAnalyses const&)>(void*, llvm::StringRef, llvm::Any&, llvm::PreservedAnalyses const&) StandardInstrumentations.cpp:0:0
 #9 0x00000000047c0005 void llvm::PassInstrumentation::runAfterPass<llvm::LazyCallGraph::SCC, llvm::detail::PassConcept<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>>(llvm::detail::PassConcept<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&> const&, llvm::LazyCallGraph::SCC const&, llvm::PreservedAnalyses const&) const (/opt/compiler-explorer/clang-trunk/bin/opt+0x47c0005)
#10 0x00000000047c4185 llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-trunk/bin/opt+0x47c4185)
#11 0x0000000002d3cc3e llvm::detail::PassModel<llvm::LazyCallGraph::SCC, llvm::PassManager<llvm::LazyCallGraph::SCC, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&>::run(llvm::LazyCallGraph::SCC&, llvm::AnalysisManager<llvm::LazyCallGraph::SCC, llvm::LazyCallGraph&>&, llvm::LazyCallGraph&, llvm::CGSCCUpdateResult&) (/opt/compiler-explorer/clang-trunk/bin/opt+0x2d3cc3e)
#12 0x00000000047c65fb llvm::ModuleToPostOrderCGSCCPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/opt+0x47c65fb)
#13 0x0000000000e7f7ee llvm::detail::PassModel<llvm::Module, llvm::ModuleToPostOrderCGSCCPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/opt+0xe7f7ee)
#14 0x00000000050ded17 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-trunk/bin/opt+0x50ded17)
#15 0x0000000000979cfa llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::PassPlugin>, llvm::ArrayRef<std::function<void (llvm::PassBuilder&)>>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool, bool, bool) (/opt/compiler-explorer/clang-trunk/bin/opt+0x979cfa)
#16 0x000000000096db91 optMain (/opt/compiler-explorer/clang-trunk/bin/opt+0x96db91)
#17 0x00007c208fe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#18 0x00007c208fe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#19 0x0000000000964bb5 _start (/opt/compiler-explorer/clang-trunk/bin/opt+0x964bb5)
Program terminated with signal: SIGSEGV
Compiler returned: 139

Generated by fuzzer.

fraglantia avatar Apr 14 '26 07:04 fraglantia

I would like to work on this

mayanksolanki393 avatar Apr 15 '26 18:04 mayanksolanki393

I don't know what is the expectation here. Both Inliner and Verifier seem to be working correctly. It looks like the testcase is incorrect.

inlining the callsite call void @strided_store_3x2_nonconst_i32_stride(i32 0) causes stride to become 0 which is less than the passed NumRows value, causing the assertion to hit.

changing @strided_store_3x2_nonconst_i32_stride(i32 0) to @strided_store_3x2_nonconst_i32_stride(i32 3) everything works correctly.

mayanksolanki393 avatar Apr 15 '26 18:04 mayanksolanki393

I'm not an expert, and this was found by a fuzzer. So, no guarantee of "meaningful" bugs.

I think the test case is unrealistic in practice. But I was mainly unsure because the original IR seems to be accepted with a non-constant %stride, while after inlining 0 is materialized and the verifier rejects it; if that means the original IR should already be considered invalid, I’m happy to close this.

fraglantia avatar Apr 16 '26 03:04 fraglantia

cc @fhahn

Assuming that stride is not supposed to be an immarg argument, the correct fix is to remove the verifier check. It is illegal to have verifier checks that apply only to constant arguments (unless they are immarg).

nikic avatar Apr 23 '26 11:04 nikic

Yeah, stride cannot be an immarg

fhahn avatar Apr 23 '26 11:04 fhahn

@fraglantia kindly assign this ticket to me

mayanksolanki393 avatar Apr 23 '26 13:04 mayanksolanki393

PR: https://github.com/llvm/llvm-project/pull/207665

mayanksolanki393 avatar Jul 06 '26 08:07 mayanksolanki393

@nikic @fhahn @fraglantia Request to assign reviewer for the PR https://github.com/llvm/llvm-project/pull/207665. I am unable to add myself.

mayanksolanki393 avatar Jul 16 '26 04:07 mayanksolanki393