From patchwork Tue Nov 30 14:09:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 48285 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1A50F385AC36 for ; Tue, 30 Nov 2021 14:10:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A50F385AC36 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1638281444; bh=04KrYqPZirQHb3Z6S1+Kcu7mfRcGHHEspiww6NG3wlA=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=HQUNdqc+z1r3ZOigH3MsnHnXLgj15q7gufXLYGHu6aJWwsaDkvT2qxdi4SuZ0wlRW dPWxJnQGTSAPdQl3vSnMhd9SY+kZLySziD3drTtIV4/RYe3OiPs7EqWZEHkpa1UkQX IMxf9q464WheWwJ+/a57BINs946W8t21TIwpT3cE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 17FB6385AC3B for ; Tue, 30 Nov 2021 14:10:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 17FB6385AC3B Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-416-QHgFJ1MCNheuVGCJXiIPog-1; Tue, 30 Nov 2021 09:10:13 -0500 X-MC-Unique: QHgFJ1MCNheuVGCJXiIPog-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9DB5C100CC98; Tue, 30 Nov 2021 14:09:49 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.194.188]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 205E019D9F; Tue, 30 Nov 2021 14:09:48 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 1AUE9jWl2949703 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 30 Nov 2021 15:09:46 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 1AUE9iGH2949702; Tue, 30 Nov 2021 15:09:44 +0100 Date: Tue, 30 Nov 2021 15:09:44 +0100 To: Richard Biener Subject: [PATCH] simplify-rtx, v2: Punt on simplify_associative_operation with large operands [PR102356] Message-ID: <20211130140944.GN2646553@tucnak> References: <20211130092613.GL2646553@tucnak> <5np825s9-9595-qn54-rqnq-682rp694081@fhfr.qr> MIME-Version: 1.0 In-Reply-To: <5np825s9-9595-qn54-rqnq-682rp694081@fhfr.qr> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: richard.sandiford@arm.com, gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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). 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. Jakub --- 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++); + } +}