From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27165 invoked by alias); 29 Sep 2017 12:32:46 -0000 Mailing-List: contact libstdc++-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libstdc++-owner@gcc.gnu.org Received: (qmail 26407 invoked by uid 89); 29 Sep 2017 12:32:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-Spam-User: qpsmtpd, 2 recipients 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, 29 Sep 2017 12:32:43 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 750ADC04AC41; Fri, 29 Sep 2017 12:32:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 750ADC04AC41 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=jakub@redhat.com Received: from tucnak.zalov.cz (ovpn-116-41.ams2.redhat.com [10.36.116.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A9739183E1; Fri, 29 Sep 2017 12:32:38 +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 v8TCWa5c002490; Fri, 29 Sep 2017 14:32:36 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v8TCWXud002489; Fri, 29 Sep 2017 14:32:33 +0200 Date: Fri, 29 Sep 2017 12:32:00 -0000 From: Jakub Jelinek To: Jason Merrill Cc: "Joseph S. Myers" , Marek Polacek , Jonathan Wakely , gcc-patches List , libstdc++ Subject: Re: [PATCH] Improve -Ofast vectorization of std::sin etc. (PR libstdc++/81706) Message-ID: <20170929123233.GK1701@tucnak> Reply-To: Jakub Jelinek References: <20170807090825.GK2123@tucnak> <20170807152742.GM2123@tucnak> <20170901111249.GD2323@tucnak> <20170912074920.GC1701@tucnak> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20170912074920.GC1701@tucnak> User-Agent: Mutt/1.7.1 (2016-10-04) X-SW-Source: 2017-09/txt/msg00105.txt.bz2 On Tue, Sep 12, 2017 at 09:49:20AM +0200, Jakub Jelinek wrote: > On Sat, Sep 09, 2017 at 03:42:35PM +0200, Jason Merrill wrote: > > On Fri, Sep 1, 2017 at 1:12 PM, Jakub Jelinek wrote: > > > + tree s = lookup_attribute ("omp declare simd", > > > + DECL_ATTRIBUTES (newdecl)); > > > + if (s) > > > + { > > > + tree b > > > + = builtin_decl_explicit (DECL_FUNCTION_CODE (newdecl)); > > > + if (b) > > > + duplicate_one_attribute (&DECL_ATTRIBUTES (b), s, > > > + "omp declare simd"); > > > + } > > > > Is there a reason not to set b first and move the lookup of s into the > > function as well? > > I wanted to handle the most common case (no DECL_ATTRIBUTES at all) and the > second most common case (lookup_attribute returning NULL) inline, otherwise > we'll do an extra function call for all builtins in all cases. > But if you strongly prefer that lookup to be in duplicate_one_attribute, > I can change the patch and retest. Here is a patch which does that. Also bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2017-09-29 Jakub Jelinek PR libstdc++/81706 * attribs.c (attribute_value_equal): Use omp_declare_simd_clauses_equal for comparison of OMP_CLAUSEs regardless of flag_openmp{,_simd}. (duplicate_one_attribute): New function. * attribs.h (duplicate_one_attribute): New declaration. * c-decl.c (merge_decls): Copy "omp declare simd" attributes from newdecl to corresponding __builtin_ if any. * decl.c (duplicate_decls): Copy "omp declare simd" attributes from newdecl to corresponding __builtin_ if any. * gcc.target/i386/pr81706.c: New test. * g++.dg/ext/pr81706.C: New test. --- gcc/attribs.c.jj 2017-09-12 21:57:57.872456129 +0200 +++ gcc/attribs.c 2017-09-29 11:20:02.163793301 +0200 @@ -1125,9 +1125,9 @@ attribute_value_equal (const_tree attr1, TREE_VALUE (attr2)) == 1); } - if ((flag_openmp || flag_openmp_simd) - && TREE_VALUE (attr1) && TREE_VALUE (attr2) + if (TREE_VALUE (attr1) && TREE_CODE (TREE_VALUE (attr1)) == OMP_CLAUSE + && TREE_VALUE (attr2) && TREE_CODE (TREE_VALUE (attr2)) == OMP_CLAUSE) return omp_declare_simd_clauses_equal (TREE_VALUE (attr1), TREE_VALUE (attr2)); @@ -1319,6 +1319,32 @@ merge_decl_attributes (tree olddecl, tre DECL_ATTRIBUTES (newdecl)); } +/* Duplicate all attributes with name NAME in ATTR list to *ATTRS if + they are missing there. */ + +void +duplicate_one_attribute (tree *attrs, tree attr, const char *name) +{ + attr = lookup_attribute (name, attr); + if (!attr) + return; + tree a = lookup_attribute (name, *attrs); + while (attr) + { + tree a2; + for (a2 = a; a2; a2 = lookup_attribute (name, TREE_CHAIN (a2))) + if (attribute_value_equal (attr, a2)) + break; + if (!a2) + { + a2 = copy_node (attr); + TREE_CHAIN (a2) = *attrs; + *attrs = a2; + } + attr = lookup_attribute (name, TREE_CHAIN (attr)); + } +} + #if TARGET_DLLIMPORT_DECL_ATTRIBUTES /* Specialization of merge_decl_attributes for various Windows targets. --- gcc/attribs.h.jj 2017-09-12 21:57:57.872456129 +0200 +++ gcc/attribs.h 2017-09-29 11:19:27.965206860 +0200 @@ -77,6 +77,11 @@ extern tree remove_attribute (const char extern tree merge_attributes (tree, tree); +/* Duplicate all attributes with name NAME in ATTR list to *ATTRS if + they are missing there. */ + +extern void duplicate_one_attribute (tree *, tree, const char *); + /* Given two Windows decl attributes lists, possibly including dllimport, return a list of their union . */ extern tree merge_dllimport_decl_attributes (tree, tree); --- gcc/c/c-decl.c.jj 2017-09-29 09:57:12.582423577 +0200 +++ gcc/c/c-decl.c 2017-09-29 11:21:17.525881957 +0200 @@ -2569,6 +2569,13 @@ merge_decls (tree newdecl, tree olddecl, set_builtin_decl_declared_p (fncode, true); break; } + + tree b + = builtin_decl_explicit (DECL_FUNCTION_CODE (newdecl)); + if (b) + duplicate_one_attribute (&DECL_ATTRIBUTES (b), + DECL_ATTRIBUTES (newdecl), + "omp declare simd"); } } else --- gcc/cp/decl.c.jj 2017-09-29 09:07:33.530064213 +0200 +++ gcc/cp/decl.c 2017-09-29 11:21:55.618421309 +0200 @@ -2470,6 +2470,12 @@ next_arg:; break; } } + + tree b = builtin_decl_explicit (DECL_FUNCTION_CODE (newdecl)); + if (b) + duplicate_one_attribute (&DECL_ATTRIBUTES (b), + DECL_ATTRIBUTES (newdecl), + "omp declare simd"); } if (new_defines_function) /* If defining a function declared with other language --- gcc/testsuite/gcc.target/i386/pr81706.c.jj 2017-09-29 11:19:27.971206787 +0200 +++ gcc/testsuite/gcc.target/i386/pr81706.c 2017-09-29 11:19:27.971206787 +0200 @@ -0,0 +1,32 @@ +/* PR libstdc++/81706 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -mavx2 -mno-avx512f" } */ +/* { dg-final { scan-assembler "call\[^\n\r]_ZGVdN4v_cos" } } */ +/* { dg-final { scan-assembler "call\[^\n\r]_ZGVdN4v_sin" } } */ + +#ifdef __cplusplus +extern "C" { +#endif +extern double cos (double) __attribute__ ((nothrow, leaf, simd ("notinbranch"))); +extern double sin (double) __attribute__ ((nothrow, leaf, simd ("notinbranch"))); +#ifdef __cplusplus +} +#endif +double p[1024] = { 1.0 }; +double q[1024] = { 1.0 }; + +void +foo (void) +{ + int i; + for (i = 0; i < 1024; i++) + p[i] = cos (q[i]); +} + +void +bar (void) +{ + int i; + for (i = 0; i < 1024; i++) + p[i] = __builtin_sin (q[i]); +} --- gcc/testsuite/g++.dg/ext/pr81706.C.jj 2017-09-29 11:19:27.972206775 +0200 +++ gcc/testsuite/g++.dg/ext/pr81706.C 2017-09-29 11:19:27.972206775 +0200 @@ -0,0 +1,32 @@ +// PR libstdc++/81706 +// { dg-do compile { target i?86-*-* x86_64-*-* } } +// { dg-options "-O3 -mavx2 -mno-avx512f" } +// { dg-final { scan-assembler "call\[^\n\r]_ZGVdN4v_cos" } } +// { dg-final { scan-assembler "call\[^\n\r]_ZGVdN4v_sin" } } + +#ifdef __cplusplus +extern "C" { +#endif +extern double cos (double) __attribute__ ((nothrow, leaf, simd ("notinbranch"))); +extern double sin (double) __attribute__ ((nothrow, leaf, simd ("notinbranch"))); +#ifdef __cplusplus +} +#endif +double p[1024] = { 1.0 }; +double q[1024] = { 1.0 }; + +void +foo (void) +{ + int i; + for (i = 0; i < 1024; i++) + p[i] = cos (q[i]); +} + +void +bar (void) +{ + int i; + for (i = 0; i < 1024; i++) + p[i] = __builtin_sin (q[i]); +} Jakub