From patchwork Mon Sep 30 14:19:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1991053 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=NTqYLJkV; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=de1xHPC8; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=La+TBnFQ; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=nitTzjq1; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XHNW93lwhz1xtY for ; Tue, 1 Oct 2024 00:19:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9B3673850208 for ; Mon, 30 Sep 2024 14:19:47 +0000 (GMT) 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:2a07:de40:b251:101:10:150:64:2]) by sourceware.org (Postfix) with ESMTPS id D8162385EC20 for ; Mon, 30 Sep 2024 14:19:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D8162385EC20 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org D8162385EC20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a07:de40:b251:101:10:150:64:2 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727705970; cv=none; b=gwIGFMC77sDg+FvxqpbQW/3TAft70fyh857J/pAl9Vgd+uWVwznIPm+9LiHK14U4cQ4zjAZmaonryL7jBLHbGtuWhdwHFNXkqk2avUwVnqCUByJY1IFB2NTOafEXxn3NuNLnvQ6tULeq5ROY8Z9Q+Vgof+NxGB+6D0OrZ9LI77A= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727705970; c=relaxed/simple; bh=DIG2PSohh7CFdP0WvVr8gcEpigI2gir0g4qTT9eI0l8=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=XW01KyOAhmfI806gVcmdFtquEBs7nO0TF9pPnnhsx2lnTR6NmSJgBMLfdjWsEpbbqpMlEOHp80JJ6wL1SJr/nXN3XFylxY1VEb10hsskD1NZ5GLJsr9ZFFBELvXE9xxxO74MXyt63fK+clzaJRtlYIfHbUTl1dw3MC/G0bj0Td4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E17101FBAC for ; Mon, 30 Sep 2024 14:19:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1727705964; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=CuJsyXsRe1daYfeNA0iXISgZi6c+lE1B4nS0NZOrtu0=; b=NTqYLJkVbEvYGSXwumo0nN8/t+s6nEBLfAYw4XcRZ/O/qa5GQLPEIkPYsYwvC0J3gJZCeO jVz8vnatuAEvQXOmdThhv79Q1RAWbypS8QhreBTfmjQWt0wtCRNoYnGDaeuK/7kB24U7D0 6rmr4xFls6FgGr46nvB58uqZfs0Zz54= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1727705964; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=CuJsyXsRe1daYfeNA0iXISgZi6c+lE1B4nS0NZOrtu0=; b=de1xHPC8905DUH6UDJcSm+2jettj3WBK61QH4m688IdLgqiL81fjF5ZAq85GMfXhyiAMH9 YJrp0K3KVfg4IsDA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1727705963; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=CuJsyXsRe1daYfeNA0iXISgZi6c+lE1B4nS0NZOrtu0=; b=La+TBnFQO6aDePMEfBIY1kmBQUVAFAq0hdYnwfL0wrhF15m4wKJJKTKlpjdv9ujOFQ+AzY Es8+5Gxsb3ZRQAwoLrOsB/hQjXHR/jAgvKyGVb55FrfjQnKYKCvbKUY+z2F6suQ4tscfKX Np6jki8/hrF3QblqAel6V1J7xzlgjyg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1727705963; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=CuJsyXsRe1daYfeNA0iXISgZi6c+lE1B4nS0NZOrtu0=; b=nitTzjq1bC3YLijgKnRMsoGRn5dcN3HQLBeNrEkOD3mqh7IpzECNlxHvRA2II9UPQJenNG +YZ6pACqKzSrvpAg== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C7DEE13A8B for ; Mon, 30 Sep 2024 14:19:23 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id QwATL2uz+mbHDgAAD6G6ig (envelope-from ) for ; Mon, 30 Sep 2024 14:19:23 +0000 Date: Mon, 30 Sep 2024 16:19:23 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/116879 - failure to recognize non-empty latch MIME-Version: 1.0 Message-Id: <20240930141923.C7DEE13A8B@imap1.dmz-prg2.suse.org> X-Spam-Level: X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MIME_TRACE(0.00)[0:+]; MISSING_XM_UA(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, imap1.dmz-prg2.suse.org:mid] X-Spam-Score: -4.30 X-Spam-Status: No, score=-11.7 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org When we relaxed the vectorizers constraint on loop structure verifying the emptiness of the latch became too lose as can be seen in the case for PR116879 where the latch effectively contains two basic-blocks which one being an unmerged forwarder that's not empty. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/116879 * tree-vect-loop.cc (vect_analyze_loop_form): Scan all blocks that form the latch. * gcc.dg/pr116879.c: New testcase. --- gcc/testsuite/gcc.dg/pr116879.c | 15 +++++++++++++++ gcc/tree-vect-loop.cc | 15 +++++++++++---- 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr116879.c diff --git a/gcc/testsuite/gcc.dg/pr116879.c b/gcc/testsuite/gcc.dg/pr116879.c new file mode 100644 index 00000000000..73ddb2b658c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr116879.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -fallow-store-data-races -fno-tree-ch -ftree-loop-distribution" } */ + +static int b; +int *a, c, *d = &c; +int main() { + int e = 0; + for (; e < 8; e = (char)(e + 1)) { + int *f = &b, g[8], h = 0; + for (; h < 8; h++) + g[h] = 0; + --*f != (*d = g[0] || a); + } + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 5cd4bdb32e0..0ce1bf8ebba 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -1851,10 +1851,17 @@ vect_analyze_loop_form (class loop *loop, vect_loop_form_info *info) " too many incoming edges.\n"); /* We assume that the latch is empty. */ - if (!empty_block_p (loop->latch) - || !gimple_seq_empty_p (phi_nodes (loop->latch))) - return opt_result::failure_at (vect_location, - "not vectorized: latch block not empty.\n"); + basic_block latch = loop->latch; + do + { + if (!empty_block_p (latch) + || !gimple_seq_empty_p (phi_nodes (latch))) + return opt_result::failure_at (vect_location, + "not vectorized: latch block not " + "empty.\n"); + latch = single_pred (latch); + } + while (single_succ_p (latch)); /* Make sure there is no abnormal exit. */ auto_vec exits = get_loop_exit_edges (loop);