From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by sourceware.org (Postfix) with ESMTPS id 80EC63858C66 for ; Tue, 14 Feb 2023 11:49:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 80EC63858C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de 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-out2.suse.de (Postfix) with ESMTPS id 4D9961FDE6 for ; Tue, 14 Feb 2023 11:49:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1676375358; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=QESXW59EYWXjVyNkoeqg15UBNLGuH0KiopopFrTTEQ0=; b=nvOXBGijZfMhdtZALwiPn/8H7uuEdkIwgOisXbwY+fqukbhR9h/O1CaGeq2kR+ZdiEzesq iYjHF3GC4mVkbtLnIlUm9QNSiNTayhYF5UZIt2HbDGs82lStQb8knLjPa7XX/sdceBQm8D 52vnMM3396jYSOpsdjVVllUvTY0dh7w= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1676375358; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=QESXW59EYWXjVyNkoeqg15UBNLGuH0KiopopFrTTEQ0=; b=1NTSL5inNgAEYHMEhbzkvYE4YhJGecnHfRMBToASGpULjnFo8V3q+3qBDXzfoukVvFyr6v qZMwMrTkLVIQLsBQ== 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 3E86413A21 for ; Tue, 14 Feb 2023 11:49:18 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id vcJnDj5162NjBwAAMHmgww (envelope-from ) for ; Tue, 14 Feb 2023 11:49:18 +0000 Date: Tue, 14 Feb 2023 12:49:17 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/108782 - nested first order recurrence vectorization MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20230214114918.3E86413A21@imap2.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 List-Id: First order recurrence vectorization isn't possible for nested loops. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/108782 * tree-vect-loop.cc (vect_phi_first_order_recurrence_p): Make sure we're not vectorizing an inner loop. * gcc.dg/torture/pr108782.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr108782.c | 21 +++++++++++++++++++++ gcc/tree-vect-loop.cc | 4 ++++ 2 files changed, 25 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/torture/pr108782.c diff --git a/gcc/testsuite/gcc.dg/torture/pr108782.c b/gcc/testsuite/gcc.dg/torture/pr108782.c new file mode 100644 index 00000000000..1eac93db574 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr108782.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fno-tree-copy-prop" } */ + +int m; + +__attribute__ ((simd)) int +foo (void) +{ + unsigned a; + int b = 0; + + m = a = 1; + while (a != 0) + { + b = m; + m = 2; + ++a; + } + + return b; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index becf96bb2b8..8387f7690b2 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -538,6 +538,10 @@ static bool vect_phi_first_order_recurrence_p (loop_vec_info loop_vinfo, class loop *loop, gphi *phi) { + /* A nested cycle isn't vectorizable as first order recurrence. */ + if (LOOP_VINFO_LOOP (loop_vinfo) != loop) + return false; + /* Ensure the loop latch definition is from within the loop. */ edge latch = loop_latch_edge (loop); tree ldef = PHI_ARG_DEF_FROM_EDGE (phi, latch); -- 2.35.3