------- Additional Comments From jakub at gcc dot gnu dot org 2005-02-22 14:15 ------- This is a DOM bug. Comment above lookup_avail_expr says: NOTE: This function assumes that STMT is a MODIFY_EXPR node that contains no CALL_EXPR on its RHS and makes no volatile nor aliased references. */ and I have no reason not to believe this, if not perhaps for const calls, then certainly for pure calls. For pure calls the code would need to invalidate all recorded pure calls whenever a stmt might modify global state. But optimize_stmt/eliminate_redundant_computations will happily call lookup_avail_expr with a CALL_EXPR on the RHS, because const/pure calls don't have TREE_SIDE_EFFECTS set.
I have tried: --- tree-ssa-dom.c.jj 2005-02-17 20:02:58.000000000 +0100 +++ tree-ssa-dom.c 2005-02-22 14:40:14.912216290 +0100 @@ -2964,7 +2964,8 @@ optimize_stmt (struct dom_walk_data *wal || (TREE_CODE (stmt) == MODIFY_EXPR && ! TREE_SIDE_EFFECTS (TREE_OPERAND (stmt, 1))) || TREE_CODE (stmt) == COND_EXPR - || TREE_CODE (stmt) == SWITCH_EXPR)); + || TREE_CODE (stmt) == SWITCH_EXPR) + && get_call_expr_in (stmt) == NULL); if (may_optimize_p) may_have_exposed_new_symbols which fixes this, but it seems no other tree-SSA optimization is able to optimize say extern int foo (void) __attribute__((pure)); ... a = foo (); a += foo (); into a = 2 * foo ();, fortunately RTL optimizations optimize that. If const calls are actually handled correctly by lookup_avail_expr, then the comment above it ought to be changed and we could only avoid optimizing DECL_IS_PURE calls in addition to TREE_SIDE_EFFECTS rhs' in optimize_stmt. -- What |Removed |Added ---------------------------------------------------------------------------- CC| |law at redhat dot com, | |dnovillo at redhat dot com Severity|normal |critical http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20115