This is the mail archive of the 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]

Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication

On Oct 5, 2004, at 12:52 PM, Geoffrey Keating wrote:

Fariborz Jahanian <> writes:

OK for fsf mainline?

No, not OK.

- thanks, fariborz (


2004-10-05 Fariborz Jahanian <>

        * tree-ssa-dom.c (associative_fp_binop): New function.
        (simplify_rhs_and_lookup_avail_expr): Disallow associativity
        and constant folding of floating point MULT_EXPR/PLUS_EXPR

Index: tree-ssa-dom.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/tree-ssa-dom.c,v retrieving revision 2.56 diff -c -p -r2.56 tree-ssa-dom.c *** tree-ssa-dom.c 29 Sep 2004 02:50:46 -0000 2.56 --- tree-ssa-dom.c 5 Oct 2004 16:53:05 -0000 *************** static void restore_currdefs_to_original *** 266,271 **** --- 266,272 ---- static void register_definitions_for_stmt (tree); static edge single_incoming_edge_ignoring_loop_edges (basic_block); static void restore_nonzero_vars_to_original_value (void); + static inline bool associative_fp_binop (tree);

/* Local version of fold that doesn't introduce cruft. */

*************** record_equality (tree x, tree y)
*** 1547,1552 ****
--- 1548,1563 ----
    record_const_or_copy_1 (x, y, prev_x);

+ /* return true, if it is ok to do folding of an associative expression */
+ static inline bool
+ associative_fp_binop (tree exp)
+ {
+ enum tree_code code = TREE_CODE (exp);
+ return !(!flag_unsafe_math_optimizations

This flag is not clearly the right one. Why did you pick it from the alternatives?

Which alternatives? flag_unsafe_math_optimizations was mentioned as the one
to check for by all people who commented on this thread.

+            && (code == MULT_EXPR || code == PLUS_EXPR)
+            && FLOAT_TYPE_P (TREE_TYPE (exp)));

This function appears to disallow folding

(x * 2.0) * 2.0


x * 4.0

which seems to me to be valid.

Wording of ANSIC disallows such foldings even if it is safe sometimes.

Please provide a testcase as part of the patch in proper dejagnu format.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]