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

[Bug][LoopVectorize] LoopVectorize calls into ScalarEvolution with out-of-date LoopInfo

Open CongzheUalberta opened this issue 8 months ago • 3 comments

LoopVectorize did not update LoopInfo completely correctly.

The way to reproduce the bug: put a call to LI.verify(DT) at the beginning of ScalarEvolution::createSCEVIter, then run check-llvm-transforms-loopvectorize. The following three tests would crash at loop vectorizer.

  LLVM :: Transforms/LoopVectorize/AArch64/low_trip_memcheck_cost.ll
  LLVM :: Transforms/LoopVectorize/optimal-epilog-vectorization.ll
  LLVM :: Transforms/PhaseOrdering/assume-explosion.ll

Related parent issue: https://github.com/llvm/llvm-project/issues/190682

CongzheUalberta avatar Apr 06 '26 20:04 CongzheUalberta

Hmm, I am unable to reproduce the crashes with

diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 2862acfedb91..f2adb684e9f3 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -7690,6 +7690,7 @@ bool ScalarEvolution::loopIsFiniteByAssumption(const Loop *L) {
 }

 const SCEV *ScalarEvolution::createSCEVIter(Value *V) {
+  LI.verify(DT);
   // Worklist item with a Value and a bool indicating whether all operands have
   // been visited already.
   using PointerTy = PointerIntPair<Value *, 1, bool>;

fhahn avatar Apr 07 '26 11:04 fhahn

Hmm, I am unable to reproduce the crashes with

Thanks for the feedback. I checked again based on a more recent version of the repo (top commit dfa1c56358830e6a79a76235b56833dab2ac0b02), and it is indeed that those tests do not fail right now.

Previously they did fail on an older version of the repo (top commit bdf28a6d48112681afd24efe51a43e9807ff4fbb), just providing the stack dump below for reference.

Likely the crash from loop vectorizer is fixed by some of the very recent commits. Other relevant crashes from other passes listed on the parent issue still do occur as of now.

If you think we should close this sub-issue, please feel free to do so.

# executed command: /home/llvm-project/build/bin/opt -passes=loop-vectorize -enable-epilogue-vectorization -epilogue-vectorization-force-VF=2 -S /home/llvm-project/llvm/test/Transforms/LoopVectorize/optimal-epilog-vectorization.ll
# .---command stderr------------
# | opt: /home/llvm-project/llvm/include/llvm/Support/GenericLoopInfoImpl.h:743: void llvm::compareLoops(const LoopT *, const LoopT *, DenseMap<BlockT *, const LoopT *> &) [BlockT = llvm::BasicBlock, LoopT = llvm::Loop]: Assertion `compareVectors(BBs, OtherBBs) && "Mismatched basic blocks in the loops!"' 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: /home/llvm-project/build/bin/opt -passes=loop-vectorize -enable-epilogue-vectorization -epilogue-vectorization-force-VF=2 -S /home/llvm-project/llvm/test/Transforms/LoopVectorize/optimal-epilog-vectorization.ll
# | 1.  Running pass "function(loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>)" on module "/home/llvm-project/llvm/test/Transforms/LoopVectorize/optimal-epilog-vectorization.ll"
# | 2.  Running pass "loop-vectorize<no-interleave-forced-only;no-vectorize-forced-only;>" on function "induction_resume_value_requires_non_trivial_scev_expansion"
# |  #0 0x00000000043e0830 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/llvm-project/llvm/lib/Support/Unix/Signals.inc:880:13
# |  #1 0x00000000043de478 std::atomic<CallbackAndCookie::Status>::store(CallbackAndCookie::Status, std::memory_order) /usr/bin/../lib/gcc/aarch64-linux-gnu/10/../../../../include/c++/10/atomic:254:9
# |  #2 0x00000000043de478 llvm::sys::RunSignalHandlers() /home/llvm-project/llvm/lib/Support/Signals.cpp:110:16
# |  #3 0x00000000043e164c SignalHandler(int, siginfo_t*, void*) /home/llvm-project/llvm/lib/Support/Unix/Signals.inc:448:38
# |  #4 0x0000ffffb1c5e5c0 (linux-vdso.so.1+0x5c0)
# |  #5 0x0000ffffb16ffcd8 raise /build/glibc-70LW9c/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
# |  #6 0x0000ffffb16eca28 abort /build/glibc-70LW9c/glibc-2.31/stdlib/abort.c:81:7
# |  #7 0x0000ffffb16f93e4 __assert_fail_base /build/glibc-70LW9c/glibc-2.31/assert/assert.c:89:7
# |  #8 0x0000ffffb16f944c (/lib/aarch64-linux-gnu/libc.so.6+0x2d44c)
# |  #9 0x0000000003b0b814 llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop>::destroy(llvm::Loop*) /home/llvm-project/llvm/include/llvm/Support/GenericLoopInfo.h:774:0
# | #10 0x0000000003b0aef0 __gnu_cxx::__normal_iterator<llvm::Loop* const*, std::vector<llvm::Loop*, std::allocator<llvm::Loop*>>>::operator++() /usr/bin/../lib/gcc/aarch64-linux-gnu/10/../../../../include/c++/10/bits/stl_iterator.h:1002:2
# | #11 0x0000000003b0aef0 llvm::LoopInfoBase<llvm::BasicBlock, llvm::Loop>::verify(llvm::DominatorTreeBase<llvm::BasicBlock, false> const&) const /home/llvm-project/llvm/include/llvm/Support/GenericLoopInfoImpl.h:808:17
# | #12 0x0000000003ba8834 llvm::ScalarEvolution::createSCEVIter(llvm::Value*) /home/llvm-project/llvm/lib/Analysis/ScalarEvolution.cpp:0:6
# | #13 0x0000000002827830 llvm::EpilogueVectorizerMainLoop::createIterationCountCheck(llvm::BasicBlock*, llvm::ElementCount, unsigned int) const /home/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:2405:50
# | #14 0x000000000284a680 llvm::EpilogueVectorizerMainLoop::emitIterationCountCheck(llvm::BasicBlock*, llvm::BasicBlock*, bool) /home/llvm-project/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7617:26

CongzheUalberta avatar Apr 07 '26 17:04 CongzheUalberta

@CongzheUalberta let's close it. I think this was fixed by 0b61cd39e45ad7e0476740a5ecc455e7461488a4

fhahn avatar Apr 07 '26 17:04 fhahn