Folding fix 1

Jan Hubicka jh@suse.cz
Sun Dec 21 11:04:00 GMT 2003


Hi,
by canonicalizing expresisons in (addr_expr (array_ref ...
we lose some of string optimization as string_constant understand
(plus_expr (addr_expr ...) (const_int ...)) but not the array_ref
variant.
This shows as an regression on string-* when patch to fold each
statement after gimplification is applied.

Bootstrapped/regtested i686-pc-gnu-linux
OK?

2003-12-21  Jan Hubicka  <jh@suse.cz>
	* expr.c (string_constant): Recognize array_ref.
Index: expr.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/expr.c,v
retrieving revision 1.467.2.70
diff -c -3 -p -r1.467.2.70 expr.c
*** expr.c	17 Dec 2003 20:25:55 -0000	1.467.2.70
--- expr.c	20 Dec 2003 22:22:25 -0000
*************** string_constant (tree arg, tree *ptr_off
*** 9433,9438 ****
--- 9433,9445 ----
        *ptr_offset = size_zero_node;
        return TREE_OPERAND (arg, 0);
      }
+   if (TREE_CODE (arg) == ADDR_EXPR
+       && TREE_CODE (TREE_OPERAND (arg, 0)) == ARRAY_REF
+       && TREE_CODE (TREE_OPERAND (TREE_OPERAND (arg, 0), 0)) == STRING_CST)
+     {
+       *ptr_offset = convert (sizetype, TREE_OPERAND (TREE_OPERAND (arg, 0), 1));
+       return TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
+     }
    else if (TREE_CODE (arg) == PLUS_EXPR)
      {
        tree arg0 = TREE_OPERAND (arg, 0);



More information about the Gcc-patches mailing list