Bug 27084 - Does not propagate memory load base through useless type conversion
Summary: Does not propagate memory load base through useless type conversion
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.2.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on:
Blocks: 22501 27181
  Show dependency treegraph
 
Reported: 2006-04-08 17:04 UTC by Richard Biener
Modified: 2007-10-29 22:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-04-12 01:20:10


Attachments
prototype patch (561 bytes, patch)
2006-04-08 17:09 UTC, Richard Biener
Details | Diff
updated patch (818 bytes, patch)
2006-04-12 13:37 UTC, Richard Biener
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2006-04-08 17:04:19 UTC
Consider

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];
}

here we have after forwprop

int foo(Object&) (o)
{
  struct Object * const this;
  struct Data * D.20003;
  int D.20005;
  struct Data * const this;

<bb 2>:
  this_2 = o_1;
  D.20003_4 = this_2->data_m;
  this_5 = D.20003_4;
  D.20005_6 = this_5->value;
  D.20005_7 = D.20005_6;
  D.20005_8 = D.20005_7;
  D.20005_9 = D.20005_8;
  D.20005_10 = D.20005_9;
  return D.20005_10;

}

both memory loads could load from o_1 and D.20003_4 respectively.
Comment 1 Richard Biener 2006-04-08 17:09:49 UTC
Created attachment 11227 [details]
prototype patch

I have a prototype patch for forwprop that handles this, but somehow messes up virtual operands.  We get a non-ssaname VUSE:

#   VUSE <opD.8355>;
D.6255_561 = D.6253_558->typeD.4890

during build of libcpp.
Comment 2 Richard Biener 2006-04-08 17:21:57 UTC
Hm, we have from DCE to forwprop

  struct cpp_token * D.6254;
  struct cpp_token * D.6253;

   #   temp_1334 = V_MAY_DEF <temp_330>;
   #   unsignedp_1335 = V_MAY_DEF <unsignedp_333>;
   #   op_1336 = V_MAY_DEF <op_351>;
   #   SMT.698_1337 = V_MAY_DEF <SMT.698_1262>;
   #   SMT.700_1338 = V_MAY_DEF <SMT.700_1287>;
   #   SMT.703_1339 = V_MAY_DEF <SMT.703_1307>;
   D.6253_558 = cpp_get_token (pfile_475);
   D.6254_560 = D.6253_558;
-  #   VUSE <op_1336>;
-  D.6255_561 = D.6254_560->type;
+  D.6255_561 = D.6253_558->type;
   D.6256_562 = (cpp_ttype) D.6255_561;
   #   SFT.637_563 = V_MUST_DEF <SFT.637_360>;
   op.op = D.6256_562;
Comment 3 Richard Biener 2006-04-08 18:31:16 UTC
Of course this is from tramp3d, and I hope fixing it would enable the hoisting of more invariant loads out of the inner loops.
Comment 4 Richard Biener 2006-04-08 18:58:23 UTC
hmhm, merge_alias_info seems to fix it
Comment 5 Andrew Pinski 2006-04-08 19:09:09 UTC
forwrop when propragating better be using merge_ssa_info anyways, just like copy prop and such.
Comment 6 Andrew Pinski 2006-04-08 23:11:20 UTC
Here is the patch which fixes this issue for me:
Index: cp-objcp-common.c
===================================================================
--- cp-objcp-common.c   (revision 112789)
+++ cp-objcp-common.c   (working copy)
@@ -179,7 +179,7 @@ cxx_types_compatible_p (tree x, tree y)
   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)))
+      && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (x), TREE_TYPE (y)))
     return 1;
 
   return 0;
Comment 7 Andrew Pinski 2006-04-08 23:28:45 UTC
I am testing the C++ patch right now.  It is always a better idea to fix a pass to do what it should be doing instead of hacking another one to do the same.
Comment 8 Andrew Pinski 2006-04-12 01:20:10 UTC
The C++ patch fixes the problem with this code and it also finished bootstrapping without any regression so please test it fully and submit it instead of your hack.
Comment 9 Richard Biener 2006-04-12 13:35:46 UTC
PASS: g++.old-deja/g++.mike/dyncast7.C (test for excess errors)
FAIL: g++.old-deja/g++.mike/dyncast7.C execution test

const Foo* and Foo* are really not compatible.  We can just exchange Foo* for const Foo* for loads.
Comment 10 Richard Biener 2006-04-12 13:37:35 UTC
Created attachment 11250 [details]
updated patch

Patch I will clean and test instead.  Also fixes 27090.
Comment 11 Andrew Pinski 2006-04-12 17:40:15 UTC
(In reply to comment #9)
> PASS: g++.old-deja/g++.mike/dyncast7.C (test for excess errors)
> FAIL: g++.old-deja/g++.mike/dyncast7.C execution test

I did not get that failure.
Comment 12 patchapp@dberlin.org 2006-04-20 11:45:23 UTC
Subject: Bug number PR27084

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2006-04/msg00750.html
Comment 13 Richard Biener 2006-07-05 10:54:25 UTC
Subject: Bug 27084

Author: rguenth
Date: Wed Jul  5 10:54:17 2006
New Revision: 115200

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115200
Log:
2006-07-05  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.

Added:
    trunk/gcc/testsuite/g++.dg/tree-ssa/copyprop-1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-objcp-common.c
    trunk/gcc/testsuite/ChangeLog

Comment 14 Richard Biener 2006-07-05 10:58:56 UTC
Fixed.
Comment 15 Richard Biener 2006-08-02 20:49:09 UTC
Subject: Bug 27084

Author: rguenth
Date: Wed Aug  2 20:48:59 2006
New Revision: 115887

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=115887
Log:
2006-08-02  Richard Guenther  <rguenther@suse.de>

      PR c++/28479
      Revert
      2006-07-05  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: XFAIL.

Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/cp-objcp-common.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/tree-ssa/copyprop-1.C

Comment 16 Richard Biener 2006-08-02 20:50:32 UTC
Patch was reverted.
Comment 17 Mark Mitchell 2007-05-14 22:26:23 UTC
Will not be fixed in 4.2.0; retargeting at 4.2.1.
Comment 18 Mark Mitchell 2007-10-09 19:21:54 UTC
Change target milestone to 4.2.3, as 4.2.2 has been released.
Comment 19 Richard Biener 2007-10-29 22:12:53 UTC
This is fixed on the mainline by the middle-end type-system and the first
forwprop pass.  cxx_types_compatible_p is no longer involved for pointer types.