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

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

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </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="loop(loop-reroll,simple-loop-unswitch<nontrivial;trivial>)" bbi-74369.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=loop(loop-reroll,simple-loop-unswitch<nontrivial;trivial>) bbi-74369.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 0x00007f09da225630 __restore_rt (/lib64/libpthread.so.0+0xf630)
 #4 0x00007f09d796c387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007f09d796da78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007f09d79651a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007f09d7965252 (/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 0x0000000001e8350c llvm::ScalarEvolution::computeLoopDisposition(llvm::SCEV const*, llvm::Loop const*) (../../main-github/llvm/build-all/bin/opt+0x1e8350c)
#11 0x0000000001e824a1 llvm::ScalarEvolution::getLoopDisposition(llvm::SCEV const*, llvm::Loop const*) (../../main-github/llvm/build-all/bin/opt+0x1e824a1)
#12 0x0000000001e86e99 llvm::ScalarEvolution::verify() const (../../main-github/llvm/build-all/bin/opt+0x1e86e99)
#13 0x00000000037e44cb llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x37e44cb)
#14 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)
#15 0x000000000263c59c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x263c59c)
#16 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)
#17 0x000000000264087e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x264087e)
#18 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)
#19 0x000000000263b84c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x263b84c)
#20 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)
#21 0x00000000007323b1 main (../../main-github/llvm/build-all/bin/opt+0x7323b1)
#22 0x00007f09d7958555 __libc_start_main (/lib64/libc.so.6+0x22555)
#23 0x00000000007185d0 _start (../../main-github/llvm/build-all/bin/opt+0x7185d0)
Abort
```
[bbi-74369.ll.gz](https://github.com/llvm/llvm-project/files/9713189/bbi-74369.ll.gz)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWdtu2zgQ_Rr5hbAhUfcHPzg3bLEtNmiCvhqURNnc0qJAUm6zX79DSnZExWnaOkW73cCwZHJ45syZEUkxhagelpzvd6gUux3TXrhCVRj6aRjUeVRGnn_l-av3tJWi6kqKPjG9BRsv8fuPaDWa76lk9cNclXSP5i1RiiovvPIw5kK0Hs7MZS6pFJx7-FKxXcvp3DZ2jQLEEiAvG9FoyfaMcC-8ON5dezgHIFQUbJ5GYZIvOEdzgTx8U9E9fDcdgB7YHNiqjptI-p-TXmBsglwsYDBrSt5VFO6MBHBZNYQ_KKbg9i3we9PUYmHiDaLcDCqE4MiaAni4MiYXRF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