From patchwork Thu Oct 13 13:16:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 2049 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp274296wrs; Thu, 13 Oct 2022 06:18:54 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7vBQSJBnvK9QR9VwM7JOA6CgvlkXqleYUR5BmX4uijjwKnetzgFn5j1oA1Ir6PVZ4HfG7h X-Received: by 2002:a17:907:3207:b0:741:3a59:738d with SMTP id xg7-20020a170907320700b007413a59738dmr26845872ejb.110.1665667134390; Thu, 13 Oct 2022 06:18:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665667134; cv=none; d=google.com; s=arc-20160816; b=FK0B6TxipCPXTSNdcDxBMkgb1FmYwPrhb6pt0Z76KO7R/L3N34QVuP3Ycmx5w7p8tu x8nO1H+C9JEUPCDelsah2zDjPLFhbJDIOMmc2lsWbAT3wHgJkokJzedqn4C8XFGQeBZ2 CAlbRTmWL5wJ6+SSSoxpm+t2Og8m6jOBhQ50PLB5CG/FtHeIniRiPTejA2lFdlIrIQU0 lX467TFx82Xdzh0rSwvhgKsGRDBO9yTXg1aCM03SudvyvWJFV5Zi0eUUdj9MM/sRNVKl +R46fW8JJ1bIU9z+ib8VvJyHyCC0a88wksbCaeayJm4YaIQGCL6gR1HARIVRyd7bWcnr oRvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:message-id :mime-version:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=HYfuzfqSrMuOKrTqGbSAw+m9EckjIIW8QAfZetH9+Kg=; b=WLcAzggaQ2qQ7LqPaMQV4+/KwdHuzK44KIrz/fH5fQ/75dS4HnCJvmx3hLoz5k0Q4e 9uEOlKJx4JhIzI+tgbwtRMCJKup9NAhRkakvAV5GwXUrAYjiGRXg3Fm+vQmkJfnQDIUY xvYHfR0b/FiG0IMGrwUu0dceEHDzzZqbSq6uHwvua19gfeM1B9IsvdKtHaQdSDQmi08m +IoEvBBlPgdp1wHX/E1Gel1KhCEkzDaMAf2Ndw+Eo6vwtELCJRUK4WPnQxTWPxt/N64B NiulgL28ex9hHXeC+AJFE2+rIP4CF2oayoObYKbapd3fTOkHpmfeG/VfneAJ48Gm+Jy/ O3AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NmgbhRN5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id o14-20020a509b0e000000b00459ef929ab9si16750261edi.224.2022.10.13.06.18.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Oct 2022 06:18:54 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NmgbhRN5; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A09B73850237 for ; Thu, 13 Oct 2022 13:18:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A09B73850237 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665667114; bh=HYfuzfqSrMuOKrTqGbSAw+m9EckjIIW8QAfZetH9+Kg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=NmgbhRN5Dlqcx0acPTaa+IjqgCYQjZ3andoJjP/wRSnYf9NhzhluE1Fau3MUiwkBd R98Ua1yylYM4WZtH16cUlqdfpSUpzglx7orQyN7inGGa5fBwvcyKnP1nF84tSy6ep9 +Spw4/+ylnO9ZEvQIqMaGpt6aQn8+Zmiw0Qj7pkI= 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 CF1873857354 for ; Thu, 13 Oct 2022 13:16:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CF1873857354 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) 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) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/107160 - avoid reusing multiple accumulators MIME-Version: 1.0 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 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746578580824912478?= X-GMAIL-MSGID: =?utf-8?q?1746578580824912478?= 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 });