Should gcc-4.0 apply mathematical associative rules for addition or multiplication
Andrew Pinski
pinskia@physics.uc.edu
Mon Oct 4 23:34:00 GMT 2004
On Oct 4, 2004, at 6:56 PM, Fariborz Jahanian wrote:
> /* test */
> static const double C = 0x1.0p1023;
>
> double foo(double x)
> {
> return ( ( (x * C) * C ) * C );
> }
>
> This is done in routine: simplify_rhs_and_lookup_avail_expr(...) which
> is preceded with this comment:
>
> /* If we have z = (x OP C1), see if we earlier had x = y OP C2.
> If OP is associative, create and fold (y OP C2) OP C1 which
> should result in (y OP C3), use that as the RHS for the
> assignment. Add minus to this, as we handle it specially below.
> */
This patch should work:
Index: tree-ssa-dom.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v
retrieving revision 2.58
diff -u -p -r2.58 tree-ssa-dom.c
--- tree-ssa-dom.c 4 Oct 2004 13:19:20 -0000 2.58
+++ tree-ssa-dom.c 4 Oct 2004 23:05:28 -0000
@@ -1598,7 +1598,9 @@ simplify_rhs_and_lookup_avail_expr (stru
assignment. Add minus to this, as we handle it specially below.
*/
if ((associative_tree_code (rhs_code) || rhs_code == MINUS_EXPR)
&& TREE_CODE (TREE_OPERAND (rhs, 0)) == SSA_NAME
- && is_gimple_min_invariant (TREE_OPERAND (rhs, 1)))
+ && is_gimple_min_invariant (TREE_OPERAND (rhs, 1))
+ && (!FLOAT_TYPE_P (type)
+ || flag_unsafe_math_optimizations))
{
tree rhs_def_stmt = SSA_NAME_DEF_STMT (TREE_OPERAND (rhs, 0));
Thanks,
Andrew Pinski
More information about the Gcc
mailing list