<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=http://email.email.llvm.org/c/eJylVE2P2yAQ_TX4gjaywST2wYd8NFVVqYdupZ6xPYlpMaSAN5v99R0c7yab7laVahHDMG9eZjwPatueqq11FB5lf9BA2JqkG5IuyTydxmi2sFMGqJrnlORpC70lrBgtJh4JKylZrM5IMMGdCF-eLYqPP6rQdPSCXlMta9DRqmtOiVhdwPGJyPQGlv0JyW4g7AIhYnM2YuB1Lg7CRD-52Ss38qSU8A1VTX-g8OtV0lkafSsaOuXpUWlNDTTgvXRKn2gNdCe1B1w0csA5hkWuSHeVfe2oysY_ukk_v7HFc4r8VYqDcSCbTtbYrAmQv1kiS1-KFG8CsslPFps3e34PgHGUdiEcfGRgWxx729ZWh5l1e7Se8MeNrd2T_SzPYd_i58Eh6U9jjwaXfsBv42xP3eBDpLxhVKEb6lljezQi5E5Ls5_WOI0EHheFyDgnjI8bCO9Ra3dlmmeFEIt8qmF8fwd6lCbQYOkeqw0d0E9fsXA_6EDlLoCj9wr1rnan9fYj-bAlqzUpl_8gfe-a95SPG7fix61J_e-JKr2CzkaUBw1NmERyjo7Al0Nx3bpLM2P4e-1M2oq3JS9lIofQWVcdj6CkaR0ck8Hp6i_t0Prhebo7OPsDM7vuiOCF4ElXMWRvsrmAJhWFLBhAsajTpm6LrGE85cmoa1_Fo87YSMqX9hBUr55kUNYgGcNDm_x_MqpiKcORiSxPmchmBYeiLPiinTdlzmSDTYReKj2LPFHGiatGynrYe3Rq5YO_OKX3am8Axtwxw6CCHo1rAYkN_QLQRr05vBsfgA6xjd5TzPyAF4S3ZtJdGJxRZv98K2JElEUyVlGNJfwG1yCWzw>53853</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[SimplifyCFG] Need to remove useless comparison after turning switch to icmp
</td>
</tr>
<tr>
<th>Labels</th>
<td>
llvm:optimizations
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wweiandrew
</td>
</tr>
</table>
<pre>
For example,
```
define i64 @demo(i64 %x) {
entry:
switch i64 %x, label %bb3 [
i64 0, label %bb1
i64 1, label %bb2
]
bb1:
ret i64 0
bb2:
%0 = icmp eq i64 %x, 100 ; this will necessarily be false because %x == 1
br i1 %0, label %bb4, label %bb5
bb3:
unreachable
bb4:
ret i64 200
bb5:
ret i64 10
}
```
See: https://godbolt.org/z/3nobrzoKa
This is a known issue from rust: https://github.com/rust-lang/rust/issues/85133#issuecomment-904185574
We want to get the IR result after SimplifyCFG:
```
define i64 @src(i64 %x) {
%entry:
%switch = icmp eq i64 %x, 0
%. = select i1 %switch, i64 0, i64 10
ret i64 %.
}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNU01v2zAM_TXyRWhgS1ZsH3zIxzIMA3bYBuws20ysTZYySW7a_vpRjtukWTvMUGxRfHzhI6nGdo_1zjoKD3I4aiBsQ9ItSVdkmc5rMjvYKwNULXNK8rSDwRJWThYTD4RVlBTrMxJMcI-Er84WxcefVGh7ekFvqJYN6Gg1DadErC_g-ERkegPL_oZkNxB2gRCxPRsx8DoXB2Gmn93slRt5Ukr4lqp2OFL4_SrpLI2-NQ298vSktKYGWvBeOqUfaQN0L7UH3LRyxG8Mi1yR7ir7xlGVTX90k35-Y4vnFPmrFEfjQLa9bLBZMyB_UyJLX0SKNwHZ7CfF9s2efwPAOEr7EI4-MrAdroPtGqvDwroDWk_448Y27sl-luew77E8uCT9ZezJ4NaPWBtnB-pGHyLlDaMK_dgsWjugESF3WprDvMfPROBxU4qMc8L4dIDwAWftrkrzrBSiyGcN0_sH0JM0gQZLD6g29EA_fUXhftSByn0AR78pnHe1f9zsPpIPO7LekGr1H6PvXfve5OPB7fDj0Tz97w1VegVdTCgPGtowD8k5OgJfLsV16y7NjOHvtTPpat5VvJJJUEFDjRfuWr3Y0i8AXSyWw4t9D3SMOXhPscZHnG5vzVy0MDqjzOH5SmNE1JSMTtf_6KnW98-fu6OzP1HedVsFLwVP-rpIeSZaYHtRtAxkUUGTSZGWbV6kDSzLZLocPqZPGJtI-coegxrUkwzKGiRjqCZRNUsZrkxkecpEtig5lFXJi27ZVjmTLfYRBqn0IpLESU5cPWXXjAePTq188Ben9F4dDEyFi_xyDL119ekESprOwSmZtNSTkD8SwoGK">