<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/137739>137739</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
UB optimization leads to really bad code gen
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
bwendling
</td>
</tr>
</table>
<pre>
Linux has some code that may result in dividing by zero or shifting by negative numbers. For instance, in one of the ARMGPU drivers, a "divide by zero" results in a fall through into the following function.
```
drivers/gpu/drm/amd/amdgpu/../display/dc/basics/fixpt31_32.o:
warning: objtool: dc_fixpt_recip() falls through to next function dc_fixpt_sinc()
drivers/gpu/drm/amd/amdgpu/../display/dc/sspl/spl_fixpt31_32.o:
warning: objtool: spl_fixpt_recip() falls through to next function spl_fixpt_sinc()
```
It is undefined behavior, but in these cases it will silently generate incorrect code. It's far better to generate the bad code so that it signals/traps/whatever.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyck02r6zYQhn-NvBmukeU4HwsvcltSLrRQCnd90MfYnossGWmcnJxfX-SkOe2uLQhLSHpnHo_e0TnTGBB70X0V3c-VXnmKqTc3DM5TGCsT3b3_lcL6DpPOkOOMYKND4EkzzPoOCfPqGSiAoys5CiOYO3xgihAT5IkGfu4FHDXTFSGss8GUa7jEBBQy62BRqJ9KkBgQ4gA8IZz_-O2X37-DS3TFlMu5BqHUlgb_SiKUeiLkItcwaO-BpxTXcQIKHLdYQ_Q-3grIsAbLFEMt5LmMvXwOeX5luozLKtTFpVmoi57d4_vYrOtyQnnx-l5WVqiL0Zls0Q30vnDbvLWqjqIt8eGmU6AwivYM0fzgGH1ZOvu23X1LaGkR6ijUaUPPL3aOEPCdX8CfmkzBPiSPf_jf3DkvvkyLf_vX5K_L_wX9U_RP9r8VX8jzNwbKsAaHAwV0YHDSV4qpPL1ZN4_xhBnB6owZiOFG3kMmj4H9HUYMmDQjULAxJbS8ebWGbyzUIcOgExhkxlQIX7eLP4x2D1_n-LA2MZTW0L6UlZNeynybNOMVU125vnWn9qQr7JvDrjse97Jpq6mXysr2eOp28ij3iG3XuH3bmK47NKbtrKqoV1J1cqdOUirZtPV-ZxvXDbLrFHbGnsRO4qzJ195f5zqmsaKcV-yb9nBoT5XXBn3e-lWpgDfYToVSpX1TX0RfzDpmsZOeMufPMEzssf_-FeLCNNOH3l7Go3a5lCOh9v7-WYgRQ7Um30_MSy6OUJdiMOJpNbWNxWEl9HP6sqT4Ay0LddmASrWexNde_RkAAP___Sl2tQ">