From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 110672 invoked by alias); 22 Oct 2015 07:32:15 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 110662 invoked by uid 89); 22 Oct 2015 07:32:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.3 required=5.0 tests=AWL,BAYES_50,KAM_ASCII_DIVIDERS,RP_MATCHES_RCVD,SPF_PASS autolearn=no version=3.3.2 X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (CAMELLIA256-SHA encrypted) ESMTPS; Thu, 22 Oct 2015 07:32:13 +0000 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6B8C5AAC4; Thu, 22 Oct 2015 07:32:09 +0000 (UTC) Date: Thu, 22 Oct 2015 07:39:00 -0000 From: Richard Biener To: Jan Hubicka cc: gcc-patches@gcc.gnu.org Subject: Re: Handle CONSTRUCTOR in operand_equal_p In-Reply-To: <20151021190529.GB92763@kam.mff.cuni.cz> Message-ID: References: <20151014162702.GD16672@kam.mff.cuni.cz> <20151014235509.GC16831@kam.mff.cuni.cz> <9FF55B7D-8DEC-45C4-8FDD-5AA0344B2B15@suse.de> <20151021190529.GB92763@kam.mff.cuni.cz> User-Agent: Alpine 2.11 (LSU 23 2013-08-11) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-SW-Source: 2015-10/txt/msg02195.txt.bz2 On Wed, 21 Oct 2015, Jan Hubicka wrote: > Hi, > this is updated patch I am going to commit. As discussed, we also need to match > non-empty CONSTRUCTOR of vectors, but those should never be having CONSTANT flags > set, so they need care in the other path trhough operand_equal_p, so I will post > separate patch for that. > > I updated the comment per Richard's comment and added a testcase. Vuriously > enoug we fold "val? (struct a){} : (struct a){}" only in PRE (tailmerging). > W/o the patch even .optimized dump has the test and we fold it away only after > lowering to RTL: > ret (int val) > { > struct a D.1764; > > : > if (val_2(D) != 0) > goto ; > else > goto ; > > : > D.1764 = {}; > goto ; > > : > D.1764 = {}; > > : > return D.1764; > > } > > ret: > .LFB0: > .cfi_startproc > xorl %eax, %eax > ret > .cfi_endproc > > With the patch we get: > > ret (int val) > { > struct a D.1764; > > : > D.1764 = {}; > return D.1764; > > } But only via GENERIC folding I suppose. Yes, we don't value-number aggregates and generally PRE (and DOM via excessive jump-threading) is the only pass that remotely handles this kind of situation. code hoisting/sinking would maybe catch this but as this involves memory I'm not sure the implementation ontop of PRE that is stuck in some PR would catch it. Richard. > Honza > > * fold-const.c (operand_equal_p): Add code matching empty > constructors. > * gcc.dg/tree-ssa/operand-equal-1.c: Verify that empty constructors > are matched. > > Index: fold-const.c > =================================================================== > --- fold-const.c (revision 229133) > +++ fold-const.c (working copy) > @@ -2892,6 +2892,11 @@ operand_equal_p (const_tree arg0, const_ > return operand_equal_p (TREE_OPERAND (arg0, 0), TREE_OPERAND (arg1, 0), > flags | OEP_ADDRESS_OF > | OEP_CONSTANT_ADDRESS_OF); > + case CONSTRUCTOR: > + /* In GIMPLE empty constructors are allowed in initializers of > + aggregates. */ > + return (!vec_safe_length (CONSTRUCTOR_ELTS (arg0)) > + && !vec_safe_length (CONSTRUCTOR_ELTS (arg1))); > default: > break; > } > Index: testsuite/gcc.dg/tree-ssa/operand-equal-1.c > =================================================================== > --- testsuite/gcc.dg/tree-ssa/operand-equal-1.c (revision 0) > +++ testsuite/gcc.dg/tree-ssa/operand-equal-1.c (revision 0) > @@ -0,0 +1,8 @@ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -fdump-tree-pre" } */ > +struct a {int a,b;}; > +struct a ret(int val) > +{ > + return val? (struct a){} : (struct a){}; > +} > +/* { dg-final { scan-tree-dump-not "if " "pre"} } */ > > -- Richard Biener SUSE LINUX GmbH, GF: Felix Imendoerffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nuernberg)