Bug 55950 - Invalid sqrt constant propagation with -frounding-mode
Summary: Invalid sqrt constant propagation with -frounding-mode
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.8.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2013-01-11 22:12 UTC by Marc Glisse
Modified: 2013-11-21 16:21 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-01-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marc Glisse 2013-01-11 22:12:59 UTC
simplify_const_unary_operation (in simplify-rtx.c) does constant propagation for SQRT protected only by:

 	  if (HONOR_SNANS (mode) && real_isnan (&d))
 	    return 0;

With -frounding-math, it should check whether sqrt was exact and only propagate in that case (sqrt(1)=1, sqrt(.25)=.5, but sqrt(2) should wait for execution).

(note that this doesn't happen on a trivial sqrt(2.) example, but I've already seen it happen)
Comment 1 Richard Biener 2013-01-14 13:21:45 UTC
Confirmed.  real.c has all the bells and whistles to implement this I think.
Comment 2 Joseph S. Myers 2013-11-21 16:20:31 UTC
Author: jsm28
Date: Thu Nov 21 16:20:28 2013
New Revision: 205223

URL: http://gcc.gnu.org/viewcvs?rev=205223&root=gcc&view=rev
Log:
	PR rtl-optimization/55950
	* real.c (real_sqrt): Remove function.
	* real.h (real_sqrt): Remove prototype.
	* simplify-rtx.c (simplify_const_unary_operation): Do not fold
	SQRT using real_sqrt.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/real.c
    trunk/gcc/real.h
    trunk/gcc/simplify-rtx.c
Comment 3 Joseph S. Myers 2013-11-21 16:21:36 UTC
Fixed for 4.9 by removing this optimization, in the expectation that any important cases of sqrt constant folding are handled at the GIMPLE level which has proper checks for this.