From patchwork Thu Feb 22 12:08:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1902746 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=JHjNrVQu; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=r8JBGLZ4; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=JHjNrVQu; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=r8JBGLZ4; 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 4TgX4F6HPfz23cl for ; Thu, 22 Feb 2024 23:09:01 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D1613858416 for ; Thu, 22 Feb 2024 12:08:59 +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 010E73858C42 for ; Thu, 22 Feb 2024 12:08:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 010E73858C42 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 010E73858C42 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=1708603718; cv=none; b=gQwEibKDCtOhL0uQhUSyUDyVd2NplHJ+NLIL78MA98NguOgqrYBqHEgeP87f22dErWyouAj1ingseZNJw/4T0f3L0IiV1Nqo63QVux70XIjm9E7TDlHuTcFyzKNBafIXHmIGQUdHBvYHgcHuWh0ItbsXgLTIIOOVoo3DWf+SW/k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708603718; c=relaxed/simple; bh=hM4GWb0osnCxidRwgxg8HRdP8HB77LQ0H5frU3vsM/o=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=UaxH7h76Mevo5HbWDIDvSgl6r4xO39nKG5SyAjX74N48/wydL/d/hnd/15a3TMQcumFct4mdYb/p/dgiZJGqww4AVRytYHuzAgYYzmy+wqIIZ7I+a7KO9QPSpjs+neo/y4s1nRrvirqmjzwoc4+udedX8fJwP4KeiUYzkVhRONc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (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 B5E761F457 for ; Thu, 22 Feb 2024 12:08:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708603715; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Qd21X3FQkYJrpfPuQzrXc7oz5IB2aVc7RF8j12HTYPc=; b=JHjNrVQuT+0mjE0Yt67DsfjQXrIBBPtLAimhsYEEP9U9DA4+QSYDYLp7Wp4hlnfy6SI8Dl MaLd2k7hDCjUMPzi+VbgFB3X/4A63BmFBDbA1e8WIMsh4eNr/7NkbXkRmem7TBY1K4QDc2 CnlDIomOdJoeAvqKcnOGCv8cpNWVeMs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708603715; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Qd21X3FQkYJrpfPuQzrXc7oz5IB2aVc7RF8j12HTYPc=; b=r8JBGLZ4DQto1YEUCRQ+aWuAKHtDl7NZK4L9Qf3JuE+mCckngIOUpaMa7OpcGSjcM7Jpad gtQKi+SsRZJhCiDw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1708603715; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Qd21X3FQkYJrpfPuQzrXc7oz5IB2aVc7RF8j12HTYPc=; b=JHjNrVQuT+0mjE0Yt67DsfjQXrIBBPtLAimhsYEEP9U9DA4+QSYDYLp7Wp4hlnfy6SI8Dl MaLd2k7hDCjUMPzi+VbgFB3X/4A63BmFBDbA1e8WIMsh4eNr/7NkbXkRmem7TBY1K4QDc2 CnlDIomOdJoeAvqKcnOGCv8cpNWVeMs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1708603715; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=Qd21X3FQkYJrpfPuQzrXc7oz5IB2aVc7RF8j12HTYPc=; b=r8JBGLZ4DQto1YEUCRQ+aWuAKHtDl7NZK4L9Qf3JuE+mCckngIOUpaMa7OpcGSjcM7Jpad gtQKi+SsRZJhCiDw== Date: Thu, 22 Feb 2024 13:08:35 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/114027 - conditional reduction chain MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Level: X-Spam-Score: -1.64 X-Spamd-Result: default: False [-1.64 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.99)[-0.991]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.05)[-0.271]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] 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, T_SCC_BODY_TEXT_LINE 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: <20240222120859.8D1613858416@sourceware.org> When we classify a conditional reduction chain as CONST_COND_REDUCTION we fail to verify all involved conditionals have the same constant. That's a quite unlikely situation so the following simply disables such classification when there's more than one reduction statement. Bootstrapped and tested on x86_64-unkown-linux-gnu, pushed. Richard. PR tree-optimization/114027 * tree-vect-loop.cc (vecctorizable_reduction): Use optimized condition reduction classification only for single-element chains. * gcc.dg/vect/pr114027.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr114027.c | 26 ++++++++++++++++++++++++++ gcc/tree-vect-loop.cc | 11 ++++++----- 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr114027.c diff --git a/gcc/testsuite/gcc.dg/vect/pr114027.c b/gcc/testsuite/gcc.dg/vect/pr114027.c new file mode 100644 index 00000000000..ead9cdd982d --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr114027.c @@ -0,0 +1,26 @@ +#include "tree-vect.h" + +int __attribute__((noipa)) +foo (int *f, int n) +{ + int res = 0; + for (int i = 0; i < n; ++i) + { + if (f[2*i]) + res = 2; + if (f[2*i+1]) + res = -2; + } + return res; +} + +int f[] = { 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 0 }; + +int +main () +{ + if (foo (f, 16) != 2) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 5a5865c42fc..35f1f8c7d42 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -7759,17 +7759,18 @@ vectorizable_reduction (loop_vec_info loop_vinfo, < GET_MODE_SIZE (SCALAR_TYPE_MODE (TREE_TYPE (vectype_op[i])))))) vectype_in = vectype_op[i]; - if (op.code == COND_EXPR) + /* Record how the non-reduction-def value of COND_EXPR is defined. + ??? For a chain of multiple CONDs we'd have to match them up all. */ + if (op.code == COND_EXPR && reduc_chain_length == 1) { - /* Record how the non-reduction-def value of COND_EXPR is defined. */ if (dt == vect_constant_def) { cond_reduc_dt = dt; cond_reduc_val = op.ops[i]; } - if (dt == vect_induction_def - && def_stmt_info - && is_nonwrapping_integer_induction (def_stmt_info, loop)) + else if (dt == vect_induction_def + && def_stmt_info + && is_nonwrapping_integer_induction (def_stmt_info, loop)) { cond_reduc_dt = dt; cond_stmt_vinfo = def_stmt_info;