From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30992 invoked by alias); 15 May 2003 22:48:41 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 30885 invoked from network); 15 May 2003 22:48:36 -0000 Received: from unknown (HELO piper.synopsys.com) (204.176.21.196) by sources.redhat.com with SMTP; 15 May 2003 22:48:36 -0000 Received: (from jbuck@localhost) by piper.synopsys.com (8.11.6/8.11.6) id h4FMmTQ19241; Thu, 15 May 2003 15:48:29 -0700 Date: Thu, 15 May 2003 22:48:00 -0000 From: Joe Buck To: Richard Henderson , Diego Novillo , "gcc@gcc.gnu.org" Subject: Re: [tree-ssa] copy propagation and the abstraction penalty Message-ID: <20030515154829.A19150@synopsys.com> References: <20030514154455.A12416@synopsys.com> <1053007822.4382.137.camel@frodo.toronto.redhat.com> <20030515221748.GC10321@redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <20030515221748.GC10321@redhat.com>; from rth@redhat.com on Thu, May 15, 2003 at 03:17:48PM -0700 X-SW-Source: 2003-05/txt/msg01563.txt.bz2 On Thu, May 15, 2003 at 03:17:48PM -0700, Richard Henderson wrote: > On Thu, May 15, 2003 at 10:10:22AM -0400, Diego Novillo wrote: > > I'm also wondering if we could change the > > may-alias between this and UV2150 to a must-alias, which would > > completely free this program from aliasing problems: > > Indeed. And for this case I definitely think it's the right thing to do. > > IMO constant propagation should be able to take > > T.8_2 = &; > { > struct complex * const this; > > this_3 = (struct complex * const)T.8_2; > { > this->re = 1.0e+0; > > and turn it into > > (&)->re = 1.0e+0 > > which folds to > > .re = 1.0e+0 > > At which point we have no aliasing problem, and a subsequent round > of constant propagation ought to be able to send 1.0e+0 to its > destination. That helps this case, but in many other cases the content of the temporary struct's field will be a variable, and we would still want to copy-propagate. For example, consider bit vector classes. Typically the [] operator will be overloaded to return a "bitref" object, which is a struct that has two fields: a reference to the bit vector, and a bit offset. The compiler should be able to eliminate the temporary object. We would have struct bitref; class bitvec { public: void set_bit(unsigned pos, bool value); bool get_bit(unsigned pos) const; inline bitref operator[](unsigned pos); }; struct bitref { bitref(bitvec& o, unsigned p) : obj(o), pos(p) {} bitvec& obj; unsigned pos; operator bool() const { return obj.get_bit(pos);} void operator=(bool value) { obj.set_bit(pos, value);} void operator=(const bitref& src) { obj.set_bit(pos, src);} }; inline bitref bitvec::operator[](unsigned pos) { return bitref(*this, pos);} and we want to compile void assign(bitvec& dest, bitvec& src, unsigned i, unsigned j) { dest[i] = src[j]; } Ideally, we should be able to do copy propagation good enough to turn this into dest.set_bit(i, src.get_bit(j)); which means that we can kill the two generated bitref objects. Note, though, that there are no constants. We have {&dest,i} and {&src,j}. This kind of thing occurs throughout common C++ codes, and really kills us on the Boost graph library.