From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15654 invoked by alias); 21 Feb 2005 19:31:01 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 15455 invoked by alias); 21 Feb 2005 19:30:50 -0000 Date: Mon, 21 Feb 2005 23:19:00 -0000 Message-ID: <20050221193050.15453.qmail@sourceware.org> From: "aoliva at redhat dot com" To: gcc-bugs@gcc.gnu.org In-Reply-To: <20050206101741.19786.sylvain.pion@sophia.inria.fr> References: <20050206101741.19786.sylvain.pion@sophia.inria.fr> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug tree-optimization/19786] [4.0 Regression] Aliasing optimisation bug X-Bugzilla-Reason: CC X-SW-Source: 2005-02/txt/msg02509.txt.bz2 List-Id: ------- Additional Comments From aoliva at gcc dot gnu dot org 2005-02-21 19:30 ------- Subject: [PR tree-optimization/19786] fix alias grouping lossage The problem here was that we added type tags to other tag's may-alias lists without adding them to the corresponding bitmaps. Later on, when group_aliases performed an union of the bitmaps and discarded the lists, we lost information about the aliases, which enabled LIM to hoist a pointer access out of a loop because it appeared to be invariant, since the VDEF supposed to modify it was missing. Thanks to Jakub for having isolated the source of the problem, and Diego for discussing tree-ssa alias analysis with me for a few hours today. Here's the patch I'm testing. Ok to install if it bootstraps and regtests successfully? Index: gcc/ChangeLog from Alexandre Oliva PR tree-optimization/19786 * tree-ssa-alias.c (compute_flow_insensitive_aliasing): Add one tag to another's may-alias bitmap when adding to the other's list. Index: gcc/tree-ssa-alias.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/tree-ssa-alias.c,v retrieving revision 2.69 diff -u -p -r2.69 tree-ssa-alias.c --- gcc/tree-ssa-alias.c 17 Feb 2005 16:19:42 -0000 2.69 +++ gcc/tree-ssa-alias.c 21 Feb 2005 19:15:40 -0000 @@ -1116,6 +1116,7 @@ compute_flow_insensitive_aliasing (struc /* Since TAG2 does not have any aliases of its own, add TAG2 itself to the alias set of TAG1. */ add_may_alias (tag1, tag2); + SET_BIT (may_aliases1, var_ann (tag2)->uid); } } } Index: gcc/testsuite/ChangeLog from Alexandre Oliva PR tree-optimization/19786 * g++.dg/tree-ssa/pr19786.C: New. Index: gcc/testsuite/g++.dg/tree-ssa/pr19786.C =================================================================== RCS file: gcc/testsuite/g++.dg/tree-ssa/pr19786.C diff -N gcc/testsuite/g++.dg/tree-ssa/pr19786.C --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ gcc/testsuite/g++.dg/tree-ssa/pr19786.C 21 Feb 2005 19:15:54 -0000 @@ -0,0 +1,48 @@ +// { dg-do run } +/* { dg-options "-O2" } */ + +// We used to get alias grouping wrong on this one, hoisting accesses +// to the vector's end out of the loop. + +#include +#include + +struct A +{ + double unused; // If I remove it => it works. + std::vector v; + + A() : v(1) {} +}; + +inline // If not inline => it works. +A g() +{ + A r; + r.v.resize(2); + r.v[0] = 1; + + while (!r.v.empty() && r.v.back() == 0) + r.v.pop_back(); + + return r; +} + +A f(const A &a) +{ + if (a.v.empty()) return a; + if (a.v.empty()) return a; + + // A z = g(); return z; // If I return like this => it works. + return g(); +} + +int main() +{ + A a; + A b; + A r = f(a); + assert(r.v.size() != 0); + + return 0; +} -- Alexandre Oliva http://www.ic.unicamp.br/~oliva/ Red Hat Compiler Engineer aoliva@{redhat.com, gcc.gnu.org} Free Software Evangelist oliva@{lsd.ic.unicamp.br, gnu.org} -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19786