The existing instruction-combining optimization FoldFCmp_IntToFP_Cst simplifies fcmp ([us]itofp x, constant) punts if the conversion of x might lose accuracy, unless the constant is positive zero. This patch makes the "lose accuracy" test slightly less conservative and lifts restrictions on the constant so that the following additional cases are handled:
- the constant's magnitude is so small that rounding of x is irrelevant.
- the constant's magnitude is so large that the rounding of x is irrelevant.
The first case includes negative zero. The last case includes comparing against infinity. Note that sufficiently large integers can exceed a floating-point format's range, so the last case still requires care. See the new i128 test for an example.
The patch just inspects the exponent of the constant, and so still leaves some optimizable cases behind, but those seem not worth adding further complexity.
Motivation for patch is a Julia issue https://github.com/JuliaLang/julia/issues/11987 . See thread starting with http://lists.cs.uiuc.edu/pipermail/llvmdev/2015-July/087630.html for more LLVM discussion.
Who is the code owner for this optimization?