c++/6546: static const members optimization failure
jakub@gcc.gnu.org
jakub@gcc.gnu.org
Fri May 3 10:07:00 GMT 2002
Synopsis: static const members optimization failure
State-Changed-From-To: open->analyzed
State-Changed-By: jakub
State-Changed-When: Fri May 3 10:07:14 2002
State-Changed-Why:
I think this basically waits for the AST optimizations.
In the meantime, something like:
--- gcc/expr.c.jj Fri May 3 18:58:54 2002
+++ gcc/expr.c Fri May 3 19:12:33 2002
@@ -6667,6 +6667,35 @@ expand_expr (exp, target, tmode, modifie
GEN_INT (trunc_int_for_mode (TREE_STRING_POINTER (string)
[TREE_INT_CST_LOW (index)], mode));
+ /* Try to optimize references to constant variables. */
+ if (optimize && TREE_READONLY (exp) && modifier != EXPAND_WRITE)
+ {
+ tree tem = exp1;
+ if (TREE_CODE (tem) == NOP_EXPR
+ && TREE_CODE (TREE_TYPE (tem)) == REFERENCE_TYPE
+ && TREE_TYPE (TREE_TYPE (tem)) == type
+ && TREE_READONLY (tem)
+ && TREE_CONSTANT (tem))
+ tem = TREE_OPERAND (tem, 0);
+ if (TREE_CODE (tem) == ADDR_EXPR
+ && TREE_CODE (TREE_TYPE (tem)) == POINTER_TYPE
+ && TREE_TYPE (TREE_TYPE (tem)) == type
+ && TREE_READONLY (tem)
+ && TREE_CONSTANT (tem))
+ {
+ tem = TREE_OPERAND (tem, 0);
+ if (TREE_CODE (tem) == VAR_DECL
+ && TREE_TYPE (tem) == type
+ && TREE_READONLY (tem)
+ && ! TREE_SIDE_EFFECTS (tem)
+ && DECL_INITIAL (tem)
+ && DECL_INITIAL (tem) != error_mark_node)
+ /* Record the actual variable decl below into MEM
+ attributes. */
+ exp = tem;
+ }
+ }
+
op0 = expand_expr (exp1, NULL_RTX, VOIDmode, EXPAND_SUM);
op0 = memory_address (mode, op0);
temp = gen_rtx_MEM (mode, op0);
and teaching CSE that for MEM/u which has MEM_EXPR set
to some VAR_DECL which is constant it could try to REG_EQUAL
it to that constant.
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=6546
More information about the Gcc-bugs
mailing list