> https://github.com/gcc-mirror/gcc/commit/b8ce8129a560f64f8b2855c4a3812b7c3c0ebf3f#diff-e2d535917af8555baad2e9c8749e96a5 > with/adding to the test the following one should work. I still > couldn't get test to run though......
And yet another related issue that I think I would appreciate some help on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95790 . For `target_clones` usage I can probably just check that the target_clones attribute matches but I'm not sure how to get the list of targets for the function when the target attribute is used directly. Another issue that I've noticed but haven't really debugged yet is that this elimination doesn't work when target_clones and target are mixed even in the case where the two generate basically identical code without this optimization. > > ``` > /* { dg-do compile } */ > /* { dg-require-ifunc "" } */ > /* { dg-options "-O2 -fdump-tree-optimized" } */ > > __attribute__ ((flatten,target ("default"),cold)) > static unsigned foo(const char *buf, unsigned size) { > return 1; > } > > __attribute__ ((flatten,target ("avx"),cold)) > static unsigned foo(const char *buf, unsigned size) { > return 2; > } > > __attribute__ ((target ("default"))) > unsigned bar() { > char buf[4096]; > unsigned acc = 0; > for (int i = 0; i < sizeof(buf); i++) { > acc += foo(&buf[i], 1); > } > return acc; > } > > __attribute__ ((target ("avx"))) > unsigned bar() { > char buf[4096]; > unsigned acc = 0; > for (int i = 0; i < sizeof(buf); i++) { > acc += foo(&buf[i], 1); > } > return acc; > } > > /* { dg-final { scan-tree-dump-times "return 4096;" 1 "optimized" } } */ > /* { dg-final { scan-tree-dump-times "return 8192;" 1 "optimized" } } */ > ``` > > > > > Yes it at least partially fixes them. As mentioned in the other email, > > this still does not allow inlining but maybe that should be reported > > as another issue? > > > > I need to work on the test and might need some help. > > Right now I'm not sure how to write such a test (I assume blaming on > > the old implementation should tell me where the right test is though). > > Also, make -k check somehow gives me some segfaults from LLVM. I was > > wondering if it is related to that I was using an out-of-tree non > > bootstrap build so I'm recompiling a bootstrap in-source build... > > > > > > > > > This changes the comparison to be only on the `target` attribute which > > > > should be > > > > the intent of the code. > > > > --- > > > > gcc/multiple_target.c | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c > > > > index c1cfe8ff978..9eb0afd58cc 100644 > > > > --- a/gcc/multiple_target.c > > > > +++ b/gcc/multiple_target.c > > > > @@ -483,7 +483,7 @@ redirect_to_specific_clone (cgraph_node *node) > > > > DECL_ATTRIBUTES > > > > (e->callee->decl)); > > > > > > > > /* Function is not calling proper target clone. */ > > > > - if (!attribute_list_equal (attr_target, attr_target2)) > > > > + if (attr_target2 == NULL_TREE || !attribute_value_equal > > > > (attr_target, attr_target2)) > > > > { > > > > while (fv2->prev != NULL) > > > > fv2 = fv2->prev; > > > > @@ -494,7 +494,7 @@ redirect_to_specific_clone (cgraph_node *node) > > > > cgraph_node *callee = fv2->this_node; > > > > attr_target2 = lookup_attribute ("target", > > > > DECL_ATTRIBUTES > > > > (callee->decl)); > > > > - if (attribute_list_equal (attr_target, attr_target2)) > > > > + if (attr_target2 != NULL_TREE && attribute_value_equal > > > > (attr_target, attr_target2)) > > > > { > > > > e->redirect_callee (callee); > > > > cgraph_edge::redirect_call_stmt_to_callee (e); > > > > -- > > > > 2.27.0 > > > > > > > > > > > > > -- > > > H.J.