<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/73446>73446</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Remove the default branch of a switch
</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>
DianQK
</td>
</tr>
</table>
<pre>
When the default branch is the last case, we can transform that branch into a concrete branch with an unreachable default branch.
```llvm
define i64 @src(i64 %0) {
%2 = urem i64 %0, 4
switch i64 %2, label %5 [
i64 1, label %3
i64 2, label %3
i64 3, label %4
]
3: ; preds = %1, %1
br label %5
4: ; preds = %1
br label %5
5: ; preds = %1, %4, %3
%.0 = phi i64 [ 2, %4 ], [ 1, %3 ], [ 0, %1 ]
ret i64 %.0
}
define i64 @tgt(i64 %0) {
%2 = urem i64 %0, 4
switch i64 %2, label %unreachable [
i64 0, label %5
i64 1, label %3
i64 2, label %3
i64 3, label %4
]
unreachable: ; preds = %1
unreachable
3: ; preds = %1, %1
br label %5
4: ; preds = %1
br label %5
5: ; preds = %1, %4, %3
%.0 = phi i64 [ 2, %4 ], [ 1, %3 ], [ 0, %1 ]
ret i64 %.0
}
```
alive: https://alive2.llvm.org/ce/z/Y-PGXv
from: https://github.com/rust-lang/rust/issues/118306
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVU2PmzAQ_TXmMkpkxpgkBw6bjeihl7aXtkcDQ3DFR2SbrLq_vsJAA90vVWp7ahTFMDPPM_PmxVbW6nNLlDB5ZPIUqN5VnUlOWrUf3wdZV3xPPlfUgqsICipVXzvIjGrzCrT11lpZB7myxPAeHghy1YIzqrVlZxpwlboBWteBgrxrc0OOZvODdhWoFvrWkMorldW_ptoyfmL8bvqN-fit62szmgoqdUug4whYxK3JGe79C0rO8ABsdxwDYTAhMHGC3lADt6B7iOYQ-6DdUO3ow8FXq4zq4U3CwNMUCD4mXAWItRNfc4qVc87P5GnZrmDCA37nw8QRLoYK6ztlKH2Nfp0KyMyip2W6aEj3DP4tnHwBN-aNplUsxrDlPupS6ZFqeRzZGsI9CcOzPMK8h1ga-dzQjS4AQ26e2pZPxe1WZK6F4s7urwllKeYnkuFrTU3OfyCmRVVvyupFESw3-S_UPy7U-XhbFq1qffUTq5y7WCbuGKYMU2_G7XAQbjtzZpjmxDB9ZJh-3Xx49-U6okvTNU_BZ-2qPtvmXcMwNb11m1q15-mZYaqt7ckyTMNwL3gcFIkoDuKgAkrCHQ85Ry7ioEqKfS6jfK_2BaowpjiMo0O4wwwp43lUyEAnyFGEIcYhCiHj7Y7Lcl8q2odU7OKsYBGnRun6ZyOBz53sRBTFgR-j9fcToj_zxV13cbrRj8rprrUMh3EwxEZbS8Vm6Rx88hSYZABusv5sWcRrbZ29JXPa1ZR8oqa70nP3XFeCmv7rQW_q5BUafXnjsrmY7hvlKyZ9Qz8CAAD__0Nq7dU">