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

    <tr>
        <th>Summary</th>
        <td>
            Assertion `SE->DT.dominates(ENT.ExitingBlock, Latch) && "We should only have known counts for exiting blocks that dominate " "latch!"' 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: 5c943e368818
Reproduce with:
```
opt -passes="loop-unroll,loop(simple-loop-unswitch<nontrivial>)" bbi-79654.ll -o /dev/null -unroll-count=0 -verify-scev
```
Result:
```
opt: ../lib/Analysis/ScalarEvolution.cpp:8563: const llvm::SCEV *llvm::ScalarEvolution::BackedgeTakenInfo::getExact(const llvm::Loop *, llvm::ScalarEvolution *, SmallVector<const llvm::SCEVPredicate *, 4> *) const: Assertion `SE->DT.dominates(ENT.ExitingBlock, Latch) && "We should only have known counts for exiting blocks that dominate " "latch!"' 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-unroll,loop(simple-loop-unswitch<nontrivial>) bbi-79654.ll -o /dev/null -unroll-count=0 -verify-scev
 #0 0x0000000002eeda78 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x2eeda78)
 #1 0x0000000002eeb60e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x2eeb60e)
 #2 0x0000000002eee0f6 SignalHandler(int) Signals.cpp:0:0
 #3 0x00007f1a79064630 __restore_rt sigaction.c:0:0
 #4 0x00007f1a767ab387 raise (/lib64/libc.so.6+0x36387)
 #5 0x00007f1a767aca78 abort (/lib64/libc.so.6+0x37a78)
 #6 0x00007f1a767a41a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
 #7 0x00007f1a767a4252 (/lib64/libc.so.6+0x2f252)
 #8 0x0000000001f5b1e8 llvm::ScalarEvolution::BackedgeTakenInfo::getExact(llvm::Loop const*, llvm::ScalarEvolution*, llvm::SmallVector<llvm::SCEVPredicate const*, 4u>*) const (../../main-github/llvm/build-all/bin/opt+0x1f5b1e8)
 #9 0x0000000001f7c02c llvm::ScalarEvolution::verify() const (../../main-github/llvm/build-all/bin/opt+0x1f7c02c)
#10 0x00000000039b9bdb llvm::FunctionToLoopPassAdaptor::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x39b9bdb)
#11 0x000000000326269d llvm::detail::PassModel<llvm::Function, llvm::FunctionToLoopPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) crtstuff.c:0:0
#12 0x00000000027b5a55 llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function>>::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x27b5a55)
#13 0x0000000000b33add 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>&) crtstuff.c:0:0
#14 0x00000000027b9fa2 llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x27b9fa2)
#15 0x0000000000b338bd llvm::detail::PassModel<llvm::Module, llvm::ModuleToFunctionPassAdaptor, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) crtstuff.c:0:0
#16 0x00000000027b4c55 llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module>>::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x27b4c55)
#17 0x0000000000734ac3 llvm::runPassPipeline(llvm::StringRef, llvm::Module&, llvm::TargetMachine*, llvm::TargetLibraryInfoImpl*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, llvm::ToolOutputFile*, 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+0x734ac3)
#18 0x00000000007430c2 main (../../main-github/llvm/build-all/bin/opt+0x7430c2)
#19 0x00007f1a76797555 __libc_start_main (/lib64/libc.so.6+0x22555)
#20 0x000000000072dd20 _start (../../main-github/llvm/build-all/bin/opt+0x72dd20)
Abort (core dumped)
```
This is rather old, it starts happening with d1e880acaa6f
```
[SCEV] Enable verification in LoopPM

Currently, we hardly ever actually run SCEV verification, even in
tests with -verify-scev. This is because the NewPM LPM does not
verify SCEV. The reason for this is that SCEV verification can
actually change the result of subsequent SCEV queries, which means
that you see different transformations depending on whether
verification is enabled or not.

To allow verification in the LPM, this limits verification to
BECounts that have actually been cached. It will not calculate
new BECounts.

BackedgeTakenInfo::getExact() is still not entirely readonly,
it still calls getUMinFromMismatchedTypes(). But I hope that this
is not problematic in the same way. (This could be avoided by
performing the umin in the other SCEV instance, but this would
require duplicating some of the code.)

Differential Revision: https://reviews.llvm.org/D120551
```
[bbi-79654.ll.gz](https://github.com/llvm/llvm-project/files/10857936/bbi-79654.ll.gz)

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzcWV1T4zoS_TXipSspR44d54GHAEnt1MJdamDvPqZkuRNrkSVfSU4m--u3JCUhDjDMDNzaDwoSsKWj06ePOlbDrBVrhXhJsiuS3VywztXaXDbiiaGstWxQXZS62l1KuWmA66YRjqQzyPh0nGKaF8WoIMkNSWZfsTW66jjCVriapLN4meT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