[PATCH] Fix PR27084, missed copyprop due to C++ compatible-types langhook

Richard Guenther rguenther@suse.de
Thu Apr 20 11:40:00 GMT 2006


This fixes copy propagation for pointers only differing in toplevel
qualifiers.  It adjusts behavior to that of the respective C langhook.

Bootstrapped and tested on x86_64-unknown-linux-gnu for all C++ish
languages.

Ok for mainline?

Thanks,
Richard.

:ADDPATCH c++:

2006-04-20  Richard Guenther  <rguenther@suse.de>
	Andrew Pinski  <pinskia@gcc.gnu.org>

	PR c++/27084
	* cp-objcp-common.c (cxx_types_compatible_p): Ignore
	top level qualifiers for pointer type comparisons.

	* g++.dg/tree-ssa/copyprop-1.C: New testcase.

Index: cp/cp-objcp-common.c
===================================================================
*** cp/cp-objcp-common.c	(revision 112884)
--- cp/cp-objcp-common.c	(working copy)
*************** cxx_types_compatible_p (tree x, tree y)
*** 179,185 ****
    if (POINTER_TYPE_P (x) && POINTER_TYPE_P (y)
        && TYPE_MODE (x) == TYPE_MODE (y)
        && TYPE_REF_CAN_ALIAS_ALL (x) == TYPE_REF_CAN_ALIAS_ALL (y)
!       && same_type_p (TREE_TYPE (x), TREE_TYPE (y)))
      return 1;
  
    return 0;
--- 179,186 ----
    if (POINTER_TYPE_P (x) && POINTER_TYPE_P (y)
        && TYPE_MODE (x) == TYPE_MODE (y)
        && TYPE_REF_CAN_ALIAS_ALL (x) == TYPE_REF_CAN_ALIAS_ALL (y)
!       && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (x),
! 						    TREE_TYPE (y)))
      return 1;
  
    return 0;
Index: testsuite/g++.dg/tree-ssa/copyprop-1.C
===================================================================
*** testsuite/g++.dg/tree-ssa/copyprop-1.C	(revision 0)
--- testsuite/g++.dg/tree-ssa/copyprop-1.C	(revision 0)
***************
*** 0 ****
--- 1,29 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-dce2" } */
+ 
+ /* Verify that we can eliminate the useless conversions to/from
+    const qualified pointer types
+      this_2 = o_1;
+      D.20003_4 = this_2->data_m;
+      this_5 = D.20003_4;
+      D.20005_6 = this_5->value;
+    copyprop should propagate o_1 and D.20003_4 to the loads of data_m
+    and value.  dce removes all traces of this.  */
+ 
+ struct Data {
+   int get() const { return value; }
+   int value;
+ };
+ 
+ struct Object {
+   int operator[](int i) const { return data_m->get(); }
+   Data *data_m;
+ };
+ 
+ int foo(Object&o)
+ {
+   return o[0];
+ }
+ 
+ /* { dg-final { scan-tree-dump-not "this" "dce2" } } */
+ /* { dg-final { cleanup-tree-dump "dce2" } } */



More information about the Gcc-patches mailing list