This is the mail archive of the
mailing list for the GCC project.
Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication
- From: Fariborz Jahanian <fjahanian at apple dot com>
- To: Geoffrey Keating <geoffk at geoffk dot org>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 5 Oct 2004 13:04:05 -0700
- Subject: Re: Patch gcc-4.0 should not apply mathematical associative rules for addition or multiplication
- References: <2B2F21A1-16FF-11D9-957B-000A95BA54A6@apple.com> <email@example.com>
On Oct 5, 2004, at 12:52 PM, Geoffrey Keating wrote:
Fariborz Jahanian <firstname.lastname@example.org> writes:
OK for fsf mainline?
No, not OK.
- thanks, fariborz (email@example.com)
2004-10-05 Fariborz Jahanian <firstname.lastname@example.org>
* 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
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
+ 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
Which alternatives? flag_unsafe_math_optimizations was mentioned as the
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