This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
This patch adds a transformation of builtin finite(x) into:
tmp = x - x; result = tmp ORD tmp;
We already do something similar (but simpler) for builtin isnan.
This particular transformation works because "x - x" turns Inf into NaN, while preserving an existing NaN. Then the ORD returns true if we don't have NaN, i.e. a finite original value. (I got the idea from libgcc2.c.)
One glich was that the "x - x" got folded to zero with only the flag -funsafe-math-optimizations. I added an additional check on !HONOR_NANS and !HONOR_INFINITIES to those transformations. These macros check (among other things) for -ffinite-math-only before folding "x - x". I had to leave the "unsafe" check in there because the comments indicate that there are some wierd corner cases where folding "x - x" to zero is actually invalid for non-ieee finite values.
I also filled out the existing two tests with more cases to cover all floating point types.
Tested on sparc-sun-solaris2.10, no regressions and all the testcases pass.
Okay for mainline?
Andrew is right about x - x trapping if x is a signalling NaN or +Inf or -Inf (invalid operation exception), x is a denormal (denormal operand exception). So the transformation is only valid for non-trapping math. Btw. - is it actually faster to use the new sequence than fxam in x87 math? How do code size compare to a function call? (Just to see if we should add a finite optab as well to allow the target to override the general expansion and conditionalize on OPTIMIZE_SIZE).
Thanks, Richard.
Thanks, --Kaveh
2007-06-11 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* builtins.c (fold_builtin_classify): Transform builtin finite.
* fold-const.c (fold_binary): Guard (X-X) -> 0 transformation with !HONOR_NANS and !HONOR_INFINITIES. * simplify-rtx.c (simplify_binary_operation_1): Likewise.
testsuite: * gcc.dg/pr28796-1.c: Add more cases. * gcc.dg/pr28796-2.c: Likewise.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |