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

    <tr>
        <th>Summary</th>
        <td>
            Assertion `!isInvalid() && "Loop not in a valid state!"' failed. with opt -verify-scev
        </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: 7ec6dde83ae6
Reproduce with: ```opt -passes="loop-mssa(loop-simplifycfg,require<iv-users>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>)" bbi-74333.ll -S -o /dev/null -verify-scev```
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 -passes=loop-mssa(loop-simplifycfg,require<iv-users>,licm<allowspeculation>,simple-loop-unswitch<nontrivial;trivial>) bbi-74333.ll -S -o /dev/null -verify-scev
 #0 0x0000000002e5ad33 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x2e5ad33)
 #1 0x0000000002e58a4e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x2e58a4e)
 #2 0x0000000002e5b0b6 SignalHandler(int) (../../main-github/llvm/build-all/bin/opt+0x2e5b0b6)
 #3 0x00007f4de7d06630 __restore_rt (/lib64/libpthread.so.0+0xf630)
 #4 0x00007f4de544d387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007f4de544ea78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007f4de54461a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007f4de5446252 (/lib64/libc.so.6+0x2f252)
 #8 0x0000000001e85b31 (../../main-github/llvm/build-all/bin/opt+0x1e85b31)
 #9 0x0000000001e84741 llvm::ScalarEvolution::getLoopDisposition(llvm::SCEV const*, llvm::Loop const*) (../../main-github/llvm/build-all/bin/opt+0x1e84741)
#10 0x0000000001e89139 llvm::ScalarEvolution::verify() const (../../main-github/llvm/build-all/bin/opt+0x1e89139)
#11 0x00000000037e687b llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x37e687b)
#12 0x00000000031c4acd 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+0x31c4acd)
#13 0x000000000263ef5c llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x263ef5c)
#14 0x0000000000ae661d 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+0xae661d)
#15 0x000000000264323e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x264323e)
#16 0x0000000000ae63fd 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+0xae63fd)
#17 0x000000000263e20c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x263e20c)
#18 0x000000000071ffa0 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+0x71ffa0)
#19 0x0000000000732371 main (../../main-github/llvm/build-all/bin/opt+0x732371)
#20 0x00007f4de5439555 __libc_start_main (/lib64/libc.so.6+0x22555)
#21 0x0000000000718590 _start (../../main-github/llvm/build-all/bin/opt+0x718590)
Abort
```
[bbi-74333.ll.gz](https://github.com/llvm/llvm-project/files/9703351/bbi-74333.ll.gz)


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWNtu2zgQ_Rr5hbAhibr5wQ_ODVtsiw3qoK8GJVE2t7SoJSmn2a_fISU7ouI0TZ2i3V1DkGhyOHPmzHAkMhflw4Lz_Q4VYrdj2sNLlNIiKUuaYUITz7_y_OVH2khRtgVF90xvjYyX-N0lGo2mDVGKKg9feWHIhWimO6WIF2a2rdiu4ax6KKqNF15K-lfLJPXwJdtPW0UlTLuGfs6KHXQSzsW9amjRcqKZqLtBq4JOrbq2VgCiABSXtai1ZHtGuIcvji2YMAccKM_ZNI0wxjPO0XSFpgJ54U1J93CvW9O3pxJwTVUBfQd_Dg6rlhsyur-jUfDZcDCbgSZWF7wtKbQMi_BY1oQ_KKag-R7wvqsrMTOUBdHcTMqF4MiKgnK8NCIXRBk-HjuhgxUXXBSfwfeRsPHP_inAecJqsJNBU2lkJ9yBj0sgAHV9Xnxx6MZX6DkLRu9Ywt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