<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/58159>58159</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Assertion `!isInvalid() && "Loop not in a valid state!"' failed. with opt -verify-scev with loop-deletion and simple-loop-unswitch
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          mikaelholmen
      </td>
    </tr>
</table>

<pre>
    llvm commit: d330731f94c4
Reproduce with:```opt -verify-scev -passes="function(loop-mssa(loop-deletion,simple-loop-unswitch<nontrivial>))" bbi-74371.ll -o /dev/null```
Result:
```
opt: ../include/llvm/Analysis/LoopInfo.h:149: bool llvm::LoopBase<llvm::BasicBlock, llvm::Loop>::contains(const BlockT *) const [BlockT = llvm::BasicBlock, LoopT = llvm::Loop]: Assertion `!isInvalid() && "Loop not in a valid state!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: ../../main-github/llvm/build-all/bin/opt -verify-scev -passes=function(loop-mssa(loop-deletion,simple-loop-unswitch<nontrivial>)) bbi-74371.ll -o /dev/null
 #0 0x0000000002e58473 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x2e58473)
 #1 0x0000000002e5618e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x2e5618e)
 #2 0x0000000002e587f6 SignalHandler(int) (../../main-github/llvm/build-all/bin/opt+0x2e587f6)
 #3 0x00007f27e5a5c630 __restore_rt (/lib64/libpthread.so.0+0xf630)
 #4 0x00007f27e31a3387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007f27e31a4a78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007f27e319c1a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007f27e319c252 (/lib64/libc.so.6+0x2f252)
 #8 0x0000000001e83891 (../../main-github/llvm/build-all/bin/opt+0x1e83891)
 #9 0x0000000001e824a1 llvm::ScalarEvolution::getLoopDisposition(llvm::SCEV const*, llvm::Loop const*) (../../main-github/llvm/build-all/bin/opt+0x1e824a1)
#10 0x0000000001e86e99 llvm::ScalarEvolution::verify() const (../../main-github/llvm/build-all/bin/opt+0x1e86e99)
#11 0x00000000037e44cb llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x37e44cb)
#12 0x00000000031c24ed llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x31c24ed)
#13 0x000000000263c59c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x263c59c)
#14 0x0000000000ae638d llvm::detail::PassModel<llvm::Function, llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0xae638d)
#15 0x000000000264087e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x264087e)
#16 0x0000000000ae616d llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0xae616d)
#17 0x000000000263b84c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x263b84c)
#18 0x000000000071ffe0 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::StringRef, llvm::ArrayRef<llvm::StringRef>, llvm::ArrayRef<llvm::PassPlugin>, llvm::opt_tool::OutputKind, llvm::opt_tool::VerifierKind, bool, bool, bool, bool, bool, bool) (../../main-github/llvm/build-all/bin/opt+0x71ffe0)
#19 0x00000000007323b1 main (../../main-github/llvm/build-all/bin/opt+0x7323b1)
#20 0x00007f27e318f555 __libc_start_main (/lib64/libc.so.6+0x22555)
#21 0x00000000007185d0 _start (../../main-github/llvm/build-all/bin/opt+0x7185d0)
Abort
```
[bbi-74371.ll.gz](https://github.com/llvm/llvm-project/files/9713405/bbi-74371.ll.gz)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWNtu2zgQ_Rr5hbAhUfcHPzgXY4ttsUET9NWgJErmlhYNknI3-_U7pGRHVJymrVPsLRAimRzOnDkzGopTiOpxyflhh0qx2zHthStUhaGfhkGdR2Xk-Teev_pI91JUXUnRF6a3IOMlfn-JvUbzA5Wsfpyrkh7QfE-UosoLbzyM664tNROthzMuxH6-U4ocnyvKaT93rdhuz-ncDnetAhslGLluRaslOzDCvfDWw7m9MCoKNk-jMA0WnKO5QB5eV_QA_9uO8xOwI3DVceNU_3MyC-CNv4sFLGZtybuKwpNhA26rlvBHxRQ8vgdg79paLIzrQZSbRYUQHFlRUB6ujMgVURRgPw3CACuvuCg_g5MTYeOS_VGCl4S1YCeDR6WRXfAAbq3AYdSPefHVcTi8QS9ZMHqnEtZWfGMgryAw0lCODAM4YOpdeyCcVWDamPJwAhfcsFmEWqERaxFBVgYpTTTQE8C0h1NUE8ZpteiJvHt_u7q_RaorIIVgRdE1SNK9kBppgbZa75VB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