Gentoo Archives: gentoo-commits

From: "Ryan Hill (dirtyepic)" <dirtyepic@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo commit in src/patchsets/gcc/4.7.2/gentoo: 96_all_pr56125_4.7.3_ffast-math-pow.patch README.history
Date: Tue, 26 Feb 2013 01:09:14
Message-Id: 20130226010910.574782171D@flycatcher.gentoo.org
1 dirtyepic 13/02/26 01:09:10
2
3 Modified: README.history
4 Added: 96_all_pr56125_4.7.3_ffast-math-pow.patch
5 Log:
6 Add patch for PR56125.
7
8 Revision Changes Path
9 1.10 src/patchsets/gcc/4.7.2/gentoo/README.history
10
11 file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/gcc/4.7.2/gentoo/README.history?rev=1.10&view=markup
12 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/gcc/4.7.2/gentoo/README.history?rev=1.10&content-type=text/plain
13 diff : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/gcc/4.7.2/gentoo/README.history?r1=1.9&r2=1.10
14
15 Index: README.history
16 ===================================================================
17 RCS file: /var/cvsroot/gentoo/src/patchsets/gcc/4.7.2/gentoo/README.history,v
18 retrieving revision 1.9
19 retrieving revision 1.10
20 diff -u -r1.9 -r1.10
21 --- README.history 25 Feb 2013 03:49:18 -0000 1.9
22 +++ README.history 26 Feb 2013 01:09:10 -0000 1.10
23 @@ -1,3 +1,6 @@
24 +1.5 pending
25 + + 96_all_pr56125_4.7.3_ffast-math-pow.patch
26 +
27 1.4 24 Jan 2013
28 - 03_all_java-nomulti.patch
29 + 48_all_x86_pr53113_libitm-avx.patch
30
31
32
33 1.1 src/patchsets/gcc/4.7.2/gentoo/96_all_pr56125_4.7.3_ffast-math-pow.patch
34
35 file : http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/gcc/4.7.2/gentoo/96_all_pr56125_4.7.3_ffast-math-pow.patch?rev=1.1&view=markup
36 plain: http://sources.gentoo.org/viewvc.cgi/gentoo/src/patchsets/gcc/4.7.2/gentoo/96_all_pr56125_4.7.3_ffast-math-pow.patch?rev=1.1&content-type=text/plain
37
38 Index: 96_all_pr56125_4.7.3_ffast-math-pow.patch
39 ===================================================================
40 -O2 -ffast-math generates bad code when dividing a double by the square of another double.
41
42 http://gcc.gnu.org/PR56125
43
44
45 commit a42ec1527275f12e8584e1640bc6b16a9d2ca858
46 Author: jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
47 Date: Fri Feb 1 14:17:50 2013 +0000
48
49 Backported from mainline
50 2013-01-28 Jakub Jelinek <jakub@××××××.com>
51
52 PR tree-optimization/56125
53 * tree-ssa-math-opts.c (gimple_expand_builtin_pow): Don't optimize
54 pow(x,c) into sqrt(x) * powi(x, n/2) or
55 1.0 / (sqrt(x) * powi(x, abs(n/2))) if c is an integer or when
56 optimizing for size.
57 Don't optimize pow(x,c) into powi(x, n/3) * powi(cbrt(x), n%3) or
58 1.0 / (powi(x, abs(n)/3) * powi(cbrt(x), abs(n)%3)) if 2c is an
59 integer.
60
61 * gcc.dg/pr56125.c: New test.
62
63
64 git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@195664 138bc75d-0d04-0410-961f-82ee72b054a4
65 ---
66 gcc/ChangeLog | 11 +++++++++++
67 gcc/testsuite/ChangeLog | 5 +++++
68 gcc/testsuite/gcc.dg/pr56125.c | 21 +++++++++++++++++++++
69 gcc/tree-ssa-math-opts.c | 14 ++++++++++----
70 4 files changed, 47 insertions(+), 4 deletions(-)
71
72 --- /dev/null
73 +++ b/gcc/testsuite/gcc.dg/pr56125.c
74 @@ -0,0 +1,21 @@
75 +/* PR tree-optimization/56125 */
76 +/* { dg-do run } */
77 +/* { dg-options "-O2 -ffast-math" } */
78 +
79 +extern void abort (void);
80 +extern double fabs (double);
81 +
82 +__attribute__((cold)) double
83 +foo (double x, double n)
84 +{
85 + double u = x / (n * n);
86 + return u;
87 +}
88 +
89 +int
90 +main ()
91 +{
92 + if (fabs (foo (29, 2) - 7.25) > 0.001)
93 + abort ();
94 + return 0;
95 +}
96 --- a/gcc/tree-ssa-math-opts.c
97 +++ b/gcc/tree-ssa-math-opts.c
98 @@ -1113,7 +1113,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
99 tree type, sqrtfn, cbrtfn, sqrt_arg0, sqrt_sqrt, result, cbrt_x, powi_cbrt_x;
100 tree target = NULL_TREE;
101 enum machine_mode mode;
102 - bool hw_sqrt_exists;
103 + bool hw_sqrt_exists, c_is_int, c2_is_int;
104
105 /* If the exponent isn't a constant, there's nothing of interest
106 to be done. */
107 @@ -1125,8 +1125,9 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
108 c = TREE_REAL_CST (arg1);
109 n = real_to_integer (&c);
110 real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0);
111 + c_is_int = real_identical (&c, &cint);
112
113 - if (real_identical (&c, &cint)
114 + if (c_is_int
115 && ((n >= -1 && n <= 2)
116 || (flag_unsafe_math_optimizations
117 && optimize_insn_for_speed_p ()
118 @@ -1224,7 +1225,8 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
119 return build_and_insert_call (gsi, loc, &target, cbrtfn, sqrt_arg0);
120 }
121
122 - /* Optimize pow(x,c), where n = 2c for some nonzero integer n, into
123 + /* Optimize pow(x,c), where n = 2c for some nonzero integer n
124 + and c not an integer, into
125
126 sqrt(x) * powi(x, n/2), n > 0;
127 1.0 / (sqrt(x) * powi(x, abs(n/2))), n < 0.
128 @@ -1233,10 +1235,13 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
129 real_arithmetic (&c2, MULT_EXPR, &c, &dconst2);
130 n = real_to_integer (&c2);
131 real_from_integer (&cint, VOIDmode, n, n < 0 ? -1 : 0, 0);
132 + c2_is_int = real_identical (&c2, &cint);
133
134 if (flag_unsafe_math_optimizations
135 && sqrtfn
136 - && real_identical (&c2, &cint))
137 + && c2_is_int
138 + && !c_is_int
139 + && optimize_function_for_speed_p (cfun))
140 {
141 tree powi_x_ndiv2 = NULL_TREE;
142
143 @@ -1289,6 +1294,7 @@ gimple_expand_builtin_pow (gimple_stmt_iterator *gsi, location_t loc,
144 && cbrtfn
145 && (gimple_val_nonnegative_real_p (arg0) || !HONOR_NANS (mode))
146 && real_identical (&c2, &c)
147 + && !c2_is_int
148 && optimize_function_for_speed_p (cfun)
149 && powi_cost (n / 3) <= POWI_MAX_MULTS)
150 {