From patchwork Tue Sep 26 16:24:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andre Vieira (lists)" X-Patchwork-Id: 1839840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 4Rw4p64cK8z1ypD for ; Wed, 27 Sep 2023 02:24:46 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AE991385DC17 for ; Tue, 26 Sep 2023 16:24:44 +0000 (GMT) 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 34E73385F003 for ; Tue, 26 Sep 2023 16:24:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 34E73385F003 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=arm.com 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 27A481FB; Tue, 26 Sep 2023 09:25:10 -0700 (PDT) Received: from [10.1.31.134] (E121495.arm.com [10.1.31.134]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 5F3493F6C4; Tue, 26 Sep 2023 09:24:31 -0700 (PDT) Message-ID: Date: Tue, 26 Sep 2023 17:24:26 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: "gcc-patches@gcc.gnu.org" Cc: Richard Sandiford , Richard Biener , Andrew Stubbs From: "Andre Vieira (lists)" Subject: [PATCH] vect, omp: inbranch simdclone dropping const X-Spam-Status: No, score=-13.9 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.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 const attribute is ignored when simdclone's are used inbranch. This is due to the fact that when analyzing a MASK_CALL we were not looking at the targeted function for flags, but instead only at the internal function call itself. This patch adds code to make sure we look at the target function to check for the const attribute and enables the autovectorization of inbranch const simdclones without needing the loop to be adorned the 'openmp simd' pragma. Not sure about how to add new includes to the ChangeLog. Which brings me to another point, I contemplated changing gimple_call_flags to do the checking of flags of the first argument of IFN_MASK_CALL itself rather than only calling internal_fn_flags on gimple_call_internal_fn (stmt), but that might be a bit too intrusive, opinions welcome :) Bootstrapped and regression tested on aarch64-unknown-linux-gnu and x86_64-pc-linux-gnu. Is this OK for trunk? gcc/ChangeLog: * tree-vect-data-ref.cc (include calls.h): Add new include. (get_references_in_stmt): Correctly handle IFN_MASK_CALL. gcc/testsuite/ChangeLog: * gcc.dg/vect/vect-simd-clone-19.c: New test. diff --git a/gcc/testsuite/gcc.dg/vect/vect-simd-clone-19.c b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-19.c new file mode 100644 index 0000000000000000000000000000000000000000..09127b8cb6f2e3699b6073591f58be7047330273 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-19.c @@ -0,0 +1,23 @@ +/* { dg-require-effective-target vect_simd_clones } */ +/* { dg-do compile } */ +/* { dg-additional-options "-fopenmp-simd" } */ + +int __attribute__ ((__simd__, const)) fn (int); + +void test (int * __restrict__ a, int * __restrict__ b, int n) +{ + for (int i = 0; i < n; ++i) + { + int a_; + if (b[i] > 0) + a_ = fn (b[i]); + else + a_ = b[i] + 5; + a[i] = a_; + } +} + +/* { dg-final { scan-tree-dump-not {loop contains function calls or data references} "vect" } } */ + +/* The LTO test produces two dump files and we scan the wrong one. */ +/* { dg-skip-if "" { *-*-* } { "-flto" } { "" } } */ diff --git a/gcc/tree-data-ref.cc b/gcc/tree-data-ref.cc index 6d3b7c2290e4db9c1168a4c763facb481157c97c..2926c3925ee7897fef53c16cfd1d19d23dbf05f3 100644 --- a/gcc/tree-data-ref.cc +++ b/gcc/tree-data-ref.cc @@ -100,6 +100,7 @@ along with GCC; see the file COPYING3. If not see #include "vr-values.h" #include "range-op.h" #include "tree-ssa-loop-ivopts.h" +#include "calls.h" static struct datadep_stats { @@ -5816,6 +5817,18 @@ get_references_in_stmt (gimple *stmt, vec *references) } case IFN_MASK_LOAD: case IFN_MASK_STORE: + case IFN_MASK_CALL: + { + tree orig_fndecl + = gimple_call_addr_fndecl (gimple_call_arg (stmt, 0)); + if (!orig_fndecl) + { + clobbers_memory = true; + break; + } + if ((flags_from_decl_or_type (orig_fndecl) & ECF_CONST) == 0) + clobbers_memory = true; + } break; default: clobbers_memory = true; @@ -5852,7 +5865,7 @@ get_references_in_stmt (gimple *stmt, vec *references) } else if (stmt_code == GIMPLE_CALL) { - unsigned i, n; + unsigned i = 0, n; tree ptr, type; unsigned int align; @@ -5879,13 +5892,15 @@ get_references_in_stmt (gimple *stmt, vec *references) ptr); references->safe_push (ref); return false; + case IFN_MASK_CALL: + i = 1; default: break; } op0 = gimple_call_lhs (stmt); n = gimple_call_num_args (stmt); - for (i = 0; i < n; i++) + for (; i < n; i++) { op1 = gimple_call_arg (stmt, i);