This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] improve C++ code by changing fold-const.c



On May 20, 2004, at 23:00, law@redhat.com wrote:


In message <20040520225634.GA5401@redhat.com>, Richard Henderson writes:
On Thu, May 20, 2004 at 04:36:39PM -0600, Roger Sayle wrote:
Is your preference for ADDR_EXPR to be allowed to be a form of
conversion operator, or to clean-up the existing mismatches?

I dunno. As Jeff mentions, it has constant propagation implications. As far as it goes, the current implied conversions are merely array-to-pointer decomposition.
My preference would to _not_ have ADDR_EXPR be a conversion operator and
instead look at:

Patch1 removes the conversion operator but does not helps C++ code as for some reason when the reference is taken there is a different type for the struct which the reference points to than what the pointer points to. This one would help the secondary inliner (which does not exist yet but I hear that Honza is working on it).

On the other hand just checking to see if the types have the same
TYPE_MAIN_VARIANT helps C++ code and fixes both the PRs which I
wanted to fix, see Patch2.

Both bootstraped and tested with no regressions.

I would at least like the first one approved, getting the second one
approved would mean that the compile time and generated code for C++
would greatly improve.

Patch1:
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)




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 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)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]