From patchwork Thu Aug 4 10:49:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 381 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:b5d6:b0:2b9:3548:2db5 with SMTP id v22csp292810pxt; Thu, 4 Aug 2022 03:50:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR6/V0qnqiFjIwTIhjKcq+5LN9iFf7RxXcL2/wW5WXiRszj1eI4p+BTx66eswuBjYHNXnE1K X-Received: by 2002:a05:6402:4143:b0:43b:206d:c283 with SMTP id x3-20020a056402414300b0043b206dc283mr1368669eda.381.1659610243136; Thu, 04 Aug 2022 03:50:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659610243; cv=none; d=google.com; s=arc-20160816; b=QoCefuQaXWZDC8/39iqXLFHpU7Vdg1oiNKfUHEREeIDp5mtymRnR8JIpIbO9iUFuFh JzWGdfzGAxYc+PqBMb2vm2MniZUKTXiE4iH+QErz5Ef/p+sKfsngl7Mz7KaPKrteZ20U QFU6/O6Con4VFpwpawlZy8dJW4Dj3nFbuPZzQ4N29jFBp4ZlcLoV9pP5XUXlOEVmC7OC QIaWldp4URzDd6ahx7sZzQVDLqZG81aVmm9L+kMrd4L+5YdZe5Qo7ut6sk7Twg7bUvzp /2cFC84OogNsrr1KSBFIzn9QVmccDibe7uTMat8kMfNbVzaATlkFW9t0RuRDWkI7lmcJ mXhw== 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:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=r1EsX4SXlPEzcEPD5G926+L/ob3YOcfshbCSVKCYSmw=; b=p5XgNiNwp52g32JrrYrQCbVXDhClZObl4Qb9RdBDcsNTbmPjArTDygy9GZLqSofBEn 3n9txHeZUj3EU14GABV0RvTRZx/vthhtBHccrAnuZvG6mf4gS6olyqE/GEDy4VT13xjx CatFRIuMmXpQGeQ68n0tbBNH5YyqyNpkuZeS96gimBJIiYwBGLEGRFAR6v4b/c2Lilm8 7MgWcmq6bDO0Ki3yAGtSxxRCZyrdF3sWgyUiSz3DRa2ZJFtDjDmM77NXE+9n6N3Jmn8Z /mhXrFup/TLcwgDsOkSk81D9DUntR2y7tnjPVGUm/3H+9aBqJ4jY2xtNDTvqyXu/Yjjz pH0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=O9Ucn2wg; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g8-20020a1709065d0800b0072b53b3f4c5si629776ejt.217.2022.08.04.03.50.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 03:50: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=O9Ucn2wg; 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 A21A63857363 for ; Thu, 4 Aug 2022 10:50:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A21A63857363 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1659610241; bh=r1EsX4SXlPEzcEPD5G926+L/ob3YOcfshbCSVKCYSmw=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=O9Ucn2wg1rHmtoWRbasfOAY9n1ccupz4gnLEWrAKunaiHSY7W8zeoVGTsSf1ZdPkv jFSnk/UL7pmFZsGnn32zF3Zcjk8xp5ontHjRQ6bv8cUAmkd4Djr5QlckJYRXWdVbRs HCnjACoTXzbVj4MBpZ3adKHlB6ZXYxHIJ6JvWftE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id BF34C38582AE for ; Thu, 4 Aug 2022 10:49:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BF34C38582AE Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 0DAD020EC0 for ; Thu, 4 Aug 2022 10:49:57 +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 083582C141 for ; Thu, 4 Aug 2022 10:49:57 +0000 (UTC) Date: Thu, 4 Aug 2022 10:49:56 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/106521 - unroll-and-jam LC SSA rewrite 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, MISSING_MID, 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" Message-Id: <20220804105041.A21A63857363@sourceware.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1740227470687423420?= X-GMAIL-MSGID: =?utf-8?q?1740227470687423420?= The LC SSA rewrite performs SSA verification at start but the VN run performed on the unrolled-and-jammed body can leave us with invalid SSA form until CFG cleanup is run. So make sure we do that before rewriting into LC SSA. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. PR tree-optimization/106521 * gimple-loop-jam.cc (tree_loop_unroll_and_jam): Perform CFG cleanup manually before rewriting into LC SSA. * gcc.dg/torture/pr106521.c: New testcase. --- gcc/gimple-loop-jam.cc | 8 ++++++++ gcc/testsuite/gcc.dg/torture/pr106521.c | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr106521.c diff --git a/gcc/gimple-loop-jam.cc b/gcc/gimple-loop-jam.cc index 8cde6c7c5ce..41ba4e42819 100644 --- a/gcc/gimple-loop-jam.cc +++ b/gcc/gimple-loop-jam.cc @@ -39,6 +39,7 @@ along with GCC; see the file COPYING3. If not see #include "tree-ssa-loop-ivopts.h" #include "tree-vectorizer.h" #include "tree-ssa-sccvn.h" +#include "tree-cfgcleanup.h" /* Unroll and Jam transformation @@ -609,6 +610,13 @@ tree_loop_unroll_and_jam (void) if (todo) { + /* We need to cleanup the CFG first since otherwise SSA form can + be not up-to-date from the VN run. */ + if (todo & TODO_cleanup_cfg) + { + cleanup_tree_cfg (); + todo &= ~TODO_cleanup_cfg; + } rewrite_into_loop_closed_ssa (NULL, 0); scev_reset (); free_dominance_info (CDI_DOMINATORS); diff --git a/gcc/testsuite/gcc.dg/torture/pr106521.c b/gcc/testsuite/gcc.dg/torture/pr106521.c new file mode 100644 index 00000000000..05c8ce54d0b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr106521.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-floop-unroll-and-jam --param unroll-jam-min-percent=0" } */ + +short a, b, e; +volatile long c; +long d; +int main() { + for (; d; d++) { + long g = a = 1; + for (; a; a++) { + g++; + c; + } + g && (b = e); + } + return 0; +}