public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/104187] New: Call site specific attribute to control inliner
@ 2022-01-22 16:15 david.bolvansky at gmail dot com
  2022-01-22 17:46 ` [Bug ipa/104187] " pinskia at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: david.bolvansky at gmail dot com @ 2022-01-22 16:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 104187
           Summary: Call site specific attribute to control inliner
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: david.bolvansky at gmail dot com
  Target Milestone: ---

It could be useful to have more control over inlining. Use cases:



int foo();

void bar();

int g; 

void test()
{
 g = __builtin_always_inline(foo()); // force inlining of foo() here
 __builtin_noinline(bar()); // never inline bar to this function
}

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
@ 2022-01-22 17:46 ` pinskia at gcc dot gnu.org
  2022-01-24  7:49 ` marxin at gcc dot gnu.org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-22 17:46 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement
          Component|c                           |ipa

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
  2022-01-22 17:46 ` [Bug ipa/104187] " pinskia at gcc dot gnu.org
@ 2022-01-24  7:49 ` marxin at gcc dot gnu.org
  2022-01-24  9:13 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: marxin at gcc dot gnu.org @ 2022-01-24  7:49 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2022-01-24
     Ever confirmed|0                           |1

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
  2022-01-22 17:46 ` [Bug ipa/104187] " pinskia at gcc dot gnu.org
  2022-01-24  7:49 ` marxin at gcc dot gnu.org
@ 2022-01-24  9:13 ` rguenth at gcc dot gnu.org
  2022-01-24  9:19 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-01-24  9:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.  For C++ an attribute on the call stmt might work even better.

Note we're low on bits to represent this on the GENERIC CALL_EXPR and
the GIMPLE gcall.

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
                   ` (2 preceding siblings ...)
  2022-01-24  9:13 ` rguenth at gcc dot gnu.org
@ 2022-01-24  9:19 ` pinskia at gcc dot gnu.org
  2022-01-24 10:18 ` hubicka at kam dot mff.cuni.cz
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-24  9:19 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> Confirmed.  For C++ an attribute on the call stmt might work even better.

I think even C, it might be better too. [[]] syntax is there for GNU C now too.
But those only apply to the full statement and not just a subset of one ...

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
                   ` (3 preceding siblings ...)
  2022-01-24  9:19 ` pinskia at gcc dot gnu.org
@ 2022-01-24 10:18 ` hubicka at kam dot mff.cuni.cz
  2022-01-24 22:35 ` joseph at codesourcery dot com
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: hubicka at kam dot mff.cuni.cz @ 2022-01-24 10:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from hubicka at kam dot mff.cuni.cz ---
> > Confirmed.  For C++ an attribute on the call stmt might work even better.
> 
> I think even C, it might be better too. [[]] syntax is there for GNU C now too.
> But those only apply to the full statement and not just a subset of one ...
I agree it is quite desirable thing to have

Implementaiton on the inliner side is quite easy: all we need to do is
to detect the attribute and put it into the inline summary and then
handle it same way as always_inline.

However what is the way to add the attribute to front-ends and get it
attached to the gimple call statement?

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
                   ` (4 preceding siblings ...)
  2022-01-24 10:18 ` hubicka at kam dot mff.cuni.cz
@ 2022-01-24 22:35 ` joseph at codesourcery dot com
  2022-01-25 20:30 ` david.bolvansky at gmail dot com
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: joseph at codesourcery dot com @ 2022-01-24 22:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from joseph at codesourcery dot com <joseph at codesourcery dot com> ---
Right now, all the C front end does with statement attributes is parses 
them and then passes them to c_warn_unused_attributes; it doesn't have any 
other handling for such attributes.

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
                   ` (5 preceding siblings ...)
  2022-01-24 22:35 ` joseph at codesourcery dot com
@ 2022-01-25 20:30 ` david.bolvansky at gmail dot com
  2022-01-26 13:22 ` hubicka at gcc dot gnu.org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: david.bolvansky at gmail dot com @ 2022-01-25 20:30 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Dávid Bolvanský <david.bolvansky at gmail dot com> ---
So you prefer eg.

g = a[i] - [[gnu::always_inline]] foo(x, y) + 2 * bar();

over

g = a[i] - __builtin_always_inline(foo(x, y)) + 2 * bar();

?

What is your proposed syntax?

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
                   ` (6 preceding siblings ...)
  2022-01-25 20:30 ` david.bolvansky at gmail dot com
@ 2022-01-26 13:22 ` hubicka at gcc dot gnu.org
  2022-02-10 13:02 ` aaron at aaronballman dot com
  2022-03-03 10:23 ` david.bolvansky at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: hubicka at gcc dot gnu.org @ 2022-01-26 13:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
For Gimple representation __builtin_always_inline(foo(x, y))
does not make very good sense since gimple is not nested and foo may return
void so there may not be any link between call and the builtin.

I see that llvm has something like this
https://reviews.llvm.org/D51200
(or at least it was proposed), but I think in our setting it would be more
natural to have flag in the gimple call statement or some generic way to attach
attributes to statements like we attach histograms.

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
                   ` (7 preceding siblings ...)
  2022-01-26 13:22 ` hubicka at gcc dot gnu.org
@ 2022-02-10 13:02 ` aaron at aaronballman dot com
  2022-03-03 10:23 ` david.bolvansky at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: aaron at aaronballman dot com @ 2022-02-10 13:02 UTC (permalink / raw)
  To: gcc-bugs

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

Aaron Ballman <aaron at aaronballman dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aaron at aaronballman dot com

--- Comment #7 from Aaron Ballman <aaron at aaronballman dot com> ---
(In reply to Dávid Bolvanský from comment #5)
> So you prefer eg.
> 
> g = a[i] - [[gnu::always_inline]] foo(x, y) + 2 * bar();

To be clear, this syntax isn't valid in either C or C++. There are
statement-level attributes, there are not expression-level attributes.

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

* [Bug ipa/104187] Call site specific attribute to control inliner
  2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
                   ` (8 preceding siblings ...)
  2022-02-10 13:02 ` aaron at aaronballman dot com
@ 2022-03-03 10:23 ` david.bolvansky at gmail dot com
  9 siblings, 0 replies; 11+ messages in thread
From: david.bolvansky at gmail dot com @ 2022-03-03 10:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Dávid Bolvanský <david.bolvansky at gmail dot com> ---
So this works in Clang now

int foo(int x, int y) { // any compiler will happily inline this function
    return x / y;
}

int test(int x, int y) {
    int r = 0;
    [[clang::noinline]] r += foo(x, y); // for some reason we don't want any
inlining here
    return r;
}


foo(int, int): # @foo(int, int)
  mov eax, edi
  cdq
  idiv esi
  ret
test(int, int): # @test(int, int)
  jmp foo(int, int) # TAILCALL

foo(int, int): # @foo(int, int)
  mov eax, edi
  cdq
  idiv esi
  ret
test(int, int): # @test(int, int)
  jmp foo(int, int) # TAILCALL

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

end of thread, other threads:[~2022-03-03 10:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-22 16:15 [Bug c/104187] New: Call site specific attribute to control inliner david.bolvansky at gmail dot com
2022-01-22 17:46 ` [Bug ipa/104187] " pinskia at gcc dot gnu.org
2022-01-24  7:49 ` marxin at gcc dot gnu.org
2022-01-24  9:13 ` rguenth at gcc dot gnu.org
2022-01-24  9:19 ` pinskia at gcc dot gnu.org
2022-01-24 10:18 ` hubicka at kam dot mff.cuni.cz
2022-01-24 22:35 ` joseph at codesourcery dot com
2022-01-25 20:30 ` david.bolvansky at gmail dot com
2022-01-26 13:22 ` hubicka at gcc dot gnu.org
2022-02-10 13:02 ` aaron at aaronballman dot com
2022-03-03 10:23 ` david.bolvansky 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).