From patchwork Mon Jul 1 08:14:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1954540 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=zzYjvP6X; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=DPN+Xu2+; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=zzYjvP6X; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=DPN+Xu2+; 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 4WCJl23n8vz1xpT for ; Mon, 1 Jul 2024 18:15:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 90CF73899091 for ; Mon, 1 Jul 2024 08:15:37 +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 A338338197E5 for ; Mon, 1 Jul 2024 08:14:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A338338197E5 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 A338338197E5 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=1719821703; cv=none; b=U5iFU/EL65i5qETdDTsX2bY1TbxE5P/EhArZRdICIP70GNjEnb8MKU8+OMiFE7QOTPjmAi8p00BLGTBOZK/8uY66tY41ho1GrIEQiceAvI4Jqj26UJJMEgOpmpRSoFVyoGnPwp9bOsKIoRBhONG2jBFFQNF+WFDoAYnkq3YqN+M= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719821703; c=relaxed/simple; bh=QaFL6D+ny9OjCw/vn30WYrh//hzAL/slqUExDFLTEPg=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version:Message-Id; b=kr7xsloXPAUSGjPrPqbjjUoBIv5O5DZudTI+om2Tce1/WgNdXJV5PsLIJpCq/1hvyzYiWMAUO5oURHJlnoh9jTm4/K0lU2L4qxWRLafsh+UbGMcKre6uUjHSbxY476aqbITt5xfqWdTnYgffY0+/KAqCNyaPvYbryc0VWAxNjT4= 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 A6E571F828; Mon, 1 Jul 2024 08:14:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719821689; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=B1zY0sd8l6WQ+7gtpqkfi2M7JHWt6HyIRS/J0YzTbKs=; b=zzYjvP6X8uLp5T02+YzMKXio38b6nJkNAAzIlo5x+DbXH677dxApZaWhpRRb0eYGlfVH0X dqEUJfIwbyk10n8PhgYPpUli+Oms/x6ka/HBEb5cRivoshkF42Gf/4ZIyCUNqh8Ds9VMZ2 rgvcduDWZhFnIaCcvOzz2k+EJXcqizQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719821689; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=B1zY0sd8l6WQ+7gtpqkfi2M7JHWt6HyIRS/J0YzTbKs=; b=DPN+Xu2+CM2xzU0jwPRd67ccqF0i6DOF1mntOhUHMcW9pQfIBpSgClInAbWWORBJpR03kd zJKU8TxGYuUaNmBQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1719821689; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=B1zY0sd8l6WQ+7gtpqkfi2M7JHWt6HyIRS/J0YzTbKs=; b=zzYjvP6X8uLp5T02+YzMKXio38b6nJkNAAzIlo5x+DbXH677dxApZaWhpRRb0eYGlfVH0X dqEUJfIwbyk10n8PhgYPpUli+Oms/x6ka/HBEb5cRivoshkF42Gf/4ZIyCUNqh8Ds9VMZ2 rgvcduDWZhFnIaCcvOzz2k+EJXcqizQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1719821689; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=B1zY0sd8l6WQ+7gtpqkfi2M7JHWt6HyIRS/J0YzTbKs=; b=DPN+Xu2+CM2xzU0jwPRd67ccqF0i6DOF1mntOhUHMcW9pQfIBpSgClInAbWWORBJpR03kd zJKU8TxGYuUaNmBQ== 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 86BAD13800; Mon, 1 Jul 2024 08:14:49 +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 o0s+H3llgmaifQAAD6G6ig (envelope-from ); Mon, 01 Jul 2024 08:14:49 +0000 Date: Mon, 1 Jul 2024 10:14:45 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org cc: rdapp.gcc@gmail.com Subject: [PATCH] tree-optimization/115723 - ICE with .COND_ADD reduction MIME-Version: 1.0 Message-Id: <20240701081449.86BAD13800@imap1.dmz-prg2.suse.org> 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_TLS_ALL(0.00)[]; RCPT_COUNT_TWO(0.00)[2]; TAGGED_RCPT(0.00)[]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MISSING_XM_UA(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVRCPT(0.00)[gmail.com]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; FREEMAIL_CC(0.00)[gmail.com]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo] X-Spam-Score: -4.30 X-Spam-Level: X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, 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 The following fixes an ICE with a .COND_ADD discovered as reduction even though its else value isn't the reduction chain link but a constant. This would be wrong-code with --disable-checking I think. Bootstrap and regtest running on x86_64-unknown-linux-gnu. PR tree-optimization/115723 * tree-vect-loop.cc (check_reduction_path): For a .COND_ADD verify the else value also refers to the reduction chain op. * gcc.dg/vect/pr115723.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr115723.c | 25 +++++++++++++++++++++++++ gcc/tree-vect-loop.cc | 12 ++++++++---- 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr115723.c diff --git a/gcc/testsuite/gcc.dg/vect/pr115723.c b/gcc/testsuite/gcc.dg/vect/pr115723.c new file mode 100644 index 00000000000..b98b29d4870 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr115723.c @@ -0,0 +1,25 @@ +/* { dg-additional-options "-ffast-math -fno-unsafe-math-optimizations" } */ + +#include "tree-vect.h" + +double __attribute__((noipa)) +foo (double *x, double *y, int n) +{ + double res = 0.; + for (int i = 0; i < n; ++i) + if (y[i] > 0.) + res += x[i]; + else + res = 64.; + return res; +} + +double y[16] = { 1., 1., 1., 1., 0., 1., 1., 1., + 1., 1., 1., 1., 1., 1., 1., 1. }; +int main () +{ + check_vect (); + if (foo (y, y, 16) != 64. + 11.) + abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 3095ff5ab6b..a64b5082bd1 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -4163,15 +4163,19 @@ pop: FOR_EACH_IMM_USE_STMT (op_use_stmt, imm_iter, op.ops[opi]) { - /* In case of a COND_OP (mask, op1, op2, op1) reduction we might have - op1 twice (once as definition, once as else) in the same operation. - Allow this. */ + /* In case of a COND_OP (mask, op1, op2, op1) reduction we should + have op1 twice (once as definition, once as else) in the same + operation. Enforce this. */ if (cond_fn_p && op_use_stmt == use_stmt) { gcall *call = as_a (use_stmt); unsigned else_pos = internal_fn_else_index (internal_fn (op.code)); - + if (gimple_call_arg (call, else_pos) != op.ops[opi]) + { + fail = true; + break; + } for (unsigned int j = 0; j < gimple_call_num_args (call); ++j) { if (j == else_pos)