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.
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.
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;
Of course this is from tramp3d, and I hope fixing it would enable the hoisting of more invariant loads out of the inner loops.
hmhm, merge_alias_info seems to fix it
forwrop when propragating better be using merge_ssa_info anyways, just like copy prop and such.
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;
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.
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.
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.
Created attachment 11250 [details] updated patch Patch I will clean and test instead. Also fixes 27090.
(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.
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
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
Fixed.
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
Patch was reverted.
Will not be fixed in 4.2.0; retargeting at 4.2.1.
Change target milestone to 4.2.3, as 4.2.2 has been released.
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.