Fold comparisons between sqrt and zero
commitb5cb051268ac3cf810bb1fb84daabdc38c97cc94
authorrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Oct 2015 11:51:43 +0000 (27 11:51 +0000)
committerrsandifo <rsandifo@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 27 Oct 2015 11:51:43 +0000 (27 11:51 +0000)
tree81cfb3c2323bef8e2dc2dea990e95e29dc92fc9d
parente1da2e5d4c6b0c99577c44b705ffe07bcbedfe57
Fold comparisons between sqrt and zero

The expression:

      signbit(sqrt(x))

is always 0 for -ffast-math.  The signbit fold first converts it to:

      sqrt(x) < 0

and whether we realise that this is false depends on a race between two
folders: the sqrt comparison folder, which wants to convert it to

      x < 0*0

and the generic tree_expr_nonnegative_p rule for ... < 0, which would
give the hoped-for 0.

The sqrt code already handles comparisons with negative values specially,
so this patch simply extends that idea to comparisons with zero.

Tested on x86_64-linux-gnu, aarch64-linux-gnu and arm-linux-gnueabi.

gcc/
* match.pd: Handle sqrt(x) cmp 0 specially.

gcc/testsuite/
* gcc.dg/torture/builtin-sqrt-cmp-1.c: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@229422 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/ChangeLog
gcc/match.pd
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/builtin-sqrt-cmp-1.c [new file with mode: 0644]