public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/95778] New: target_clones indirection eliminates requires noinline
@ 2020-06-20  5:16 yyc1992 at gmail dot com
  2020-06-20 15:48 ` [Bug other/95778] " yyc1992 at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: yyc1992 at gmail dot com @ 2020-06-20  5:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95778

            Bug ID: 95778
           Summary: target_clones indirection eliminates requires noinline
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yyc1992 at gmail dot com
  Target Milestone: ---

Compiling

```
static __attribute__((noinline,target_clones("default,avx2"))) int f2(int *p)
{
    asm volatile ("" :: "r"(p) : "memory");
    return *p;
}

__attribute__((target_clones("default,avx2"))) int g2(int *p)
{
    return f2(p);
}
```

with `-fPIC -O3` generates


```
g2.avx2.0:
        jmp     f2.avx2.0
```

However, if any of the two `noinline` is removed, the generated code becomes,

```
g2.avx2.0:
        jmp     f2@PLT
```

which cannot get eliminated later
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95776

I think this should be possible to do and should be possible without LTO (hence
a slightly different bug than
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95776 even though if that one is
fixed turning on LTO can particially fix this).

Also, in this case, the `f2` should be inlinable to `g2`. However, no
combination of `inline`, `always_inline`, `flatten` I've tested can do that,
even though when both functions are marked with `noinline` gcc clearly knows
which function is calling what so it should have no problem inlining.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug other/95778] target_clones indirection eliminates requires noinline
  2020-06-20  5:16 [Bug other/95778] New: target_clones indirection eliminates requires noinline yyc1992 at gmail dot com
@ 2020-06-20 15:48 ` yyc1992 at gmail dot com
  2020-06-20 15:49 ` yyc1992 at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: yyc1992 at gmail dot com @ 2020-06-20 15:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95778

--- Comment #1 from Yichao Yu <yyc1992 at gmail dot com> ---
Ah, I think this might be the fix for both this issue and
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95780 . I'll test more and will
try to submit it later.

```
diff --git a/gcc/multiple_target.c b/gcc/multiple_target.c
index c1cfe8ff978..79a4c87545f 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 (!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 (attribute_value_equal (attr_target, attr_target2))
                {
                  e->redirect_callee (callee);
                  cgraph_edge::redirect_call_stmt_to_callee (e);
```

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug other/95778] target_clones indirection eliminates requires noinline
  2020-06-20  5:16 [Bug other/95778] New: target_clones indirection eliminates requires noinline yyc1992 at gmail dot com
  2020-06-20 15:48 ` [Bug other/95778] " yyc1992 at gmail dot com
@ 2020-06-20 15:49 ` yyc1992 at gmail dot com
  2020-06-20 19:08 ` hjl.tools at gmail dot com
  2020-06-20 19:14 ` yyc1992 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: yyc1992 at gmail dot com @ 2020-06-20 15:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95778

--- Comment #2 from Yichao Yu <yyc1992 at gmail dot com> ---
Also, the original code example had an error, the code that works properly was

```
static __attribute__((noinline,target_clones("default,avx2"))) int f2(int *p)
{
    asm volatile ("" :: "r"(p) : "memory");
    return *p;
}

__attribute__((noinline,target_clones("default,avx2"))) int g2(int *p)
{
    return f2(p);
}
```

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug other/95778] target_clones indirection eliminates requires noinline
  2020-06-20  5:16 [Bug other/95778] New: target_clones indirection eliminates requires noinline yyc1992 at gmail dot com
  2020-06-20 15:48 ` [Bug other/95778] " yyc1992 at gmail dot com
  2020-06-20 15:49 ` yyc1992 at gmail dot com
@ 2020-06-20 19:08 ` hjl.tools at gmail dot com
  2020-06-20 19:14 ` yyc1992 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: hjl.tools at gmail dot com @ 2020-06-20 19:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95778

--- Comment #3 from H.J. Lu <hjl.tools at gmail dot com> ---
*** Bug 95780 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug other/95778] target_clones indirection eliminates requires noinline
  2020-06-20  5:16 [Bug other/95778] New: target_clones indirection eliminates requires noinline yyc1992 at gmail dot com
                   ` (2 preceding siblings ...)
  2020-06-20 19:08 ` hjl.tools at gmail dot com
@ 2020-06-20 19:14 ` yyc1992 at gmail dot com
  3 siblings, 0 replies; 5+ messages in thread
From: yyc1992 at gmail dot com @ 2020-06-20 19:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95778

--- Comment #4 from Yichao Yu <yyc1992 at gmail dot com> ---
Yeah, after digging further the two issue are indeed the same. I initially
didn't think they are since I didn't realize PR95786 (that the visibility
attribute is simply ignored completely...) and thought static was handled
specially....

It also seems that when target attribute is used directly the inlining can
work. Maybe a pass order issue? and that's certainly a different issue so I'll
file another one if there isn't one already when I have time.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-20 19:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-20  5:16 [Bug other/95778] New: target_clones indirection eliminates requires noinline yyc1992 at gmail dot com
2020-06-20 15:48 ` [Bug other/95778] " yyc1992 at gmail dot com
2020-06-20 15:49 ` yyc1992 at gmail dot com
2020-06-20 19:08 ` hjl.tools at gmail dot com
2020-06-20 19:14 ` yyc1992 at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).