public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/23769] New: always inline short functions if inlining would be as small as non-inlined code
@ 2005-09-07 19:11 ash at onezero dot org
  2005-09-07 19:14 ` [Bug middle-end/23769] " pinskia at gcc dot gnu dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: ash at onezero dot org @ 2005-09-07 19:11 UTC (permalink / raw)
  To: gcc-bugs

I noticed when compiling with gcc -std=c99 -Winline that this function

  inline uint16_t f(uint16_t x)  {  return x;  }

wasn't getting inlined.  Inlining is also not done even when the function is 
attributed with "__attribute__ ((always_inline))", nor does inlining happen 
when there no attributes at all.  Maybe this function isn't getting inlined 
because the compiler decided that it would involve in some sense "too much" 
expansion in the caller.

Regardless of this particular case, I wonder if the following enhancement to 
gcc would be worthwhile: always inline when it can be deduced that the code 
with inlining would be no larger than the code without inlining, regardless of 
the size of the caller in whatever representation is used at the time this 
decision is being made.

For example, on many architectures, a call to a function that accepts an 
argument and returns a value will use at least 3 instructions in the caller: 
one to push the argument onto the stack, one to call the function, and one to 
retrieve the return value from the function.  So, if the function uses up to 
three instructions to do its calculation, plus a return statement (with no 
calculation in the return), then inlining will use no more instruction space 
than not inlining.  In these cases, inlining probably ought to be done so as to 
create opportunities for further optimizations later, e.g., common 
subexpression elimination.  A more sophisticated determination could take into 
account the number of arguments and other factors.  This might be especially 
helpful with C++ programs that have a lot of short methods.

At least, this is how it looks to me - if I am wrong, maybe someone could 
educate me a bit or point me to some documentation where I can learn more about 
how gcc's inlining works.  If inlining is supposed to work this way already, 
then I'll be happy to try to isolate the code further so that we have a small 
fully compilable example.

I'm compiling with this:

gcc -o t.exe -DZCodeTest -g -DZAssert -D__GCC__ -std=c99 -O3 -pedantic -Werror -
Wall -W -I. -Wundef -Wshadow -Wpointer-arith -Wcast-qual -Wbad-function-cast -
Wwrite-strings -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -
Wredundant-decls -Wdisabled-optimization -Winline t.c

-- 
           Summary: always inline short functions if inlining would be as
                    small as non-inlined code
           Product: gcc
           Version: 3.3.1
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ash at onezero dot org
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23769


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

* [Bug middle-end/23769] always inline short functions if inlining would be as small as non-inlined code
  2005-09-07 19:11 [Bug c/23769] New: always inline short functions if inlining would be as small as non-inlined code ash at onezero dot org
@ 2005-09-07 19:14 ` pinskia at gcc dot gnu dot org
  2005-09-07 19:18 ` ash at onezero dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-07 19:14 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-07 19:14 -------
3.3.x is old and does not have the inlining improvements that went into 3.4.x.  You might want to try 
3.4.x or even 4.0.x.  4.1.x (the mainline) has better inlining still.

But without a full testcase, we won't know if this is fixed.  I am thinking it is for 4.0.x or 4.1.x.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c                           |middle-end


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23769


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

* [Bug middle-end/23769] always inline short functions if inlining would be as small as non-inlined code
  2005-09-07 19:11 [Bug c/23769] New: always inline short functions if inlining would be as small as non-inlined code ash at onezero dot org
  2005-09-07 19:14 ` [Bug middle-end/23769] " pinskia at gcc dot gnu dot org
@ 2005-09-07 19:18 ` ash at onezero dot org
  2005-09-07 19:18 ` ash at onezero dot org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: ash at onezero dot org @ 2005-09-07 19:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ash at onezero dot org  2005-09-07 19:18 -------
(Cygwin)

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23769


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

* [Bug middle-end/23769] always inline short functions if inlining would be as small as non-inlined code
  2005-09-07 19:11 [Bug c/23769] New: always inline short functions if inlining would be as small as non-inlined code ash at onezero dot org
  2005-09-07 19:14 ` [Bug middle-end/23769] " pinskia at gcc dot gnu dot org
  2005-09-07 19:18 ` ash at onezero dot org
@ 2005-09-07 19:18 ` ash at onezero dot org
  2005-09-10  2:22 ` pinskia at gcc dot gnu dot org
  2005-09-10  2:33 ` ash at onezero dot org
  4 siblings, 0 replies; 6+ messages in thread
From: ash at onezero dot org @ 2005-09-07 19:18 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ash at onezero dot org  2005-09-07 19:18 -------
I'm on Cywin and couldn't find a later version of gcc - is there one somewhere 
that I can use?

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23769


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

* [Bug middle-end/23769] always inline short functions if inlining would be as small as non-inlined code
  2005-09-07 19:11 [Bug c/23769] New: always inline short functions if inlining would be as small as non-inlined code ash at onezero dot org
                   ` (2 preceding siblings ...)
  2005-09-07 19:18 ` ash at onezero dot org
@ 2005-09-10  2:22 ` pinskia at gcc dot gnu dot org
  2005-09-10  2:33 ` ash at onezero dot org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-10  2:22 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-10 02:22 -------
(In reply to comment #2)
> I'm on Cywin and couldn't find a later version of gcc - is there one somewhere 
> that I can use?

Either you can compile one or I think cygwin has a couple of versions of GCC you can install.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pinskia at gcc dot gnu dot
                   |                            |org
             Status|UNCONFIRMED                 |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23769


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

* [Bug middle-end/23769] always inline short functions if inlining would be as small as non-inlined code
  2005-09-07 19:11 [Bug c/23769] New: always inline short functions if inlining would be as small as non-inlined code ash at onezero dot org
                   ` (3 preceding siblings ...)
  2005-09-10  2:22 ` pinskia at gcc dot gnu dot org
@ 2005-09-10  2:33 ` ash at onezero dot org
  4 siblings, 0 replies; 6+ messages in thread
From: ash at onezero dot org @ 2005-09-10  2:33 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ash at onezero dot org  2005-09-10 02:33 -------
Yes, I'm running the most recent one of those.  The discussion in the cygwin 
lists does not make it appear that it is easy to compile and install gcc.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23769


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

end of thread, other threads:[~2005-09-10  2:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-07 19:11 [Bug c/23769] New: always inline short functions if inlining would be as small as non-inlined code ash at onezero dot org
2005-09-07 19:14 ` [Bug middle-end/23769] " pinskia at gcc dot gnu dot org
2005-09-07 19:18 ` ash at onezero dot org
2005-09-07 19:18 ` ash at onezero dot org
2005-09-10  2:22 ` pinskia at gcc dot gnu dot org
2005-09-10  2:33 ` ash at onezero dot org

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).