This is an archive of the discontinued LLVM Phabricator instance.

Mark some FP intrinsics as safe to speculatively execute
ClosedPublic

Authored by whitequark on Mar 31 2016, 6:06 AM.

Details

Summary

Mark some FP intrinsics as safe to speculatively execute

Floating point intrinsics in LLVM are generally not speculatively
executed, since most of them are defined to behave the same as libm
functions, which set errno.

However, the only error that can happen when executing ceil, floor,
nearbyint, rint and round libm functions per POSIX.1-2001 is -ERANGE,
and that requires the maximum value of the exponent to be smaller
than the number of mantissa bits, which is not the case with any of
the floating point types supported by LLVM.

The trunc and copysign functions never set errno per per POSIX.1-2001.

Context: our architecture uses soft-FP, and hoisting FP out of loops provides massive gains.
Often, LLVM can turn rapidly changing FP expressions into integer expressions, and hoist
slowly changing FP expressions out of loops. Hoisting FP intrinsics are the last low-hanging
fruit in our codebase.

Diff Detail

Repository
rL LLVM

Event Timeline

whitequark updated this revision to Diff 52193.Mar 31 2016, 6:06 AM
whitequark retitled this revision from to Mark llvm.round.* and llvm.rint.* intrinsics as safe to speculatively execute.
whitequark updated this object.
whitequark set the repository for this revision to rL LLVM.
whitequark added a subscriber: llvm-commits.
whitequark updated this object.Mar 31 2016, 6:12 AM

Yeah, speculation is safe for ceil/floor/nearbyint/rint/round. This needs a testcase though ;)

whitequark updated this revision to Diff 52497.Apr 3 2016, 4:17 AM
whitequark retitled this revision from Mark llvm.round.* and llvm.rint.* intrinsics as safe to speculatively execute to Mark some FP intrinsics as safe to speculatively execute.
whitequark updated this object.

Added a test; updated to include the complete list of LLVM FP intrinsics that are safe to speculate (excluding the fp16 conversion ones, since I don't really know anything about them).

bkramer accepted this revision.Apr 3 2016, 5:04 AM
bkramer edited edge metadata.

looks good, thanks!

This revision is now accepted and ready to land.Apr 3 2016, 5:04 AM
This revision was automatically updated to reflect the committed changes.