From patchwork Thu Aug 3 09:09:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 130440 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9f41:0:b0:3e4:2afc:c1 with SMTP id v1csp1013172vqx; Thu, 3 Aug 2023 02:10:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlFQCrc0c8iq3QKEVv69SxHo5qJBugSqdWOowtLiGuz/9/e4AGHrHMS2SUm5E9E99xtaDHvV X-Received: by 2002:a17:906:20de:b0:99b:d698:152e with SMTP id c30-20020a17090620de00b0099bd698152emr7616137ejc.42.1691053843376; Thu, 03 Aug 2023 02:10:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691053843; cv=none; d=google.com; s=arc-20160816; b=pxNz2lEd53Fx3aHVN/KMFNXAlae4Q7ows3ZANGU8w9PMmBhky6Syjcmfzz6oCF8JRv 76BvxGDi1mkPs3gVIhcpLpkBaupyDbZFMa+BO7JN3CQGoPhu8V+qeny5YHVkA8NjFLFa Ip6aoiRUXBPa15v+DPr0P6ycFw1KGiP5CaaRKgZ0B9RtyV4IaHED/bCWKz0mi2/fE2II m0wKdNpSf/YZ06GSm83u+Rj9BBGChljwxx8OLRfG0cF7sZuNcwsZPejCkIyY8d1Ipipr LeHez/pMmE3Lw/0srFC6Aq04IylRqSaWng/n2Z6NW2eYSfzXQpBqMYHjYCqZNUEgsa3M rRkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:cc:to:date:dmarc-filter :delivered-to:dkim-signature:dkim-filter; bh=6ybM705aBFsG87b3Sul5VN/txLkgJIjERAOHo/Uj2iQ=; fh=Q7VQrkpiznztM67wgOvKwv1UVHHTooRCLgPSeptf8cg=; b=cDsMeUOSEF9yNy3lDevPdYILbV32V03LEDx8Fdc19ZzukkfJJCDp8ef0fuYd+gIv1H vy0GXr4wjnvS2Ear9tTlLPUqi+cibIcd0o1odSMxzik12qjBs3ZQ519N85SmmMqW+3Zf L3uVyKSsshM7p8vEbnK76p+5N8wCCLtfM3sF1mDKt6b3tmSJI3Pxmcs+vKC6wQmSzX21 WD8s4NP0XXx9EpTXmv3qJySidgjLW7YCcV+LXZhkdTwLU4Oq516edNvE9a6WwVREqFfD LW8+1apk96WrkeLCe0n65abzkzvBLWofSQJEBzEuCdz7D63Ikvv5dBqxoIiymw6H7Wbs JOtw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FIe57m39; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id p2-20020a1709061b4200b009935121ecd6si8798962ejg.644.2023.08.03.02.10.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 02:10:43 -0700 (PDT) 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=FIe57m39; 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 BE3EE3857C51 for ; Thu, 3 Aug 2023 09:10:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE3EE3857C51 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691053841; bh=6ybM705aBFsG87b3Sul5VN/txLkgJIjERAOHo/Uj2iQ=; h=Date:To:cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=FIe57m39iLiQVekNXhHCLOuUubSr9zoNqgo/WT3buituBNCVPV9rWQlj58w2DNX6o 0jOtSzSeCKMZO/82jdz0CDej9bCZhG0xQiANfiezDuBli+l0gnKr7Utxdo8XOPYBZT S45V16GEP/VToL4lAUJF3dCEKuK5vyYZvfLFmbv0= 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 603FE385840A for ; Thu, 3 Aug 2023 09:09:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 603FE385840A Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 8602E218DF; Thu, 3 Aug 2023 09:09:46 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (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 718D52C142; Thu, 3 Aug 2023 09:09:46 +0000 (UTC) Date: Thu, 3 Aug 2023 09:09:46 +0000 (UTC) To: gcc-patches@gcc.gnu.org cc: Jan Hubicka Subject: [PATCH] Swap loop splitting and final value replacement User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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" Message-Id: <20230803091041.BE3EE3857C51@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773198474641336703 X-GMAIL-MSGID: 1773198474641336703 The following swaps the loop splitting pass and the final value replacement pass to avoid keeping the IV of the earlier loop live when not necessary. The existing gcc.target/i386/pr87007-5.c testcase shows that we otherwise fail to elide an empty loop later. I don't see any good reason why loop splitting would need final value replacement, all exit values honor the constraints we place on loop header PHIs automatically. Bootstrap and regtest running on x86_64-unknown-linux-gnu, I plan to install this if testing succeeds. Richard. * passes.def: Exchange loop splitting and final value replacement passes. * gcc.target/i386/pr87007-5.c: Make sure we split the loop and eliminate both in the end. --- gcc/passes.def | 2 +- gcc/testsuite/gcc.target/i386/pr87007-5.c | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/gcc/passes.def b/gcc/passes.def index f2893ae8a8b..ef5a21afe49 100644 --- a/gcc/passes.def +++ b/gcc/passes.def @@ -282,8 +282,8 @@ along with GCC; see the file COPYING3. If not see form if possible. */ NEXT_PASS (pass_tree_loop_init); NEXT_PASS (pass_tree_unswitch); - NEXT_PASS (pass_scev_cprop); NEXT_PASS (pass_loop_split); + NEXT_PASS (pass_scev_cprop); NEXT_PASS (pass_loop_versioning); NEXT_PASS (pass_loop_jam); /* All unswitching, final value replacement and splitting can expose diff --git a/gcc/testsuite/gcc.target/i386/pr87007-5.c b/gcc/testsuite/gcc.target/i386/pr87007-5.c index b36e81c270c..a6cdf11522e 100644 --- a/gcc/testsuite/gcc.target/i386/pr87007-5.c +++ b/gcc/testsuite/gcc.target/i386/pr87007-5.c @@ -1,5 +1,5 @@ /* { dg-do compile } */ -/* { dg-options "-Ofast -march=skylake-avx512 -mfpmath=sse -fno-tree-vectorize" } */ +/* { dg-options "-Ofast -march=skylake-avx512 -mfpmath=sse -fno-tree-vectorize -fdump-tree-cddce3-details -fdump-tree-lsplit-optimized" } */ /* Load of d2/d3 is hoisted out, vrndscalesd will reuse loades register to avoid partial dependence. */ #include @@ -15,4 +15,6 @@ foo (int n, int k) d1 = sqrt (d3); } +/* { dg-final { scan-tree-dump "optimized: loop split" "lsplit" } } */ +/* { dg-final { scan-tree-dump-times "removing loop" 2 "cddce3" } } */ /* { dg-final { scan-assembler-times "vxorps\[^\n\r\]*xmm\[0-9\]" 0 } } */