From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 7FC5C385AC2C for ; Tue, 30 Nov 2021 14:13:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7FC5C385AC2C Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 52BE22177B; Tue, 30 Nov 2021 14:13:19 +0000 (UTC) Received: from murzim.suse.de (murzim.suse.de [10.160.4.192]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 46B1DA3B81; Tue, 30 Nov 2021 14:13:19 +0000 (UTC) Date: Tue, 30 Nov 2021 15:13:19 +0100 (CET) From: Richard Biener To: Jakub Jelinek cc: gcc-patches@gcc.gnu.org, richard.sandiford@arm.com Subject: Re: [PATCH] simplify-rtx, v2: Punt on simplify_associative_operation with large operands [PR102356] In-Reply-To: <20211130140944.GN2646553@tucnak> Message-ID: References: <20211130092613.GL2646553@tucnak> <5np825s9-9595-qn54-rqnq-682rp694081@fhfr.qr> <20211130140944.GN2646553@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Nov 2021 14:13:22 -0000 On Tue, 30 Nov 2021, Jakub Jelinek wrote: > On Tue, Nov 30, 2021 at 10:43:28AM +0100, Richard Biener wrote: > > I wonder given we now have 'simplify_context' whether we can > > track a re-association budget we can eat from. At least your > > code to determine whether the expression is too large is > > quadratic as well (but bound to 64, so just a very large constant > > overhead for an outermost expression of size 63). We already > > have a mem_depth there, > > Makes sense. > > > so just have reassoc_times and punt > > if that reaches --param max-simplify-reassoc-times, incrementing > > it each time simplify_associative_operation is entered? > > Though, is a --param worth for it? There is IMO no way the 64 limit > can trigger for non-debug insns (I can certainly gather how many times > it triggers when > 20 and in which pass during bootstrap/regtest > to verify). Probably not - but maybe use a (static) const unsigned int max_assoc_count in the class then? OK either way I guess. Thanks, Richard. > 2021-11-30 Jakub Jelinek > > PR rtl-optimization/102356 > * rtl.h (simplify_context): Add assoc_count member. > * simplify-rtx.c (simplify_associative_operation): Don't reassociate > more than 64 times within one outermost simplify_* call. > * dwarf2out.c (mem_loc_descriptor): Optimize binary operation > with both operands the same using DW_OP_dup. > > * gcc.dg/pr102356.c: New test. > > --- gcc/rtl.h.jj 2021-11-02 09:06:05.904396581 +0100 > +++ gcc/rtl.h 2021-11-30 14:55:39.701257736 +0100 > @@ -3433,6 +3433,10 @@ public: > inside a MEM than outside. */ > unsigned int mem_depth = 0; > > + /* Tracks number of simplify_associative_operation calls performed during > + outermost simplify* call. */ > + unsigned int assoc_count = 0; > + > private: > rtx simplify_truncation (machine_mode, rtx, machine_mode); > rtx simplify_byte_swapping_operation (rtx_code, machine_mode, rtx, rtx); > --- gcc/simplify-rtx.c.jj 2021-11-30 09:44:46.619606170 +0100 > +++ gcc/simplify-rtx.c 2021-11-30 14:59:00.251321577 +0100 > @@ -2263,6 +2263,16 @@ simplify_context::simplify_associative_o > { > rtx tem; > > + /* Normally expressions simplified by simplify-rtx.c are combined > + at most from a few machine instructions and therefore the > + expressions should be fairly small. During var-tracking > + we can see arbitrarily large expressions though and reassociating > + those can be quadratic, so punt after encountering 64 > + simplify_associative_operation calls during outermost simplify_* > + call. */ > + if (++assoc_count >= 64) > + return NULL_RTX; > + > /* Linearize the operator to the left. */ > if (GET_CODE (op1) == code) > { > --- gcc/dwarf2out.c.jj 2021-11-30 09:44:46.568606908 +0100 > +++ gcc/dwarf2out.c 2021-11-30 14:53:28.779174490 +0100 > @@ -16363,6 +16363,15 @@ mem_loc_descriptor (rtx rtl, machine_mod > do_binop: > op0 = mem_loc_descriptor (XEXP (rtl, 0), mode, mem_mode, > VAR_INIT_STATUS_INITIALIZED); > + if (XEXP (rtl, 0) == XEXP (rtl, 1)) > + { > + if (op0 == 0) > + break; > + mem_loc_result = op0; > + add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_dup, 0, 0)); > + add_loc_descr (&mem_loc_result, new_loc_descr (op, 0, 0)); > + break; > + } > op1 = mem_loc_descriptor (XEXP (rtl, 1), mode, mem_mode, > VAR_INIT_STATUS_INITIALIZED); > > --- gcc/testsuite/gcc.dg/pr102356.c.jj 2021-11-30 14:53:28.779174490 +0100 > +++ gcc/testsuite/gcc.dg/pr102356.c 2021-11-30 14:53:28.779174490 +0100 > @@ -0,0 +1,33 @@ > +/* PR rtl-optimization/102356 */ > +/* { dg-do compile { target int32plus } } */ > +/* { dg-options "-O3 -g" } */ > + > +signed char a = 0; > +unsigned char b = 9; > +unsigned long long c = 0xF1FBFC17225F7A57ULL; > +int d = 0x3A6667C6; > + > +unsigned char > +foo (unsigned int x) > +{ > + unsigned int *e = &x; > + if ((c /= ((0 * (*e *= b)) <= 0))) > + ; > + for (d = 9; d > 2; d -= 2) > + { > + c = -2; > + do > + if ((*e *= *e)) > + { > + a = 4; > + do > + { > + a -= 3; > + if ((*e *= *e)) > + b = 9; > + } > + while (a > 2); > + } > + while (c++); > + } > +} > > > Jakub > > -- Richard Biener SUSE Software Solutions Germany GmbH, Maxfeldstrasse 5, 90409 Nuernberg, Germany; GF: Ivo Totev; HRB 36809 (AG Nuernberg)