Message ID | 20240502140246.674422-1-jason@redhat.com |
---|---|
State | New |
Headers | show |
Series | [RFA,(cgraph)] c++: pragma target and static init [PR109753] | expand |
Ping On 5/2/24 09:54, Jason Merrill wrote: > Tested x86_64-pc-linux-gnu, OK for trunk? 14.2? > > This two-year-old thread seems relevant: > https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593410.html > > -- 8< -- > > #pragma target and optimize should also apply to implicitly-generated > functions like static initialization functions and defaulted special member > functions. > > At least one of the create_same_body_alias/handle_optimize_attribute changes > is necessary to avoid regressing g++.dg/opt/pr105306.C; maybe_clone_body > creates a cgraph_node for the ~B alias before handle_optimize_attribute, and > the alias never goes through finalize_function, so we need to adjust > semantic_interposition somewhere else. > > PR c++/109753 > > gcc/ChangeLog: > > * cgraph.cc (cgraph_node::create_same_body_alias): Set > semantic_interposition. > > gcc/c-family/ChangeLog: > > * c-attribs.cc (handle_optimize_attribute): Set > cgraph_node::semantic_interposition. > > gcc/cp/ChangeLog: > > * decl.cc (start_preparsed_function): Call decl_attributes. > > gcc/testsuite/ChangeLog: > > * g++.dg/opt/always_inline1.C: New test. > --- > gcc/c-family/c-attribs.cc | 4 ++++ > gcc/cgraph.cc | 2 ++ > gcc/cp/decl.cc | 3 +++ > gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++ > 4 files changed, 17 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/opt/always_inline1.C > > diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc > index 04e39b41bdf..605469dd7dd 100644 > --- a/gcc/c-family/c-attribs.cc > +++ b/gcc/c-family/c-attribs.cc > @@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree name, tree args, > if (prev_target_node != target_node) > DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node; > > + /* Also update the cgraph_node, if it's already built. */ > + if (cgraph_node *cn = cgraph_node::get (*node)) > + cn->semantic_interposition = flag_semantic_interposition; > + > /* Restore current options. */ > cl_optimization_restore (&global_options, &global_options_set, > &cur_opts); > diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc > index 473d8410bc9..f3bd2fa8ece 100644 > --- a/gcc/cgraph.cc > +++ b/gcc/cgraph.cc > @@ -604,6 +604,8 @@ cgraph_node::create_same_body_alias (tree alias, tree decl) > > n = cgraph_node::create_alias (alias, decl); > n->cpp_implicit_alias = true; > + /* Aliases don't go through finalize_function. */ > + n->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition); > if (symtab->cpp_implicit_aliases_done) > n->resolve_alias (cgraph_node::get (decl)); > return n; > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index 378311c0f04..4531d830462 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -17796,6 +17796,9 @@ start_preparsed_function (tree decl1, tree attrs, int flags) > doing_friend = true; > } > > + /* Adjust for #pragma target/optimize. */ > + decl_attributes (&decl1, NULL_TREE, 0); > + > if (DECL_DECLARED_INLINE_P (decl1) > && lookup_attribute ("noinline", attrs)) > warning_at (DECL_SOURCE_LOCATION (decl1), 0, > diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C b/gcc/testsuite/g++.dg/opt/always_inline1.C > new file mode 100644 > index 00000000000..a042a1cf0c6 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/opt/always_inline1.C > @@ -0,0 +1,8 @@ > +// PR c++/109753 > +// { dg-do compile { target x86_64-*-* } } > + > +#pragma GCC target("avx2") > +struct aa { > + __attribute__((__always_inline__)) aa() {} > +}; > +aa _M_impl; > > base-commit: 2f15787f2e1a3afe2c2ad93d4eb0d3c1f73c8fbd
Ping On 5/14/24 17:21, Jason Merrill wrote: > Ping > > On 5/2/24 09:54, Jason Merrill wrote: >> Tested x86_64-pc-linux-gnu, OK for trunk? 14.2? >> >> This two-year-old thread seems relevant: >> https://gcc.gnu.org/pipermail/gcc-patches/2022-April/593410.html >> >> -- 8< -- >> >> #pragma target and optimize should also apply to implicitly-generated >> functions like static initialization functions and defaulted special >> member >> functions. >> >> At least one of the create_same_body_alias/handle_optimize_attribute >> changes >> is necessary to avoid regressing g++.dg/opt/pr105306.C; maybe_clone_body >> creates a cgraph_node for the ~B alias before >> handle_optimize_attribute, and >> the alias never goes through finalize_function, so we need to adjust >> semantic_interposition somewhere else. >> >> PR c++/109753 >> >> gcc/ChangeLog: >> >> * cgraph.cc (cgraph_node::create_same_body_alias): Set >> semantic_interposition. >> >> gcc/c-family/ChangeLog: >> >> * c-attribs.cc (handle_optimize_attribute): Set >> cgraph_node::semantic_interposition. >> >> gcc/cp/ChangeLog: >> >> * decl.cc (start_preparsed_function): Call decl_attributes. >> >> gcc/testsuite/ChangeLog: >> >> * g++.dg/opt/always_inline1.C: New test. >> --- >> gcc/c-family/c-attribs.cc | 4 ++++ >> gcc/cgraph.cc | 2 ++ >> gcc/cp/decl.cc | 3 +++ >> gcc/testsuite/g++.dg/opt/always_inline1.C | 8 ++++++++ >> 4 files changed, 17 insertions(+) >> create mode 100644 gcc/testsuite/g++.dg/opt/always_inline1.C >> >> diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc >> index 04e39b41bdf..605469dd7dd 100644 >> --- a/gcc/c-family/c-attribs.cc >> +++ b/gcc/c-family/c-attribs.cc >> @@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree >> name, tree args, >> if (prev_target_node != target_node) >> DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node; >> + /* Also update the cgraph_node, if it's already built. */ >> + if (cgraph_node *cn = cgraph_node::get (*node)) >> + cn->semantic_interposition = flag_semantic_interposition; >> + >> /* Restore current options. */ >> cl_optimization_restore (&global_options, &global_options_set, >> &cur_opts); >> diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc >> index 473d8410bc9..f3bd2fa8ece 100644 >> --- a/gcc/cgraph.cc >> +++ b/gcc/cgraph.cc >> @@ -604,6 +604,8 @@ cgraph_node::create_same_body_alias (tree alias, >> tree decl) >> n = cgraph_node::create_alias (alias, decl); >> n->cpp_implicit_alias = true; >> + /* Aliases don't go through finalize_function. */ >> + n->semantic_interposition = opt_for_fn (decl, >> flag_semantic_interposition); >> if (symtab->cpp_implicit_aliases_done) >> n->resolve_alias (cgraph_node::get (decl)); >> return n; >> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc >> index 378311c0f04..4531d830462 100644 >> --- a/gcc/cp/decl.cc >> +++ b/gcc/cp/decl.cc >> @@ -17796,6 +17796,9 @@ start_preparsed_function (tree decl1, tree >> attrs, int flags) >> doing_friend = true; >> } >> + /* Adjust for #pragma target/optimize. */ >> + decl_attributes (&decl1, NULL_TREE, 0); >> + >> if (DECL_DECLARED_INLINE_P (decl1) >> && lookup_attribute ("noinline", attrs)) >> warning_at (DECL_SOURCE_LOCATION (decl1), 0, >> diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C >> b/gcc/testsuite/g++.dg/opt/always_inline1.C >> new file mode 100644 >> index 00000000000..a042a1cf0c6 >> --- /dev/null >> +++ b/gcc/testsuite/g++.dg/opt/always_inline1.C >> @@ -0,0 +1,8 @@ >> +// PR c++/109753 >> +// { dg-do compile { target x86_64-*-* } } >> + >> +#pragma GCC target("avx2") >> +struct aa { >> + __attribute__((__always_inline__)) aa() {} >> +}; >> +aa _M_impl; >> >> base-commit: 2f15787f2e1a3afe2c2ad93d4eb0d3c1f73c8fbd >
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc index 04e39b41bdf..605469dd7dd 100644 --- a/gcc/c-family/c-attribs.cc +++ b/gcc/c-family/c-attribs.cc @@ -5971,6 +5971,10 @@ handle_optimize_attribute (tree *node, tree name, tree args, if (prev_target_node != target_node) DECL_FUNCTION_SPECIFIC_TARGET (*node) = target_node; + /* Also update the cgraph_node, if it's already built. */ + if (cgraph_node *cn = cgraph_node::get (*node)) + cn->semantic_interposition = flag_semantic_interposition; + /* Restore current options. */ cl_optimization_restore (&global_options, &global_options_set, &cur_opts); diff --git a/gcc/cgraph.cc b/gcc/cgraph.cc index 473d8410bc9..f3bd2fa8ece 100644 --- a/gcc/cgraph.cc +++ b/gcc/cgraph.cc @@ -604,6 +604,8 @@ cgraph_node::create_same_body_alias (tree alias, tree decl) n = cgraph_node::create_alias (alias, decl); n->cpp_implicit_alias = true; + /* Aliases don't go through finalize_function. */ + n->semantic_interposition = opt_for_fn (decl, flag_semantic_interposition); if (symtab->cpp_implicit_aliases_done) n->resolve_alias (cgraph_node::get (decl)); return n; diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 378311c0f04..4531d830462 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -17796,6 +17796,9 @@ start_preparsed_function (tree decl1, tree attrs, int flags) doing_friend = true; } + /* Adjust for #pragma target/optimize. */ + decl_attributes (&decl1, NULL_TREE, 0); + if (DECL_DECLARED_INLINE_P (decl1) && lookup_attribute ("noinline", attrs)) warning_at (DECL_SOURCE_LOCATION (decl1), 0, diff --git a/gcc/testsuite/g++.dg/opt/always_inline1.C b/gcc/testsuite/g++.dg/opt/always_inline1.C new file mode 100644 index 00000000000..a042a1cf0c6 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/always_inline1.C @@ -0,0 +1,8 @@ +// PR c++/109753 +// { dg-do compile { target x86_64-*-* } } + +#pragma GCC target("avx2") +struct aa { + __attribute__((__always_inline__)) aa() {} +}; +aa _M_impl;