<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74013>74013</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Use of rccps leads to incorrect results for large values
</td>
</tr>
<tr>
<th>Labels</th>
<td>
backend:X86,
floating-point
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
andykaylor
</td>
</tr>
</table>
<pre>
When the arcp and ninf flags are set, the x86 backend uses an rccps instruction plus Newton-Raphson refinement to lower single precision vector division. Unfortunately, the rccps instruction returns zero if the result is denormal. This leads to incorrect results for simple division when the divisor is near FLT_MAX.
Here's a reproducer:
https://godbolt.org/z/9c6TK471o
Note that this happens without regard to whether FTZ/DAZ are enabled.
FWIW, gcc has this same behavior, though gcc requires -funsafe-math-optimizations and -ffinite-math-only and a comment at X86TargetLowering::getRecipEstimate indicates that it intends to match gcc behavior. This problem can be avoided using -mrecip=none.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEU0GTozYT_TXi0mUXCI8ZHzj4W39UUtnsYctbM7WXVCMaUFZIRN3Y8fz6lLAn2SSHXKBontTv9XuNzHbwRLV6-p96OmW4yBhijb67fcObCzFrQ3erX0byICMBRjMD-g689T30DgcGjARMovSHFfL78x5aNN_Id7AwMaCHaMzMYD1LXIzY4GF2C8Mnukrwm884jxw8ROqtp4m8gARw4UoR2PrBEcyRjOV08EJGQoTOXtbvLXzxfYiyeBRyt3cS_24YSZboGd4oBrD9HUW8OAHL0JEPcUK3hfNoGRxhx4mE9SbESEYeWIY-JFLT7OhPDnB9H89aCTHd6AkjNB_Pv_x8fN2q_KTy4_35A0VSumJAiDTH0C2GoiqP32NGkZlTTTdKN0Po2uBkG-KgdPOmdHMw-_NPu6oI3x_6FIRARhSQpGHEeSbPcLUyhiUJGDB2SdR1JBkpQnP-qnRzOn5dLSSPraPub1yblx9f0kgHY2BEvl_MOBG0NOLFhngfeFiGcQVF-m2xkRg2_eIZe9pMKOMmzGIn-4bJCV7zs-l76628__futpYRTJjWBKDA6_P-jHEg-ZiiYP2QJlIeB5LPZOz8fxY7oRBY31mDQnxXbwWsF_J3BycUc-f2Tvnh8RxD62gCgx5aArwE21GKrPUDbKYUuFmVJx88bbOuLrtDecCM6qLKi_JQ6GKXjbUxz0VVlU8lEbaHfd_vu0PVHw5VToeqynVma53rstB5kee7vNhtNRVdUeEzFm3e7p-M2uU0oXVb5y5TsjizzAvV1S4vysxhS47X7dT6sVWqPL4-75XWSn9QWvcuoFg_bOZgvaTy0ymLdbpu0y4Dq13uLAv_1UCsOKq_MEHoH5vyH4F3yQa4oFuIsyW6-h8BtTIu7daESekmtXm8NnMMv5IRpZtVFCvdrLr-CAAA___jBYZm">