From patchwork Mon Sep 9 10:59:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1982506 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=gg21Y7Ww; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Vf6d89Fi; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=gg21Y7Ww; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Vf6d89Fi; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4X2P410HrYz1y1D for ; Mon, 9 Sep 2024 20:59:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1846B3858432 for ; Mon, 9 Sep 2024 10:59:41 +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 [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id E1EE33858CDB for ; Mon, 9 Sep 2024 10:59:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E1EE33858CDB 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 E1EE33858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725879564; cv=none; b=IXRX5/610pb0t5WZjY4a55WITlFNz0hfNYsLmULgfaKX6yAplms2D2tPq1NHkfdml83613wB7c9ZdT2l+h3nvp8xpEcqsBEBxGuiAU96ALh7QweqBlEFJT7vf2djinNWWMf8Rw3RYClGSXX2/3E7sxzp5Qe2dIiXwIGRkCb91eA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725879564; c=relaxed/simple; bh=7Fo9/YoMhi+exVhW0XUfSXGryRMEgSVk0g/7floDJ10=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=h2PVkQiN7tuwN0sclHKSLDuCSZ3TCidF7G+PJ/EdsxtzIPQMv2oy8/RNVA5vVWAJ/cg7pNTuuwWno7ef8A20XQy1FnN2Aza25Tuz5hpnMXEiQlxyxGENIcV2KA5To94pxYGR+/iCIhW2VpGdeJGz5vEieS4+nyNWOThKR4CK6jk= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from murzim.nue2.suse.org (unknown [10.168.4.243]) (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 5DD1F1F7B2 for ; Mon, 9 Sep 2024 10:59:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725879559; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=IzXmZnM08WAWSQEOp3pmK3jnVFTU8eK7mb0glZUXpjU=; b=gg21Y7Ww1NXOz+bSZsCVYuKsHtOwuVdD9Pjrdy8qgNVwi7qlMR+3StdpAxv7mLProCRojW phcTU2EzmiUVgfPD2IoAA8V+jILu8rmgeh0Uj4LNwvYAkkrLa2oOXmq2As8TW5Ov92FYsH Lh0QP7S2T3TxR050B3RZsinC6nHZIFM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725879559; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=IzXmZnM08WAWSQEOp3pmK3jnVFTU8eK7mb0glZUXpjU=; b=Vf6d89FitjrOp9nBgYSvYXNX/i8HZV8l+l++BrDtTp96NBvvAJoW7fUNnTGU2smyq89ZBK wEVVfXcqe77fz5Dw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1725879559; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=IzXmZnM08WAWSQEOp3pmK3jnVFTU8eK7mb0glZUXpjU=; b=gg21Y7Ww1NXOz+bSZsCVYuKsHtOwuVdD9Pjrdy8qgNVwi7qlMR+3StdpAxv7mLProCRojW phcTU2EzmiUVgfPD2IoAA8V+jILu8rmgeh0Uj4LNwvYAkkrLa2oOXmq2As8TW5Ov92FYsH Lh0QP7S2T3TxR050B3RZsinC6nHZIFM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1725879559; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=IzXmZnM08WAWSQEOp3pmK3jnVFTU8eK7mb0glZUXpjU=; b=Vf6d89FitjrOp9nBgYSvYXNX/i8HZV8l+l++BrDtTp96NBvvAJoW7fUNnTGU2smyq89ZBK wEVVfXcqe77fz5Dw== Date: Mon, 9 Sep 2024 12:59:19 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/116647 - wrong classified double reduction MIME-Version: 1.0 X-Spam-Score: -1.13 X-Spamd-Result: default: False [-1.13 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MISSING_MID(2.50)[]; NEURAL_HAM_LONG(-0.33)[-0.335]; NEURAL_HAM_SHORT(-0.20)[-0.989]; MIME_GOOD(-0.10)[text/plain]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FUZZY_BLOCKED(0.00)[rspamd.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCVD_COUNT_ZERO(0.00)[0]; MISSING_XM_UA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; MIME_TRACE(0.00)[0:+] X-Spam-Level: X-Spam-Status: No, score=-10.5 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.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 Message-Id: <20240909105941.1846B3858432@sourceware.org> The following avoids classifying a double reduction that's not actually a reduction in the outer loop (because its value isn't used outside of the outer loop). This avoids us ICEing on the unexpected stmt/SLP node arrangement. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/116647 * tree-vect-loop.cc (vect_is_simple_reduction): Add missing check to double reduction detection. * gcc.dg/torture/pr116647.c: New testcase. * gcc.dg/vect/no-scevccp-pr86725-2.c: Adjust expected pattern. * gcc.dg/vect/no-scevccp-pr86725-4.c: Likewise. --- gcc/testsuite/gcc.dg/torture/pr116647.c | 22 +++++++++++++++++++ .../gcc.dg/vect/no-scevccp-pr86725-2.c | 2 +- .../gcc.dg/vect/no-scevccp-pr86725-4.c | 2 +- gcc/tree-vect-loop.cc | 3 ++- 4 files changed, 26 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr116647.c diff --git a/gcc/testsuite/gcc.dg/torture/pr116647.c b/gcc/testsuite/gcc.dg/torture/pr116647.c new file mode 100644 index 00000000000..2b5cc348690 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr116647.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ + +int a; +char b; +long c, d, e; +unsigned long f; +long g() { + if (a <= 0) + return 1; + for (; d; d++) { + e = 0; + for (; e < a; e++) { + unsigned long h = 0; + switch (b) + case 2: + if (e) + h = 5; + c += h; + } + } + c /= f; +} diff --git a/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c b/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c index b208c1a2d61..66185a9483b 100644 --- a/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c +++ b/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-2.c @@ -19,5 +19,5 @@ nr (int xe) return xe; } -/* { dg-final { scan-tree-dump "reduction used in loop" "vect" { target vect_int } } } */ +/* { dg-final { scan-tree-dump "Unknown def-use cycle pattern" "vect" { target vect_int } } } */ /* { dg-final { scan-tree-dump-not "OUTER LOOP VECTORIZED" "vect" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c b/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c index d995c9b30fe..6ada0a10cb3 100644 --- a/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c +++ b/gcc/testsuite/gcc.dg/vect/no-scevccp-pr86725-4.c @@ -19,5 +19,5 @@ nr (unsigned int xe, unsigned int qqn) return xe; } -/* { dg-final { scan-tree-dump "reduction used in loop" "vect" { target vect_int } } } */ +/* { dg-final { scan-tree-dump "Unknown def-use cycle pattern" "vect" { target vect_int } } } */ /* { dg-final { scan-tree-dump-not "OUTER LOOP VECTORIZED" "vect" } } */ diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index e45adbaccbd..77486183a64 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -4342,7 +4342,8 @@ vect_is_simple_reduction (loop_vec_info loop_info, stmt_vec_info phi_info, && is_a (phi_use_stmt) && flow_bb_inside_loop_p (loop->inner, gimple_bb (phi_use_stmt)) && (op1 == PHI_ARG_DEF_FROM_EDGE (phi_use_stmt, - loop_latch_edge (loop->inner)))) + loop_latch_edge (loop->inner))) + && lcphis.length () == 1) { if (dump_enabled_p ()) report_vect_op (MSG_NOTE, def_stmt,