From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1971) id EB3333857B93; Wed, 27 Sep 2023 12:22:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EB3333857B93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1695817361; bh=EHFkqJ75wxA0flZThcs/htKIn4aU034XDLKXcUh8olQ=; h=From:To:Subject:Date:From; b=xIfbwU6K9Pp8SZmvR06k24SQW0oQTMChNzPaxTiuPXwTIVWxg5b1XBiKSb+mpVaDR Wn0xetGeXaHTkohwTnIytDQ0PR9kq9SDZIWDEY2x65QMQo31me6gUxbYKskOukEjuY e764suZx6f5vGfr+uyx3oy7h9qZCOdaKyCoI4Hks= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andre Simoes Dias Vieira To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-4296] vect, omp: inbranch simdclone dropping const X-Act-Checkin: gcc X-Git-Author: Andre Vieira X-Git-Refname: refs/heads/master X-Git-Oldrev: f7d7e26f10e8e329c3521ae7475ed2dfa38ba677 X-Git-Newrev: b31218bc93683554077c68dec14f4217a5e66835 Message-Id: <20230927122241.EB3333857B93@sourceware.org> Date: Wed, 27 Sep 2023 12:22:41 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b31218bc93683554077c68dec14f4217a5e66835 commit r14-4296-gb31218bc93683554077c68dec14f4217a5e66835 Author: Andre Vieira Date: Wed Sep 27 11:05:40 2023 +0100 vect, omp: inbranch simdclone dropping const 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. gcc/ChangeLog: * tree-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: --- gcc/testsuite/gcc.dg/vect/vect-simd-clone-19.c | 22 ++++++++++++++++++++++ gcc/tree-data-ref.cc | 17 +++++++++++++++-- 2 files changed, 37 insertions(+), 2 deletions(-) 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 00000000000..e7ed56ca754 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-simd-clone-19.c @@ -0,0 +1,22 @@ +/* { dg-require-effective-target vect_simd_clones } */ +/* { dg-do compile } */ + +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 6d3b7c2290e..689aaeed722 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,15 @@ get_references_in_stmt (gimple *stmt, vec *references) } case IFN_MASK_LOAD: case IFN_MASK_STORE: + break; + case IFN_MASK_CALL: + { + tree orig_fndecl + = gimple_call_addr_fndecl (gimple_call_arg (stmt, 0)); + if (!orig_fndecl + || (flags_from_decl_or_type (orig_fndecl) & ECF_CONST) == 0) + clobbers_memory = true; + } break; default: clobbers_memory = true; @@ -5852,7 +5862,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 +5889,16 @@ get_references_in_stmt (gimple *stmt, vec *references) ptr); references->safe_push (ref); return false; + case IFN_MASK_CALL: + i = 1; + gcc_fallthrough (); 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);