<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63470>63470</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SimplifyCFG] Conversion of comparisons to switch only partial
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations,
missed-optimization
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
nikic
</td>
</tr>
</table>
<pre>
```llvm
define i1 @test1(i32 %c) {
entry:
%i1 = icmp eq i32 %c, 115
br i1 %i1, label %bb12, label %bb11
bb11: ; preds = %entry
%_6 = icmp eq i32 %c, 109
br label %bb12
bb12: ; preds = %entry, %bb11
%_4.0 = phi i1 [ %_6, %bb11 ], [ true, %entry ]
br i1 %_4.0, label %bb9, label %bb8
bb8: ; preds = %bb12
%_8 = icmp eq i32 %c, 104
br label %bb9
bb9: ; preds = %bb12, %bb8
%_3.0 = phi i1 [ %_8, %bb8 ], [ true, %bb12 ]
br i1 %_3.0, label %bb6, label %bb5
bb5: ; preds = %bb9
%_10 = icmp eq i32 %c, 100
br label %bb6
bb6: ; preds = %bb9, %bb5
%_2.0 = phi i1 [ %_10, %bb5 ], [ true, %bb9 ]
br i1 %_2.0, label %bb3, label %bb2
bb2: ; preds = %bb6
%_12 = icmp eq i32 %c, 119
br label %bb3
bb3: ; preds = %bb6, %bb2
%i.0 = phi i1 [ %_12, %bb2 ], [ true, %bb6 ]
ret i1 %i.0
}
```
`opt -S -passes=simplifycfg` produces:
```llvm
define i1 @test1(i32 %c) {
entry:
switch i32 %c, label %bb8 [
i32 115, label %bb9
i32 109, label %bb9
i32 104, label %bb9
]
bb8: ; preds = %entry
br label %bb9
bb9: ; preds = %entry, %entry, %entry, %bb8
%_3.0 = phi i1 [ false, %bb8 ], [ true, %entry ], [ true, %entry ], [ true, %entry ]
%_10 = icmp eq i32 %c, 100
%spec.select1 = select i1 %_3.0, i1 true, i1 %_10
%_12 = icmp eq i32 %c, 119
%spec.select = select i1 %spec.select1, i1 true, i1 %_12
ret i1 %spec.select
}
```
Three of the comparisons have been converted into a switch, but the last two use selects.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyslt1yqzYQx59G3GjsESuE4YKLOB73AU7vO3wsRi1GFImcSZ--I2HCh4077kkmkyBrpf3vz9q_SLWWlwYxIeJIxMlLe1OpLmnkXzL3MlV8JiRkw29df1wJOxH2VmApG6TSpyRgBrXxCUSSAyUgcgIxJYfjEImN6T4Jf6PDkNoIu4yfqMyvLcW_6bTunfq-GAOzzu1vw-1MnWZY22GW-bD-wB8WDX_d2GbkR9p2WGiXjYAYtEw6_gi3dbB4pmOZe5kKbKpXfjZkwfuylkFhsGcurK2koyGOg_BZOCXi5IbiSE3X423K7erm1jztpiuA8WocLYuMHuKcYAxaoyc0g8c0Y7pMFL8Kc0PVSCea6-OPWUZT9AZKu-VjkvyOZLgai2WBYoNkPBfqsyck2WOS4Ypk-B0k4y8AYq4PHoP02RS-STJ-DBLuQPLVeDpqtwphA2W4QAlPrGajxfnt4zER_w6UU8fOe0ZukJxOMGySDOckOzSjW9oth6NwOI1Po4PPzwgJmWoN3f2guzbVGjXhJy2vbS3Lz7y8kJDRtlNFn9uZt9XKX78QRuX6pzR5tfhm5kZk6x5DqYuyV8TavZYBbG1ndwHBVsAX0ufWt7hJVpb2wNGeWv7W8-ReG-ZVprXG_zSv6R74v3MvOxMBoVvM9xprzM1w2Q_PK9-U_lfG24TPXu_eZbr7bHMtG1nhvo9mq77a6Uk3_V51iFSV1FRIc3Vt005q1WhapR9IM8SG5qr5wM5gQWVjFE1vR9_qyHrjFtapNtT8VLTXeCtC770i4UXM49TDxA-jg4BA8MCrEhYf_DBkTGRwEKXADDOflwXkPkYpD1NPJsCAsxC4D0Ekgn3OSwgFY6UvDnEpMhIwvKay3ttO3qvu4kmte0xCHhyY5061di-GAK7X-ZtqjbzKf1IjVaMJWKMiAFepNRa7-aSdEyevS-zCXdZfNAlYLbXRUzIjTe1ePH_cfOf9_BsRJ_ruSGmpGkt0TtOo0TBUU3_SNu2MTGuv7-qkMqZ1TgVnAueLNFWf7XN1JXB22od_u7ZTf9rvFM6uVE3g7Kr9NwAA___UdNrp">