From patchwork Fri Sep 16 07:58:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 1248 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp637820wrt; Fri, 16 Sep 2022 00:59:48 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4Mxa6I7mBr9/+f/clWGgLJs50KGynqAj+yHLhIEeTuL+Nv4xNZTi0GfqXHH/65YkJD78z/ X-Received: by 2002:a17:907:dac:b0:775:58d2:defe with SMTP id go44-20020a1709070dac00b0077558d2defemr2713208ejc.231.1663315188808; Fri, 16 Sep 2022 00:59:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663315188; cv=none; d=google.com; s=arc-20160816; b=ddLyTZBtZDDVSd+2IxPYNXQrIqK1awBzkYfubcZjCks7CzqVCgbeTsqwD1ffRlnUkv BbHtjTT4rDzb8RJfChL7BEaMR1B2Ne37xQikvrwwofpZ54jsPZJnvv9OfjYA5Y5VI5o0 3v1gTF9/dgCibR0WF89NSZqbzHLe2UrlDXj895KHZmqseL5n+tAY8MYlb+qgPg0R01Df 7Mk5mjYw9jH0oWnC6iIMIX0F1TBe7M4ZjqeqP2QqamOFOqj4Dx/8pGguZb9CQPyr8GDL 1pgQUlkBi4ROHrI/h5BBOXiPR4/fWKC4Zr5+svUZ/xuGAvEB+XDgm2F4lBXdDnMIg+oX 98Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:message-id:date:subject:mail-followup-to:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=+esIB+ySKh00E6GY9ROKbvqRz45CdW+dhk8G+aGVCo0=; b=txINFjVhUNz1rGgtAHosi7pW3UK+hDKu3jX7PluTtltz3+ZwH6ehGIUWqyvZV41PVC b6qgiWJP2xWrXErP15xkga88/UQ9rj0F3NUJlbnQexVmRqOqxuMUp1OkysUaKfbP/9KV yxxfCj7Cc9p5QShwp/e4ewes4VhwJOpVf3aGIL6+18+CskkICVRGbaBu2MenOsyc+Z2B rSpv40FUrHJA9H+6oliaQ4pfQslI5E4mw3rUi9Rz0hYOl//X6DkltFGR3niYmotr+OGs MOHsK6dsjIa688OfZok+iqcEiRIMj1+4nyDxz5Btt3dv+MRacrEGBveNptRGfed2k7UE v7ag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ruUse6Ks; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id f17-20020a0564021e9100b00450f1234f6bsi1954568edf.129.2022.09.16.00.59.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Sep 2022 00:59:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ruUse6Ks; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 4914B385380E for ; Fri, 16 Sep 2022 07:59:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4914B385380E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663315181; bh=+esIB+ySKh00E6GY9ROKbvqRz45CdW+dhk8G+aGVCo0=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=ruUse6KsIWu/A+b3S5K+w4JvcwbNn7bnrcij2FMtBhGzp47/VoQfYEirqr1kTPy9M EvpIK3ZLXFxKi9zDJBQdhw4RRsOXESp6t7jttBYxBW0XvOHxQtUJiqsFXIDtfOrbjN ePH1slihc5b9iGTchJeG0ohmA9Sm51HgDYVdQq/Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by sourceware.org (Postfix) with ESMTP id 190333853809 for ; Fri, 16 Sep 2022 07:58:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 190333853809 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 233191D34; Fri, 16 Sep 2022 00:59:04 -0700 (PDT) Received: from localhost (e121540-lin.manchester.arm.com [10.32.98.62]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 34CE33F73D; Fri, 16 Sep 2022 00:58:57 -0700 (PDT) To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, rguenther@suse.de, richard.sandiford@arm.com Subject: [PATCH] vect: Fix missed gather load opportunity Date: Fri, 16 Sep 2022 08:58:55 +0100 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) MIME-Version: 1.0 X-Spam-Status: No, score=-48.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_NONE, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_NONE, SPF_NONE, 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 Sandiford via Gcc-patches From: Richard Sandiford Reply-To: Richard Sandiford Cc: rguenther@suse.de 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?1744112387831823328?= X-GMAIL-MSGID: =?utf-8?q?1744112387831823328?= While writing a testcase for PR106794, I noticed that we failed to vectorise the testcase in the patch for SVE. The code that recognises gather loads tries to optimise the point at which the offset is calculated, to avoid unnecessary extensions or truncations: /* Don't include the conversion if the target is happy with the current offset type. */ But breaking only makes sense if we're at an SSA_NAME (which could then be vectorised). We shouldn't break on a conversion embedded in a generic expression. Tested on aarch64-linux-gnu & x86_64-linux-gnu. OK to install? Richard gcc/ * tree-vect-data-refs.cc (vect_check_gather_scatter): Restrict early-out optimisation to SSA_NAMEs. gcc/testsuite/ * gcc.dg/vect/vect-gather-5.c: New test. --- gcc/testsuite/gcc.dg/vect/vect-gather-5.c | 42 +++++++++++++++++++++++ gcc/tree-vect-data-refs.cc | 1 + 2 files changed, 43 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/vect/vect-gather-5.c diff --git a/gcc/testsuite/gcc.dg/vect/vect-gather-5.c b/gcc/testsuite/gcc.dg/vect/vect-gather-5.c new file mode 100644 index 00000000000..8b5074bba88 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-gather-5.c @@ -0,0 +1,42 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-O3" } */ + +#ifdef __aarch64__ +#pragma GCC target "+sve" +#endif + +long a[100], b[100], c[100]; + +void g1 () +{ + for (int i = 0; i < 100; i += 2) + { + c[i] += a[b[i]] + 1; + c[i + 1] += a[b[i + 1]] + 2; + } +} + +long g2 () +{ + long res = 0; + for (int i = 0; i < 100; i += 2) + { + res += a[b[i + 1]]; + res += a[b[i]]; + } + return res; +} + +long g3 () +{ + long res = 0; + for (int i = 0; i < 100; i += 2) + { + res += a[b[i]]; + res += a[b[i + 1]]; + } + return res; +} + +/* { dg-final { scan-tree-dump-times {add new stmt[^\n]*GATHER_LOAD} 3 "vect" { target aarch64*-*-* } } } */ +/* { dg-final { scan-tree-dump-not {add new stmt[^\n]*VEC_PERM_EXPR} "vect" { target aarch64*-*-* } } } */ diff --git a/gcc/tree-vect-data-refs.cc b/gcc/tree-vect-data-refs.cc index b279a82551e..e03b50498d1 100644 --- a/gcc/tree-vect-data-refs.cc +++ b/gcc/tree-vect-data-refs.cc @@ -4151,6 +4151,7 @@ vect_check_gather_scatter (stmt_vec_info stmt_info, loop_vec_info loop_vinfo, /* Don't include the conversion if the target is happy with the current offset type. */ if (use_ifn_p + && TREE_CODE (off) == SSA_NAME && !POINTER_TYPE_P (TREE_TYPE (off)) && vect_gather_scatter_fn_p (loop_vinfo, DR_IS_READ (dr), masked_p, vectype, memory_type,