From patchwork Fri Dec 2 07:04:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 28725 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp687652wrr; Thu, 1 Dec 2022 23:05:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf5mOQqfbopO4ZSsrHGL4ALvIwmImWTr+Kgh5Hvikec4WmbissoOYPWaxkhKEsH/Il90Z9DV X-Received: by 2002:a17:906:52c8:b0:7ad:ba1e:1bac with SMTP id w8-20020a17090652c800b007adba1e1bacmr59250476ejn.528.1669964712297; Thu, 01 Dec 2022 23:05:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669964712; cv=none; d=google.com; s=arc-20160816; b=aJs8rgUdHcVxlvskaL09yuR6bQ5OE3+mKJgTOqz0Yt8wTgFMtq9rm2c4u3YsDIXV4s br6dlaTKr5SGvWUM9yzJVWbM3usb18lqjt6yaFk90K1LIwkMlxw6uMZvi/RncS8qINVF xHPjVYBcVIJ9f3N879E5PlmAITVmKoQkbr0rVfL4c9TvUJ9BkR2/z9qhno6eSHjIUmKT qh7tu43J6l8ZCdG/C15zxCQhJzN7w5W1vcXRr/SUq/UhnmbnwNO8QbHnVmS/SHAkUJYs nFzVr2hJtU3Uk//ggTFYgqXYpHObeanjW+sjLiV/NDChbTkAvjc4ilchyzXPNDeAZ+08 DHQw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=iYTi0tvAS3iZ6Wr/nzR3rZoQgxrl4WSY9z6MUNbftsE=; b=CKOOD1zapSnNuK4lUDUWVYlKQkPMUMmkQYyLn2zS1tuPCvbld/lr95HR219OQh+8Zp s9YDpt77+SJKT6u7lNNtAmhBbEDpAXRmXj8OEaLM3CNRcisWvdqWDK7JBcwsc0R9XX9G HKC0nCGhWAjCgwclSjKlN/2E1CiKpoeZ9qYOlMi2F0OSIKU+kYI67hYz677ToURPYVbE ltyq8iaE7/QIGJDNseQb1xKoNL9oj/69FSC2r2Hycpp4Kmb7/KPjIxjF5xNkjr2p3pkj GX9oXfPg++QUiW52pl4PkDtMlpIzKom/ranOnjBGep7gjkFeVKwLlMZPX12t/s8nFYuf lc6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gsrLafhB; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id m17-20020a056402511100b0046b9c536fa7si5714325edd.286.2022.12.01.23.05.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Dec 2022 23:05:12 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gsrLafhB; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id ED53B385B539 for ; Fri, 2 Dec 2022 07:04:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org ED53B385B539 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669964686; bh=iYTi0tvAS3iZ6Wr/nzR3rZoQgxrl4WSY9z6MUNbftsE=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gsrLafhBqrigSBlYp3CWd4sKxxEOrNrlGQH11TilIrgBQKLwzDUrNLtV85MILDPGs f69wXBuw+7Nq1MwzUnAwbUw9dhOjIAb3GYXy1cd6gz7Yx8FP31B8428y39snzv38wo W/VMnkBqBZ8+MpsFJmhQewVIiFVjs3jTiKAwSCSc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 410783858D3C for ; Fri, 2 Dec 2022 07:04:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 410783858D3C Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B3E8C21AB4 for ; Fri, 2 Dec 2022 07:04:01 +0000 (UTC) Received: from imap1.suse-dmz.suse.de (imap1.suse-dmz.suse.de [192.168.254.73]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap1.suse-dmz.suse.de (Postfix) with ESMTPS id A01F6133DE for ; Fri, 2 Dec 2022 07:04:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap1.suse-dmz.suse.de with ESMTPSA id yix+JWGjiWOaewAAGKfGzw (envelope-from ) for ; Fri, 02 Dec 2022 07:04:01 +0000 Date: Fri, 2 Dec 2022 08:04:01 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Add --param max-unswitch-depth MIME-Version: 1.0 Message-Id: <20221202070401.A01F6133DE@imap1.suse-dmz.suse.de> X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751084917823834510?= X-GMAIL-MSGID: =?utf-8?q?1751084917823834510?= The following adds a --param to limit the depth of unswitched loop nests. One can use --param max-unswitch-depth=1 to disable unswitching of outer loops (the innermost loop will then be unswitched). Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/107946 * params.opt (-param=max-unswitch-depth=): New. * doc/invoke.texi (--param=max-unswitch-depth): Document. * tree-ssa-loop-unswitch.cc (init_loop_unswitch_info): Honor --param=max-unswitch-depth --- gcc/doc/invoke.texi | 3 +++ gcc/params.opt | 4 ++++ gcc/tree-ssa-loop-unswitch.cc | 4 +++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index 56e5e875e86..277ac35ad16 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -14963,6 +14963,9 @@ The maximum depth of a loop nest suitable for complete peeling. @item max-unswitch-insns The maximum number of insns of an unswitched loop. +@item max-unswitch-depth +The maximum depth of a loop nest to be unswitched. + @item lim-expensive The minimum cost of an expensive expression in the loop invariant motion. diff --git a/gcc/params.opt b/gcc/params.opt index c1dcb7ea487..397ec0bd128 100644 --- a/gcc/params.opt +++ b/gcc/params.opt @@ -726,6 +726,10 @@ The maximum number of instructions to consider to unroll in a loop. Common Joined UInteger Var(param_max_unswitch_insns) Init(50) Param Optimization The maximum number of insns of an unswitched loop. +-param=max-unswitch-depth= +Common Joined UInteger Var(param_max_unswitch_depth) Init(50) IntegerRange(1, 50) Param Optimization +The maximum depth of a loop nest to be unswitched. + -param=max-variable-expansions-in-unroller= Common Joined UInteger Var(param_max_variable_expansions) Init(1) Param Optimization If -fvariable-expansion-in-unroller is used, the maximum number of times that an individual variable will be expanded during loop unrolling. diff --git a/gcc/tree-ssa-loop-unswitch.cc b/gcc/tree-ssa-loop-unswitch.cc index e8c9bd6812a..df7a2019b1c 100644 --- a/gcc/tree-ssa-loop-unswitch.cc +++ b/gcc/tree-ssa-loop-unswitch.cc @@ -263,8 +263,10 @@ init_loop_unswitch_info (class loop *&loop, unswitch_predicate *&hottest, /* Unswitch only nests with no sibling loops. */ class loop *outer_loop = loop; + unsigned max_depth = param_max_unswitch_depth; while (loop_outer (outer_loop)->num != 0 - && !loop_outer (outer_loop)->inner->next) + && !loop_outer (outer_loop)->inner->next + && --max_depth != 0) outer_loop = loop_outer (outer_loop); hottest = NULL; hottest_bb = NULL;