public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21690] New: gcc misses trivial optimizations ?
@ 2005-05-21  0:24 TazForEver at dlfp dot org
  2005-05-21  0:32 ` [Bug tree-optimization/21690] gcc misses trivial optimizations pinskia at gcc dot gnu dot org
  2005-05-21  0:32 ` pinskia at gcc dot gnu dot org
  0 siblings, 2 replies; 5+ messages in thread
From: TazForEver at dlfp dot org @ 2005-05-21  0:24 UTC (permalink / raw)
  To: gcc-bugs

hi, i'm using Debian SID experimental gcc-4.0

gcc-4.0 -v
Using built-in specs.
Target: powerpc-linux
Configured with: ../src/configure -v
--enable-languages=c,c++,java,f95,objc,ada,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib --enable-nls
--without-included-gettext --enable-threads=posix --program-suffix=-4.0
--enable-__cxa_atexit --enable-libstdcxx-allocator=mt --enable-clocale=gnu
--enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk
--enable-mpfr --disable-multilib --disable-werror --enable-checking=release
powerpc-linux
Thread model: posix
gcc version 4.0.1 20050508 (prerelease) (Debian 4.0.0-6)



i'm compiling the following simple code :

BEGIN_CODE

void
foo(void*);

static inline char*
bar(char * const p)
{
	foo(p);
	return p;
}

unsigned long
baz(char * const p)
{
	return (unsigned long)(bar(p+1) - bar(p));
}

END_CODE

it's obvious that baz(...) == 1. But gcc outputs the following (gcc -O3 -S -Wall
foo.c)

BEGIN_CODE

baz:
        stwu 1,-32(1)
        mflr 0
        stw 28,16(1)
        addi 28,3,1
        stw 29,20(1)
        mr 29,3
        mr 3,28
        stw 0,36(1)
        bl foo
        mr 3,29
        bl foo
        lwz 0,36(1)
        subf 3,29,28
        lwz 28,16(1)
        lwz 29,20(1)
        mtlr 0
        addi 1,1,32
        blr

END_CODE

if i remove the call foo(p) in function bar, gcc outputs

BEGIN_CODE

baz:
        li 3,1
        blr
        
END_CODE


I would have expect gcc to output the same trivial code in both cases.

Now,

addi 28,3,1
...
mr 29,3
mr 3,28
...
mr 3,29
...
subf 3,29,28

is a complex way to get 1.

Why gcc is not able to optimize this kind of code ?
gcc-2.95, gcc-3.3 and gcc-4.0 output the same result.

Thank you.

-- 
           Summary: gcc misses trivial optimizations ?
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: TazForEver at dlfp dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


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

* [Bug tree-optimization/21690] gcc misses trivial optimizations
  2005-05-21  0:24 [Bug c/21690] New: gcc misses trivial optimizations ? TazForEver at dlfp dot org
  2005-05-21  0:32 ` [Bug tree-optimization/21690] gcc misses trivial optimizations pinskia at gcc dot gnu dot org
@ 2005-05-21  0:32 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-21  0:32 UTC (permalink / raw)
  To: gcc-bugs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2005-05-21 00:32:28
               date|                            |


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


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

* [Bug tree-optimization/21690] gcc misses trivial optimizations
  2005-05-21  0:24 [Bug c/21690] New: gcc misses trivial optimizations ? TazForEver at dlfp dot org
@ 2005-05-21  0:32 ` pinskia at gcc dot gnu dot org
  2005-05-21  0:32 ` pinskia at gcc dot gnu dot org
  1 sibling, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-05-21  0:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-05-21 00:32 -------
This bolls down to combine not working across function calls.  The correct way to fix this would to have 
a tree combiner.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |15459
          Component|c                           |tree-optimization
           Keywords|                            |missed-optimization
            Summary|gcc misses trivial          |gcc misses trivial
                   |optimizations ?             |optimizations


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


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

* [Bug tree-optimization/21690] gcc misses trivial optimizations
       [not found] <bug-21690-4@http.gcc.gnu.org/bugzilla/>
@ 2014-10-31  4:02 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2014-10-31  4:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21690
Bug 21690 depends on bug 15459, which changed state.

Bug 15459 Summary: [meta-bug] there should be a tree combiner like the rtl one
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=15459

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED


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

* [Bug tree-optimization/21690] gcc misses trivial optimizations
       [not found] <bug-21690-9544@http.gcc.gnu.org/bugzilla/>
@ 2008-09-09  1:50 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-09-09  1:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2008-09-09 01:49 -------
This was fixed for 4.3.0.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.3.0


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


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

end of thread, other threads:[~2014-10-31  4:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-21  0:24 [Bug c/21690] New: gcc misses trivial optimizations ? TazForEver at dlfp dot org
2005-05-21  0:32 ` [Bug tree-optimization/21690] gcc misses trivial optimizations pinskia at gcc dot gnu dot org
2005-05-21  0:32 ` pinskia at gcc dot gnu dot org
     [not found] <bug-21690-9544@http.gcc.gnu.org/bugzilla/>
2008-09-09  1:50 ` pinskia at gcc dot gnu dot org
     [not found] <bug-21690-4@http.gcc.gnu.org/bugzilla/>
2014-10-31  4:02 ` pinskia at gcc dot gnu.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).