Issue 242906
Summary [LoopVectorize] Segfault in formLCSSAImpl after vectorizing an early-exit loop next to a self-loop
Labels new issue
Assignees
Reporter arie2026
    The function has two top-level loops: an early-exit loop (`%loop.header`) and a single-block self-loop
(`%inner`) that is entered from the early-exit loop's header and leaves to the same exit block. LV vectorizes
the early-exit loop (VF=4). It then segfaults in `formLCSSARecursively` when it moves on to `%inner`.
The IR passes the verifier, and no target flags are needed.

Reproducer (`opt -passes=loop-vectorize`, also reproduces on bab211dec4a1 and 5e457cda8d5a):
```llvm
@A = external global [64 x i8]

define void @f() {
entry:
  br label %loop.header

loop.header:
  %iv = phi i64 [ %iv.next, %loop.latch ], [ 0, %entry ]
  br i1 false, label %inner, label %check

check:
  %gep = getelementptr i8, ptr @A, i64 %iv
  %l = load i8, ptr %gep, align 1
  %cmp = icmp eq i8 %l, 0
  br i1 %cmp, label %exit, label %loop.latch

inner:
  br i1 false, label %inner, label %exit

loop.latch:
  %iv.next = add i64 %iv, 1
  %ec = icmp eq i64 %iv.next, 64
  br i1 %ec, label %exit, label %loop.header

exit:
  ret void
}
```

```
$ opt -passes=loop-vectorize -disable-output test.ll
Stack dump:
1.      Running pass "function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)" on module "test.ll"
2.      Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "f"
 #4 formLCSSAImpl(llvm::Loop&, llvm::DominatorTree const&, llvm::LoopInfo const*, llvm::ScalarEvolution*, llvm::SmallDenseMap<llvm::Loop*, llvm::SmallVector<llvm::BasicBlock*, 1u>, 4u, ...>*)
 #5 formLCSSARecursivelyImpl(llvm::Loop&, llvm::DominatorTree const&, llvm::LoopInfo const*, llvm::ScalarEvolution*, ...)
 #6 llvm::formLCSSARecursively(llvm::Loop&, llvm::DominatorTree const&, llvm::LoopInfo const*, llvm::ScalarEvolution*)
 #7 llvm::LoopVectorizePass::runImpl(llvm::Function&)
 #8 llvm::LoopVectorizePass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)
 #9 llvm::detail::PassModel<llvm::Function, llvm::LoopVectorizePass, llvm::AnalysisManager<llvm::Function>>::runImpl(...)
#10 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&)
#12 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&)
Segmentation fault
```

Expected: no crash.

Notes: `-debug-_only_=loop-vectorize` shows the early-exit loop is vectorized ("Vectorizing: innermost loop") before the
crash, and `-force-vector-width=1 -force-vector-interleave=1` avoids it. So vectorizing the first loop
apparently leaves stale state for the sibling loop `%inner` (they share the exit block). Not confirmed which analysis.

Found with a mutation-based IR fuzzer. Triage, test-case minimization and parts of this write-up were
assisted by an LLM; verified the reproducer on b23814056.

Assisted-by: Claude (Anthropic)
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to