From bc1a75dda26988781847f00cfc5283eb13418106 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Wed, 25 Oct 2017 10:05:58 +0200 Subject: [PATCH] re PR libstdc++/81706 (std::sin vectorization bug) 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, copy_attributes_to_builtin): New functions. * attribs.h (duplicate_one_attribute, copy_attributes_to_builtin): New declarations. * 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. From-SVN: r254069 --- gcc/ChangeLog | 9 ++++++ gcc/attribs.c | 42 +++++++++++++++++++++++-- gcc/attribs.h | 10 ++++++ gcc/c/ChangeLog | 6 ++++ gcc/c/c-decl.c | 2 ++ gcc/cp/ChangeLog | 6 ++++ gcc/cp/decl.c | 2 ++ gcc/testsuite/ChangeLog | 6 ++++ gcc/testsuite/g++.dg/ext/pr81706.C | 32 +++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr81706.c | 32 +++++++++++++++++++ 10 files changed, 145 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/pr81706.C create mode 100644 gcc/testsuite/gcc.target/i386/pr81706.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 9b749af5e66..783515917e6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2017-10-25 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, copy_attributes_to_builtin): New functions. + * attribs.h (duplicate_one_attribute, copy_attributes_to_builtin): New + declarations. + 2017-10-25 Richard Biener * tree-ssa-pre.c (need_eh_cleanup, need_ab_cleanup, el_to_remove, diff --git a/gcc/attribs.c b/gcc/attribs.c index ed76a8dab6f..809f4c3a8d5 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -1125,9 +1125,9 @@ attribute_value_equal (const_tree attr1, const_tree attr2) 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)); @@ -1322,6 +1322,44 @@ merge_decl_attributes (tree olddecl, tree newdecl) 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)); + } +} + +/* Duplicate all attributes from user DECL to the corresponding + builtin that should be propagated. */ + +void +copy_attributes_to_builtin (tree decl) +{ + tree b = builtin_decl_explicit (DECL_FUNCTION_CODE (decl)); + if (b) + duplicate_one_attribute (&DECL_ATTRIBUTES (b), + DECL_ATTRIBUTES (decl), "omp declare simd"); +} + #if TARGET_DLLIMPORT_DECL_ATTRIBUTES /* Specialization of merge_decl_attributes for various Windows targets. diff --git a/gcc/attribs.h b/gcc/attribs.h index 65e002ce988..f4bfe03e467 100644 --- a/gcc/attribs.h +++ b/gcc/attribs.h @@ -77,6 +77,16 @@ extern tree remove_attribute (const char *, tree); 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 *); + +/* Duplicate all attributes from user DECL to the corresponding + builtin that should be propagated. */ + +extern void copy_attributes_to_builtin (tree); + /* Given two Windows decl attributes lists, possibly including dllimport, return a list of their union . */ extern tree merge_dllimport_decl_attributes (tree, tree); diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index c260f62b111..b4fde0dccf7 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,9 @@ +2017-10-25 Jakub Jelinek + + PR libstdc++/81706 + * c-decl.c (merge_decls): Copy "omp declare simd" attributes from + newdecl to corresponding __builtin_ if any. + 2017-10-24 Paolo Carlini PR c++/82466 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 5c472e66af8..90f07297a37 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -2570,6 +2570,8 @@ merge_decls (tree newdecl, tree olddecl, tree newtype, tree oldtype) set_builtin_decl_declared_p (fncode, true); break; } + + copy_attributes_to_builtin (newdecl); } } else diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 8c587a3e845..fdb2c9b52a8 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2017-10-25 Jakub Jelinek + + PR libstdc++/81706 + * decl.c (duplicate_decls): Copy "omp declare simd" attributes from + newdecl to corresponding __builtin_ if any. + 2017-10-24 Paolo Carlini PR c++/82466 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index bb48099da56..c9c3d0a2711 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -2478,6 +2478,8 @@ next_arg:; break; } } + + copy_attributes_to_builtin (newdecl); } if (new_defines_function) /* If defining a function declared with other language diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8dbf3b5604d..00dde9f9d6d 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2017-10-25 Jakub Jelinek + + PR libstdc++/81706 + * gcc.target/i386/pr81706.c: New test. + * g++.dg/ext/pr81706.C: New test. + 2017-10-24 Jakub Jelinek PR target/82460 diff --git a/gcc/testsuite/g++.dg/ext/pr81706.C b/gcc/testsuite/g++.dg/ext/pr81706.C new file mode 100644 index 00000000000..f0ed8ab6d71 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/pr81706.C @@ -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]); +} diff --git a/gcc/testsuite/gcc.target/i386/pr81706.c b/gcc/testsuite/gcc.target/i386/pr81706.c new file mode 100644 index 00000000000..333fd159770 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr81706.c @@ -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]); +} -- 2.30.2