From patchwork Wed Sep 15 09:13:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 45018 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E131D3858039 for ; Wed, 15 Sep 2021 09:14:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E131D3858039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631697268; bh=9qFk60HbfCJ786pD6kdVrav4h+7N1xJwkPR0nIenmBQ=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=PcLh1LJRtNG8A/K0Z5NpG5aj4AyhDl68UaEBjvK4kFvIcEzBjhjiE2BiVfzqVBsKf XcChm9dQk4psPDlhXprZjysiBb++iOJAqRQNAdvScGZz4oO+Gebud6nkKi0sOYjHBd 628bOmd7g3nOe+XjH+g4nuecbOZmXzmmVzYBPK3g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 0642B3858018 for ; Wed, 15 Sep 2021 09:13:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0642B3858018 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 074EE22179 for ; Wed, 15 Sep 2021 09:13:02 +0000 (UTC) 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 E67B213AD4 for ; Wed, 15 Sep 2021 09:13:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id tvscNx25QWENTwAAMHmgww (envelope-from ) for ; Wed, 15 Sep 2021 09:13:01 +0000 Date: Wed, 15 Sep 2021 11:13:01 +0200 (CEST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/102318 - reduction epilogue re-use Message-ID: MIME-Version: 1.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This refines the fix for PR102226 to do the mode conversion from V2DI to VNx2DI separately from the sign-conversion, retaining the signedness of the saved accumulator as before the original fix. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-09-15 Richard Biener PR tree-optimization/102318 * tree-vect-loop.c (vect_transform_cycle_phi): Revert previous change and do the mode conversion separately from the sign conversion. * gcc.dg/vect/pr102318.c: New testcase. --- gcc/testsuite/gcc.dg/vect/pr102318.c | 21 +++++++++++++++++++++ gcc/tree-vect-loop.c | 13 +++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr102318.c diff --git a/gcc/testsuite/gcc.dg/vect/pr102318.c b/gcc/testsuite/gcc.dg/vect/pr102318.c new file mode 100644 index 00000000000..cc58efacecd --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr102318.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ + +void +vec_slp_int16_t (short int *restrict a, short int *restrict b, int n) +{ + short int x0 = b[0]; + short int x1 = b[1]; + short int x2 = b[2]; + short int x3 = b[3]; + for (int i = 0; i < n; ++i) + { + x0 += a[i * 4]; + x1 += a[i * 4 + 1]; + x2 += a[i * 4 + 2]; + x3 += a[i * 4 + 3]; + } + b[0] = x0; + b[1] = x1; + b[2] = x2; + b[3] = x3; +} diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index c9dcc647d2c..5a5b8da2e77 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -7755,11 +7755,20 @@ vect_transform_cycle_phi (loop_vec_info loop_vinfo, (reduc_info), &stmts); } - if (!useless_type_conversion_p (vectype_out, TREE_TYPE (def))) - def = gimple_convert (&stmts, vectype_out, def); + /* The epilogue loop might use a different vector mode, like + VNx2DI vs. V2DI. */ + if (TYPE_MODE (vectype_out) != TYPE_MODE (TREE_TYPE (def))) + { + tree reduc_type = build_vector_type_for_mode + (TREE_TYPE (TREE_TYPE (def)), TYPE_MODE (vectype_out)); + def = gimple_convert (&stmts, reduc_type, def); + } /* Adjust the input so we pick up the partially reduced value for the skip edge in vect_create_epilog_for_reduction. */ accumulator->reduc_input = def; + /* And the reduction could be carried out using a different sign. */ + if (!useless_type_conversion_p (vectype_out, TREE_TYPE (def))) + def = gimple_convert (&stmts, vectype_out, def); if (loop_vinfo->main_loop_edge) { /* While we'd like to insert on the edge this will split