Issue 203176
Summary [opt] `-passes="loop(loop-flatten),loop-vectorize"` causes assertion error `(Legal->hasUncountableEarlyExit() || BackedgeTakenCount == PSE.getBackedgeTakenCount()) && "Invalid loop count"'`
Labels new issue
Assignees
Reporter fraglantia
    Reproducer: https://godbolt.org/z/E6hPed6j3

```
opt: /root/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:3042: llvm::LoopVectorizationCostModel::computeMaxVF(llvm::ElementCount, unsigned int)::<lambda(unsigned int)>: Assertion `(Legal->hasUncountableEarlyExit() || BackedgeTakenCount == PSE.getBackedgeTakenCount()) && "Invalid loop count"' 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: /opt/compiler-explorer/clang-assertions-trunk/bin/opt -o /app/output.s -S -passes=loop(loop-flatten),loop-vectorize <source>
1.	Running pass "function(loop(loop-flatten),loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)" on module "<source>"
2.	Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "f"
 #0 0x0000000005a97dd8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5a97dd8)
 #1 0x0000000005a94c14 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x5a94c14)
 #2 0x0000000005a94d8a SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
 #3 0x000078739e445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
 #4 0x000078739e49eb2c pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x9eb2c)
 #5 0x000078739e44527e raise (/lib/x86_64-linux-gnu/libc.so.6+0x4527e)
 #6 0x000078739e4288ff abort (/lib/x86_64-linux-gnu/libc.so.6+0x288ff)
 #7 0x000078739e42881b (/lib/x86_64-linux-gnu/libc.so.6+0x2881b)
 #8 0x000078739e43b517 (/lib/x86_64-linux-gnu/libc.so.6+0x3b517)
 #9 0x000000000372a6dc llvm::LoopVectorizationCostModel::computeMaxVF(llvm::ElementCount, unsigned int)::'lambda0'(unsigned int)::operator()(unsigned int) const (.isra.0) LoopVectorize.cpp:0:0
#10 0x0000000003750211 llvm::LoopVectorizationCostModel::computeMaxVF(llvm::ElementCount, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3750211)
#11 0x000000000378376a llvm::LoopVectorizationPlanner::plan(llvm::ElementCount, unsigned int) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x378376a)
#12 0x0000000003786653 llvm::LoopVectorizePass::processLoop(llvm::Loop*) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3786653)
#13 0x00000000037890f9 llvm::LoopVectorizePass::runImpl(llvm::Function&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x37890f9)
#14 0x0000000003789847 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x3789847)
#15 0x00000000030c29ce llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x30c29ce)
#16 0x00000000057fd4a7 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x57fd4a7)
#17 0x0000000000f405de llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0xf405de)
#18 0x00000000057fc016 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x57fc016)
#19 0x000000000098ca9e llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x98ca9e)
#20 0x00000000057fb647 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x57fb647)
#21 0x000000000099702a 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-assertions-trunk/bin/opt+0x99702a)
#22 0x000000000098a87b optMain (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x98a87b)
#23 0x000078739e42a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#24 0x000078739e42a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#25 0x0000000000980165 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/opt+0x980165)
Program terminated with signal: SIGSEGV
Compiler returned: 139
```

This looks like an improper invalidation of `scalar-evolution` analysis results in the `loop-flatten` pass. The subsequent `loop-vectorize` pass crashes because it uses analysis result that is no longer valid.

Modifying the argument to `-passes="loop(loop-flatten),invalidate<scalar-evolution>,loop-vectorize"` (=forcing recomputation of `scalar-evolution` analysis) does not reproduce the crash.

This line makes the pass return early:
https://github.com/llvm/llvm-project/blob/7ad99619116468240ccc152c4bac05895a5ca4b6/llvm/lib/Transforms/Scalar/LoopFlatten.cpp#L932-L933
and skips cleanup that will be done in:
https://github.com/llvm/llvm-project/blob/7ad99619116468240ccc152c4bac05895a5ca4b6/llvm/lib/Transforms/Scalar/LoopFlatten.cpp#L936-L937
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to