[PATCH] improve C++ code by changing fold-const.c
Andrew Pinski
pinskia@physics.uc.edu
Thu May 27 10:07:00 GMT 2004
Oh here are the three patches:
Patch 1 uses lang_hooks.types_compatible_p, patch 2
uses memory equality, patch 3 uses memory equality
on TYPE_MAIN_VARIANT.
Patch1:
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.376
diff -u -p -r1.376 fold-const.c
--- fold-const.c 15 May 2004 23:07:49 -0000 1.376
+++ fold-const.c 16 May 2004 23:09:54 -0000
@@ -5815,6 +5815,17 @@ fold (tree expr)
if (TREE_TYPE (TREE_OPERAND (t, 0)) == type)
return TREE_OPERAND (t, 0);
+ if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
+ {
+ tree inside_tree = TREE_OPERAND (t, 0);
+ tree inside_type = TREE_TYPE (inside_tree);
+ if (POINTER_TYPE_P (inside_type)
+ && POINTER_TYPE_P (type)
+ && lang_hooks.types_compatible_p (TREE_TYPE (type),
+ TREE_TYPE (inside_type)))
+ return build (ADDR_EXPR, type, TREE_OPERAND (inside_tree, 0));
+ }
+
/* Handle cases of two conversions in a row. */
if (TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
|| TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)
Patch2:
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.379
diff -u -p -r1.379 fold-const.c
--- fold-const.c 21 May 2004 00:54:35 -0000 1.379
+++ fold-const.c 21 May 2004 14:20:42 -0000
@@ -5672,6 +5672,19 @@ fold (tree expr)
if (TREE_TYPE (TREE_OPERAND (t, 0)) == type)
return TREE_OPERAND (t, 0);
+ /* If this is an address casted to a compatible
+ pointer type then just create a new address expression. */
+ if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
+ {
+ tree outer_type = TREE_TYPE (t);
+ tree inner_type = TREE_TYPE (TREE_OPERAND (t, 0));
+ if (POINTER_TYPE_P (inner_type)
+ && POINTER_TYPE_P (outer_type)
+ && TREE_TYPE (inner_type) == TREE_TYPE (outer_type))
+ return build1 (ADDR_EXPR, outer_type,
+ TREE_OPERAND (TREE_OPERAND (t, 0), 0));
+ }
+
/* Handle cases of two conversions in a row. */
if (TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
|| TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)
Patch3:
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.379
diff -u -p -r1.379 fold-const.c
--- fold-const.c 21 May 2004 00:54:35 -0000 1.379
+++ fold-const.c 21 May 2004 15:24:48 -0000
@@ -5672,6 +5672,20 @@ fold (tree expr)
if (TREE_TYPE (TREE_OPERAND (t, 0)) == type)
return TREE_OPERAND (t, 0);
+ /* If this is an address casted to a compatible
+ pointer type then just create a new address expression. */
+ if (TREE_CODE (TREE_OPERAND (t, 0)) == ADDR_EXPR)
+ {
+ tree outer_type = TREE_TYPE (t);
+ tree inner_type = TREE_TYPE (TREE_OPERAND (t, 0));
+ if (POINTER_TYPE_P (inner_type)
+ && POINTER_TYPE_P (outer_type)
+ && TYPE_MAIN_VARIANT (TREE_TYPE (inner_type))
+ == TYPE_MAIN_VARIANT (TREE_TYPE (outer_type)))
+ return build1 (ADDR_EXPR, outer_type,
+ TREE_OPERAND (TREE_OPERAND (t, 0), 0));
+ }
+
/* Handle cases of two conversions in a row. */
if (TREE_CODE (TREE_OPERAND (t, 0)) == NOP_EXPR
|| TREE_CODE (TREE_OPERAND (t, 0)) == CONVERT_EXPR)
More information about the Gcc-patches
mailing list