From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 73851 invoked by alias); 30 Jul 2019 13:39:11 -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 73843 invoked by uid 89); 30 Jul 2019 13:39:10 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.4 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 30 Jul 2019 13:39:09 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 8D06EABF1; Tue, 30 Jul 2019 13:39:07 +0000 (UTC) Subject: Re: [PATCH] Remove also 2nd argument for unused delete operator (PR tree-optimization/91270). To: Marc Glisse Cc: Richard Biener , Jason Merrill , GCC Patches , David Malcolm , dominik.infuehr@theobroma-systems.com, Nathan Sidwell References: <8305B5F4-2A96-4698-8C2E-3255658B5C12@theobroma-systems.com> <74ce7d0b-2610-8cb6-4c22-60f9ed2bfc23@suse.cz> <3a940ca7-b024-61d1-3b05-6d36d3e22f25@suse.cz> <6c25e7d2-81eb-fb59-bd44-839c70cdebcd@suse.cz> <1440d96e-9563-ea58-39e1-1a623db1a03e@suse.cz> <61147c67-56c8-78b5-2776-d25ea4d8ed7e@suse.cz> <7e192a5c-65d3-47d7-5e8a-61bea465c275@suse.cz> From: =?UTF-8?Q?Martin_Li=c5=a1ka?= Message-ID: <4d0c00b8-ec74-57bc-09fe-489c015a57eb@suse.cz> Date: Tue, 30 Jul 2019 13:41:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-07/txt/msg01808.txt.bz2 On 7/30/19 3:09 PM, Marc Glisse wrote: > On Tue, 30 Jul 2019, Martin Liška wrote: > >> On 7/30/19 1:35 PM, Marc Glisse wrote: >>> +          /* Some delete operators have size as 2nd argument.  */ >>> >>> Some delete operators have 3 arguments. From cp/decl.c: >>> >>>             /* operator delete (void *, size_t, align_val_t); */ >>> >> >> Yep, I know. The patch I installed expects at least 2 arguments: >> >> +                 /* Some delete operators have size as 2nd argument.  */ >> +                 if (is_delete_operator && gimple_call_num_args (stmt) >= 2) > > True, I guess I am a bit confused why the second argument (which could be either size or alignment) needs special handling (mark_operand_necessary) while the third one does not (it is usually a constant). Ah, that's bad, both of them need a care: diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index bec13cd5930..80d5f5c30f7 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -824,13 +824,16 @@ propagate_necessity (bool aggressive) || DECL_FUNCTION_CODE (def_callee) == BUILT_IN_CALLOC)) || DECL_IS_REPLACEABLE_OPERATOR_NEW_P (def_callee))) { - /* Some delete operators have size as 2nd argument. */ + /* Delete operators can have alignment and (or) size as next + arguments. When being a SSA_NAME, they must be marked + as necessary. */ if (is_delete_operator && gimple_call_num_args (stmt) >= 2) - { - tree size_argument = gimple_call_arg (stmt, 1); - if (TREE_CODE (size_argument) == SSA_NAME) - mark_operand_necessary (size_argument); - } + for (unsigned i = 1; i < gimple_call_num_args (stmt); i++) + { + tree arg = gimple_call_arg (stmt, i); + if (TREE_CODE (arg) == SSA_NAME) + mark_operand_necessary (arg); + } continue; } > > I tried to experiment to understand, but it is complicated because including disables the optimization: > > #include > void fn1() { >     char*p=new char; >     delete p; > } > > This ICEs with -O -std=c++17: > > int a = 64; > std::align_val_t b{64}; > void fn1() { >   void *s = operator new(a,b); >   operator delete(s,8+*(unsigned long*)s,b); > } > > I can't see it on current master. Can you? Martin