From patchwork Mon Jan 10 10:08:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 49793 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 1A2C23892440 for ; Mon, 10 Jan 2022 10:10:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1A2C23892440 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1641809427; bh=hxVrR467y93WbAgDRtw1FdjiUQ8PRV7VskgoCCG9l1I=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gLMP+OYs5r5EcGrUSriCiSVmJuFy1U7SFaHPOtEt6KQc9/odC0EF04GR5VGrBTg+N t10T74RSQpITyrt+ofyrZfR0vk5Q8QLtdDrc+MnfveJ8+C/3wojT1ujFWW9C1yOt7M x3FTpbyhOZSGITn8YvtU2tHN100ht0IeTKhpKjZI= 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 4D7133892443 for ; Mon, 10 Jan 2022 10:08:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4D7133892443 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 156E021108 for ; Mon, 10 Jan 2022 10:08:37 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (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 imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 02CDD13CCB for ; Mon, 10 Jan 2022 10:08:36 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id LegGO6QF3GHZRAAAMHmgww (envelope-from ) for ; Mon, 10 Jan 2022 10:08:36 +0000 Date: Mon, 10 Jan 2022 11:08:36 +0100 (CET) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/100359 - restore unroll at -O3 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_PASS, 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: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This fixes a mistake done with r8-5008 when introducing allow_peel to the unroll code. The intent was to allow peeling that doesn't grow code but the result was that with -O3 and UL_ALL this wasn't done. The following instantiates the desired effect by adjusting ul to UL_NO_GROWTH if peeling is not allowed. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2022-01-05 Richard Biener PR tree-optimization/100359 * tree-ssa-loop-ivcanon.c (try_unroll_loop_completely): Allow non-growing peeling with !allow_peel and UL_ALL. * gcc.dg/tree-ssa/pr100359.c: New testcase. --- gcc/testsuite/gcc.dg/tree-ssa/pr100359.c | 31 ++++++++++++++++++++++++ gcc/tree-ssa-loop-ivcanon.c | 6 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr100359.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr100359.c b/gcc/testsuite/gcc.dg/tree-ssa/pr100359.c new file mode 100644 index 00000000000..29243522caa --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr100359.c @@ -0,0 +1,31 @@ +/* { dg-do link } */ +/* { dg-options "-O3 -fdump-tree-cunrolli-optimized" } */ + +extern void foo(void); +static int b, f, *a = &b; +int **c = &a; +static void d() { + int g, h; + for (f = 0; f < 1; f++) { + int *i = &b; + { + int *j[3], **k = &a; + for (g = 0; g < 3; g++) + for (h = 0; h < 1; h++) + j[g] = &b; + *k = j[0]; + } + *c = i; + } +} +int main() { + d(); + *a = 0; + if (**c) + foo(); + return 0; +} + +/* Verify that we unroll the inner loop early even with -O3. */ +/* { dg-final { scan-tree-dump "loop with 1 iterations completely unrolled" "cunrolli" } } */ +/* { dg-final { scan-tree-dump "loop with 3 iterations completely unrolled" "cunrolli" } } */ diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c index 4f1e3537f05..e2ac2044741 100644 --- a/gcc/tree-ssa-loop-ivcanon.c +++ b/gcc/tree-ssa-loop-ivcanon.c @@ -720,7 +720,7 @@ try_unroll_loop_completely (class loop *loop, exit = NULL; /* See if we can improve our estimate by using recorded loop bounds. */ - if ((allow_peel || maxiter == 0 || ul == UL_NO_GROWTH) + if ((maxiter == 0 || ul != UL_SINGLE_ITER) && maxiter >= 0 && (!n_unroll_found || (unsigned HOST_WIDE_INT)maxiter < n_unroll)) { @@ -729,6 +729,10 @@ try_unroll_loop_completely (class loop *loop, /* Loop terminates before the IV variable test, so we cannot remove it in the last iteration. */ edge_to_cancel = NULL; + /* If we do not allow peeling and we iterate just allow cases + that do not grow code. */ + if (!allow_peel && maxiter != 0) + ul = UL_NO_GROWTH; } if (!n_unroll_found)