<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/58521>58521</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Assertion `IterCnt++ < 1000 && "Iterative simplification didn't converge!"' failed. with simplifycfg<switch-range-to-icmp;>
</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: 851669792f
Reproduce with:```opt -passes="simplifycfg<switch-range-to-icmp;>" bbi-74965.ll -S -o /dev/null```
Result:
```
opt: ../lib/Transforms/Scalar/SimplifyCFGPass.cpp:240: bool iterativelySimplifyCFG(llvm::Function &, const llvm::TargetTransformInfo &, llvm::DomTreeUpdater *, const llvm::SimplifyCFGOptions &): Assertion `IterCnt++ < 1000 && "Iterative simplification didn't converge!"' 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=simplifycfg<switch-range-to-icmp;> bbi-74965.ll -S -o /dev/null
#0 0x0000000002e7a223 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (../../main-github/llvm/build-all/bin/opt+0x2e7a223)
#1 0x0000000002e77f3e llvm::sys::RunSignalHandlers() (../../main-github/llvm/build-all/bin/opt+0x2e77f3e)
#2 0x0000000002e7a5a6 SignalHandler(int) (../../main-github/llvm/build-all/bin/opt+0x2e7a5a6)
#3 0x00007f024d76d630 __restore_rt (/lib64/libpthread.so.0+0xf630)
#4 0x00007f024aeb4387 raise (/lib64/libc.so.6+0x36387)
#5 0x00007f024aeb5a78 abort (/lib64/libc.so.6+0x37a78)
#6 0x00007f024aead1a6 __assert_fail_base (/lib64/libc.so.6+0x2f1a6)
#7 0x00007f024aead252 (/lib64/libc.so.6+0x2f252)
#8 0x0000000002d44c20 llvm::MapVector<unsigned int, llvm::SmallVector<llvm::BasicBlock*, 2u>, llvm::SmallDenseMap<unsigned int, unsigned int, 4u, llvm::DenseMapInfo<unsigned int, void>, llvm::detail::DenseMapPair<unsigned int, unsigned int> >, llvm::SmallVector<std::pair<unsigned int, llvm::SmallVector<llvm::BasicBlock*, 2u> >, 4u> >::operator[](unsigned int const&) (../../main-github/llvm/build-all/bin/opt+0x2d44c20)
#9 0x0000000002d4453b simplifyFunctionCFGImpl(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) (../../main-github/llvm/build-all/bin/opt+0x2d4453b)
#10 0x0000000002d42f9d simplifyFunctionCFG(llvm::Function&, llvm::TargetTransformInfo const&, llvm::DominatorTree*, llvm::SimplifyCFGOptions const&) (../../main-github/llvm/build-all/bin/opt+0x2d42f9d)
#11 0x0000000002d42cfb llvm::SimplifyCFGPass::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x2d42cfb)
#12 0x000000000101f88d llvm::detail::PassModel<llvm::Function, llvm::SimplifyCFGPass, llvm::PreservedAnalyses, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x101f88d)
#13 0x00000000026586ac llvm::PassManager<llvm::Function, llvm::AnalysisManager<llvm::Function> >::run(llvm::Function&, llvm::AnalysisManager<llvm::Function>&) (../../main-github/llvm/build-all/bin/opt+0x26586ac)
#14 0x0000000000aec4fd 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+0xaec4fd)
#15 0x000000000265c98e llvm::ModuleToFunctionPassAdaptor::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x265c98e)
#16 0x0000000000aec2dd 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+0xaec2dd)
#17 0x000000000265795c llvm::PassManager<llvm::Module, llvm::AnalysisManager<llvm::Module> >::run(llvm::Module&, llvm::AnalysisManager<llvm::Module>&) (../../main-github/llvm/build-all/bin/opt+0x265795c)
#18 0x0000000000720d79 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+0x720d79)
#19 0x0000000000730241 main (../../main-github/llvm/build-all/bin/opt+0x730241)
#20 0x00007f024aea0555 __libc_start_main (/lib64/libc.so.6+0x22555)
#21 0x00000000007199e0 _start (../../main-github/llvm/build-all/bin/opt+0x7199e0)
Abort
```
This starts happening with a4772cbaf0dc
```
Revert "[SimplifyCFG] Thread branches on same condition in more cases (PR54980)"
This reverts commit 4e545bdb355a470d601e9bb7f7b2693c99e61a3e.
The newly added test is the third infinite combine loop caused by
this change. In this case, it's a combination of the branch to
common dest and jump threading folds that keeps peeling off loop
iterations.
The core problem here is that we ideally would not thread over
loop backedges, both because it is potentially non-profitable
(it may break canonical loop structure) and because it may result
in these kinds of loops. Unfortunately, due to the lack of a
dominator tree in SimplifyCFG, there is no good way to prevent
this. While we have LoopHeaders, this is an optional structure and
we don't do a good job of keeping it up to date. It would be fine
for a profitability check, but is not suitable for a correctness
check.
So for now I'm just giving up here, as I don't see a good way to
robustly prevent infinite combine loops.
Fixes https://github.com/llvm/llvm-project/issues/56203.
```
So, it crashes on current top of tree 851669792f but it didn't crash between 4e545bdb35 and a4772cbaf0dc.
However, with 4e545bdb35 something else crashes the same way, as described in https://github.com/llvm/llvm-project/issues/56203
[bbi-74965.ll.gz](https://github.com/llvm/llvm-project/files/9837417/bbi-74965.ll.gz)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzlWdty2zgS_RrpBSUVxav4oAfZjjeuTWpcsWfmUQUSoISYJFgAaEf79dsNUBIp04kTe2-zLpUlkkD36dOHuDQyyfarsnysSC6rSphJsCbLaBHHaZL6xcS7mnjrL7xRkrU5J0_C7KDFJPbcRzaGzBqqNdeT4Gri-1pUTSmKfV5sJ8Glhvb5bqZoveUzI2cir5pJcDEJPkBTkmViloRpHM3LkszuyEySiX_N-CP8r9uyPHo5oNBtifjc5dlTQILQ53PoXIoM_t-DW11IVWm4uMtpSRX-6ABeXv_tFnDP8wYQrf3Qw96ZlCURhitqxCMv973GE3-JLKH7YH3d1rkRsga88cS_BOpqbcjp-T1VW26OAG7qQh6anhpdyepecf57wyh4hOfrMVM9CL816FM7SyniXQPxygGJvRuwclmbiX8BHwLsk4Xnea51DF_-zSEw0mVJ5NR2ZoLVEz8x6PyRA_SJv4D2cIsUVJSczR3Ht58-rO8-EN1mIBRCSdZuieKNVIYYSXbGNBpB-9fw2YJS2mwOosKEYDjuawZS-spzgHkttG45JofQmhFR52XLODE7TnJF9Y5kNH8wiua8c39n4AZhLWqoE4EHj9JbJbeKVgRIbyteG30Ugv1XUVHPHJwTlKwVJZtREBn8FhD99VDKr9Xxj0VsccK9wCPeN-_w5_OE-n7QS7Tea_fjVona2FjvMfiB8BR92khtFKdVpyeBGU_B_vJXIgaleN86LKipI9jFGdikCPgY2C9tfSe2NS0_Qg5LriCdy3fAg-4GePxz8iIak4Fn8PhOXIDpge-g850Unh-yJGYx5HKzUVwbqfgG1G-DxmEnDt13Y3aQIzbXcu5ZuwX0GRgN-0Ypz8JgmRBFhebPreVoJ7Z2ghjaD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