<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61391>61391</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SimplifyCFG] unable to merge large lookup tables
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
Nic30
</td>
</tr>
</table>
<pre>
### Problem:
SimplifyCFG can not merge switch instructions If the number of the first block successor is large.
In this example https://llvm.godbolt.org/z/hP7s8YdzM (same as attached file) problem happens after first SimplifyCFGPass.
The large block with icmp eq is split on two parts when it is clearly a continuous sequence of values for each index.
This because SimplifyCFG gave up.
### Reason
The reason for this is that there is a function which is used in analysis of compared value.
And the **check does not work as intended**.
When folding switch instruction the function is called also for parent.
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/SimplifyCFG.cpp#L1398
There are no restrictions on parent of parent but the current implementation checks it. And that is why switch instructions are not merged when it should be possible.
https://github.com/llvm/llvm-project/blob/main/llvm/lib/Transforms/Utils/SimplifyCFG.cpp#L779
### Possible solution
I think that the `isValueEqualityComparison` is just missing some flag to enable mentioned check when not checking on parent block terminator.
[test.zip](https://github.com/llvm/llvm-project/files/10961507/test.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzElc9u4zYQxp-GvgwqSJT_6eBDdlMXC7RF0G5b9EiJI4kbitRyhut1nr4gpSQOkMueChiWx5I43_zmG1IRmcEhnsTug9jdb1Tk0YfT76ary03r9fUkZL184CH41uIk6jtR3oty_f7TTLM1_fXj-RfolAPnGSYMAwJdDHcjGEccYsfGO4JPPQCPCC5OLQbwfY56E4ihtb57BIpdh0Q-gCGwKgxYLIk-OeDREOB3Nc0WYWSeKYmRZyHP1n6bisHr1lsufBiEPD8JeR4fDnT8Vz_9BkIeSU0IikAxq25EDb2xKGQD81IZjGqe0RGonjGsqm7qe1BExW3tn0dcJK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