From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37626 invoked by alias); 31 May 2019 09:33:31 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 37617 invoked by uid 89); 31 May 2019 09:33:31 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.8 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=1207, regtest X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 31 May 2019 09:33:30 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D81D810F08; Fri, 31 May 2019 09:33:28 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7E8FB7E8E0; Fri, 31 May 2019 09:33:28 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id x4V9XQBi019115; Fri, 31 May 2019 11:33:26 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id x4V9XNYB019114; Fri, 31 May 2019 11:33:23 +0200 Date: Fri, 31 May 2019 09:43:00 -0000 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Handle "omp simd array" accesses in ifcvt_memrefs_wont_trap Message-ID: <20190531093323.GF19695@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.11.3 (2019-02-01) X-IsSubscribed: yes X-SW-Source: 2019-05/txt/msg02103.txt.bz2 Hi! As a preparation for lastprivate(conditional:) on #pragma omp simd, I need if-conversion to handle "omp simd array" accesses. These are safe, no matter whether written or read, each simd lane accesses their own element, after the vectorization it is all just a single vector read or store or RMW cycle, it will never trap (it is an automatic variable), it will never be out of bounds (the index is guaranteed to be within the bounds of the array, as the array is sized to the vectorization factor and index is the simd lane number within that vectorization factor). Tested on x86_64-linux with vect.exp, ok for trunk if it passes full bootstrap/regtest? 2019-05-31 Jakub Jelinek * tree-if-conv.c: Include attribs.h. (ifcvt_memrefs_wont_trap): Return true for ARRAY_REF access to "omp simd array" variable with .GOMP_SIMD_LANE as index. * gcc.dg/vect/vect-cond-12.c: New test. --- gcc/tree-if-conv.c.jj 2019-05-14 21:37:32.932400472 +0200 +++ gcc/tree-if-conv.c 2019-05-31 11:13:13.558732900 +0200 @@ -120,6 +120,7 @@ along with GCC; see the file COPYING3. #include "fold-const.h" #include "tree-ssa-sccvn.h" #include "tree-cfgcleanup.h" +#include "attribs.h" /* Only handle PHIs with no more arguments unless we are asked to by simd pragma. */ @@ -897,6 +898,32 @@ ifcvt_memrefs_wont_trap (gimple *stmt, v if (DR_W_UNCONDITIONALLY (*master_dr)) return true; + /* OpenMP simd lane accesses to omp simd array variables are always + within bounds and can be handled as if it was unconditional. */ + tree base_var = get_base_address (base); + if (VAR_P (base_var) + && lookup_attribute ("omp simd array", DECL_ATTRIBUTES (base_var))) + { + tree ref = DR_REF (a); + struct loop *loop = loop_containing_stmt (stmt); + if (loop->simduid + && TREE_CODE (ref) == ARRAY_REF + && TREE_CODE (TREE_OPERAND (ref, 1)) == SSA_NAME) + { + gimple *def = SSA_NAME_DEF_STMT (TREE_OPERAND (ref, 1)); + if (is_gimple_call (def) + && gimple_call_internal_p (def) + && (gimple_call_internal_fn (def) == IFN_GOMP_SIMD_LANE)) + { + tree arg = gimple_call_arg (def, 0); + gcc_assert (TREE_CODE (arg) == SSA_NAME); + arg = SSA_NAME_VAR (arg); + if (arg == loop->simduid) + return true; + } + } + } + /* If a is unconditionally accessed then ... Even a is conditional access, we can treat it as an unconditional --- gcc/testsuite/gcc.dg/vect/vect-cond-12.c.jj 2019-05-31 11:25:33.203577504 +0200 +++ gcc/testsuite/gcc.dg/vect/vect-cond-12.c 2019-05-31 11:26:58.616174115 +0200 @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fopenmp-simd" } */ +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { target vect_condition } } } */ + +int x; + +void +foo (int *a) +{ + #pragma omp simd lastprivate (x) + for (int i = 0; i < 1024; ++i) + if (a[i]) + x = i; +} Jakub