<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63696>63696</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
SimplifyCFGPass regression in LLVM 16: generates division by zero despite of check for divisor != 0
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
anbe42
</td>
</tr>
</table>
<pre>
The following code compiles fine, but running it fails with a floating point exception when compiled with clang++-16 -O1, while it passes with clang++-15 (x86_64, no -march flag used):
```
__attribute__((noinline))
auto f (float x)
{
if (x != 0.0f)
{
return 1.0f + (1.0f / x);
}
else
{
return 1.0f;
}
}
#include <cfenv>
auto main () -> int
{
feenableexcept(FE_DIVBYZERO);
const auto a = f(8);
const auto b = f(0);
return a + b;
}
```
A successful run should exit with 2
The emitted assembly for function f somehow misses the branch.
Checking with `-opt-bisect-limit` pinpoints the miscompilation to SimplifyCFGPass
Tested with Debian llvm-16 (1:16.0.6-3), also reproducible on godbolt:
https://godbolt.org/z/vqc7498co
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVFGP4jYQ_jXmZQRyHAjJQx4W2FSVrrqqrU5qX5DjjMm0jp3GzsLer69sOJZdnapDEbE133yTb_yNpfd0sog12-zY5rCQc-jdVEvb4losWte91n_0CNoZ485kT6Bch6DcMJJBD5osMrGHdg4wzdZGBAXQkoyHM4UeJGjjZIiB0ZENgBeFYyBn4dyj_UbVXdHKSHtiYsfEbpkVsPycRfZzTwYj7yi9R_8d6AaYKC9lcSzWMcE6WA5yUj1oI08we-yYqFj-xPiB8SdW8NuTtsejDGGidg54PDJRMlFaR9YkbVV8EkzOwYGOhZIiuNwjbLu7LgAAKEEuwETG8gPwFdd3YIy_A8ffhGGeLGQrHjN3Mfu2bq418t1j9uG2QePxx1i_T_C2uP6LnKwyc4fA8r3SaF9Y_vyISPoHSRZSjypYsvwZyIaPTdCIVrYGryfNRNk8Hw8_f9n9-dfzb58_ClLO-gCJW0JsmGaiLP8H1d5R_BH1hr0pl6mZ7Rvgrvf96T-Bn5VC7_VsoofB9242HeCFwtVp4rFCnAYcKATsILpxaM0raDeBnq1Kttbg3YC9O8NAya6hR2gnaVW_emTa96j-iXORirCCL90Yli15VGFpaKDACg4j2TQ3V5qB_HVgZCoVHPxOw2hIv-6bn36V3r_7VPTh22AdsCVpwZiXIQ5W9BjLn7JixVfFMk8234M03sGE4-S6WVFrEJyFk-taZ8J9ePoQRh93omGiuUVXbjox0Xxlonn5V23XVancoqvzrsorucA6K8pyU3Ge8UVfr3FbbattqYu8krwqM7mttkJXeZarDjO9oFpwkfMt3wi-LjZ8pYq1KnItMiywLXTL1hwHSWYV9cTaC_J-xrrIi6pYGNmi8elGE8LiGVKQCREvuKlOPWjnk2drbsgH_8YSKBisP7QUJjxN6H1sOFn49OnLL5AVLH-CE1qcZEAPHb1QArSv8BUnBx36kQKC06DiOSeLJJSb7lfDYp5M_aGfFPq5XSk3MNHE77q9luPk_kYVmGiSGs9Ek9T-FwAA__8JibZw">