From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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) From: Richard Biener 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 Content-Type: text/plain; charset=US-ASCII 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-List-Received-Date: Thu, 04 Aug 2022 10:50:00 -0000 Message-ID: <20220804104956.iDh22dH4yjlylOI9wzBrh8r-V0fstHU6proe5eLEiLk@z> 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; +} -- 2.35.3