[PATCH] D11210: Broaden optimization of fcmp ([us]itofp x, constant)

Arch D. Robison arch.robison at intel.com
Tue Jul 14 18:29:17 PDT 2015


ArchDRobison created this revision.
ArchDRobison added reviewers: silvas, arsenm.
ArchDRobison added a subscriber: llvm-commits.

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?

http://reviews.llvm.org/D11210

Files:
  lib/Transforms/InstCombine/InstCombineCompares.cpp
  test/Transforms/InstCombine/cast-int-fcmp-eq-0.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11210.29737.patch
Type: text/x-patch
Size: 8652 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150715/d1dd9724/attachment.bin>


More information about the llvm-commits mailing list