This is an archive of the discontinued LLVM Phabricator instance.

Broaden optimization of fcmp ([us]itofp x, constant)
ClosedPublic

Authored by ArchDRobison on Jul 14 2015, 6:29 PM.

Details

Summary

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?

Diff Detail

Event Timeline

ArchDRobison retitled this revision from to Broaden optimization of fcmp ([us]itofp x, constant).
ArchDRobison updated this object.
ArchDRobison added reviewers: silvas, arsenm.
ArchDRobison added a subscriber: llvm-commits.

Ping. Just a reminder that this patch needs review and approval. I've had one floating-point expert, but who does not work on LLVM, look it over so far ( https://github.com/JuliaLang/julia/issues/11987#issuecomment-124238779 ).

Updated as diff against 2015-8-24 trunk. No changes to logic.

majnemer added a subscriber: majnemer.

Adding @chandlerc and @scanon.

Could either of you (preferably both of you) take a look at this?

scanon accepted this revision.Sep 15 2015, 7:10 AM
scanon edited edge metadata.

Looks good to me. Apologies for delay in getting to this one.

This revision is now accepted and ready to land.Sep 15 2015, 7:10 AM
silvas resigned from this revision.Jul 8 2016, 11:46 PM
silvas removed a reviewer: silvas.
Eugene.Zelenko added a subscriber: Eugene.Zelenko.

Committed in rL247708.