From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id CF1873857354 for ; Thu, 13 Oct 2022 13:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CF1873857354 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-out1.suse.de (Postfix) with ESMTPS id 446C62203D for ; Thu, 13 Oct 2022 13:16:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1665666992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=HYfuzfqSrMuOKrTqGbSAw+m9EckjIIW8QAfZetH9+Kg=; b=K1EzQoU+HrznPHkPst3rSNonCV6eOcnM+PMECrSf7Aora9AXi9JZmIUHe4tvNYtxY9+HO5 00alLsF6I1tm4epCP2gPyTlZ5Xem01w6lbbCjup50lYCsKsOVMFsrHIU91ULblGhm/gt/O pR6cgD6BQD42JpeGphAN4NFiXmcy2MI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1665666992; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=HYfuzfqSrMuOKrTqGbSAw+m9EckjIIW8QAfZetH9+Kg=; b=j5+S7MfhIx9sGTxJkmjy07Y0V274Q46BrO9VMlqWrT/9GHfgm0asds6shkOcmgOxl1FxbU 2ZsDgO7srckGGUAA== 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 1017D13AAA for ; Thu, 13 Oct 2022 13:16:32 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id EEfPArAPSGPsKgAAMHmgww (envelope-from ) for ; Thu, 13 Oct 2022 13:16:32 +0000 Date: Thu, 13 Oct 2022 15:16:31 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/107160 - avoid reusing multiple accumulators MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20221013131632.1017D13AAA@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: Epilogue vectorization is not set up to re-use a vectorized accumulator consisting of more than one vector. For non-SLP we always reduce to a single but for SLP that isn't happening. In such case we currenlty miscompile the epilog so avoid this. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/107160 * tree-vect-loop.cc (vect_create_epilog_for_reduction): Do not register accumulator if we failed to reduce it to a single vector. * gcc.dg/vect/pr107160.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr107160.c | 41 ++++++++++++++++++++++++++++ gcc/tree-vect-loop.cc | 3 +- 2 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr107160.c diff --git a/gcc/testsuite/gcc.dg/vect/pr107160.c b/gcc/testsuite/gcc.dg/vect/pr107160.c new file mode 100644 index 00000000000..4f9f853cafb --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr107160.c @@ -0,0 +1,41 @@ +/* { dg-do run } */ + +#include + +#define N 128 +float fl[N]; + +__attribute__ ((noipa)) void +init () +{ + for (int i = 0; i < N; i++) + fl[i] = i; +} + +__attribute__ ((noipa)) float +foo (int n1) +{ + float sum0, sum1, sum2, sum3; + sum0 = sum1 = sum2 = sum3 = 0.0f; + + int n = (n1 / 4) * 4; + for (int i = 0; i < n; i += 4) + { + sum0 += fabs (fl[i]); + sum1 += fabs (fl[i + 1]); + sum2 += fabs (fl[i + 2]); + sum3 += fabs (fl[i + 3]); + } + + return sum0 + sum1 + sum2 + sum3; +} + +int +main () +{ + init (); + float res = foo (80); + if (res != 3160) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc index 1996ecfee7a..b1442a93581 100644 --- a/gcc/tree-vect-loop.cc +++ b/gcc/tree-vect-loop.cc @@ -6232,7 +6232,8 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo, } /* Record this operation if it could be reused by the epilogue loop. */ - if (STMT_VINFO_REDUC_TYPE (reduc_info) == TREE_CODE_REDUCTION) + if (STMT_VINFO_REDUC_TYPE (reduc_info) == TREE_CODE_REDUCTION + && vec_num == 1) loop_vinfo->reusable_accumulators.put (scalar_results[0], { orig_reduc_input, reduc_info }); -- 2.35.3