public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/21182] New: gcc can use registers but uses stack instead
@ 2005-04-23 22:30 vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-04-23 22:32 ` [Bug rtl-optimization/21182] " vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-04-23 22:30 UTC (permalink / raw)
  To: gcc-bugs

in this long but relatively simple function gcc
can store all frequently used local variables in registers,
but it fails to do so.

gcc can be forced to do this optimization by asm("reg") modifiers.
Resulting code is ~1k smaller.

# gcc -v
Reading specs from
/.share/usr/app/gcc-3.4.3/bin/../lib/gcc/i386-pc-linux-gnu/3.4.3/specs
Configured with: ../gcc-3.4.3/configure --prefix=/usr/app/gcc-3.4.3
--exec-prefix=/usr/app/gcc-3.4.3 --bindir=/usr/bin --sbindir=/usr/sbin
--libexecdir=/usr/app/gcc-3.4.3/libexec --datadir=/usr/app/gcc-3.4.3/share
--sysconfdir=/etc --sharedstatedir=/usr/app/gcc-3.4.3/var/com
--localstatedir=/usr/app/gcc-3.4.3/var --libdir=/usr/lib
--includedir=/usr/include --infodir=/usr/info --mandir=/usr/man
--with-slibdir=/usr/app/gcc-3.4.3/lib --with-local-prefix=/usr/local
--with-gxx-include-dir=/usr/app/gcc-3.4.3/include/g++-v3
--enable-languages=c,c++ --with-system-zlib --disable-nls --enable-threads=posix
i386-pc-linux-gnu
Thread model: posix
gcc version 3.4.3

-- 
           Summary: gcc can use registers but uses stack instead
           Product: gcc
           Version: 3.4.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: vda at port dot imtp dot ilyichevsk dot odessa dot ua
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i386-pc-linux-gnu
  GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-pc-linux-gnu


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


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

* [Bug rtl-optimization/21182] gcc can use registers but uses stack instead
  2005-04-23 22:30 [Bug rtl-optimization/21182] New: gcc can use registers but uses stack instead vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-04-23 22:32 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-04-23 22:39 ` pinskia at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-04-23 22:32 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-04-23 22:32 -------
Created an attachment (id=8719)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=8719&action=view)
testcase. change #if 0 into #if 1 and compare resulting asm


-- 


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


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

* [Bug rtl-optimization/21182] gcc can use registers but uses stack instead
  2005-04-23 22:30 [Bug rtl-optimization/21182] New: gcc can use registers but uses stack instead vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-04-23 22:32 ` [Bug rtl-optimization/21182] " vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-04-23 22:39 ` pinskia at gcc dot gnu dot org
  2005-04-23 22:49 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-23 22:39 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-23 22:39 -------
Hmm, on the mainline, we get for wc -l:
 1613 t.s
 1459 t1.s

t1 is the normal #if 0.

Note I used "-O2 -fomit-frame-pointer".

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization, ra


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


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

* [Bug rtl-optimization/21182] gcc can use registers but uses stack instead
  2005-04-23 22:30 [Bug rtl-optimization/21182] New: gcc can use registers but uses stack instead vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-04-23 22:32 ` [Bug rtl-optimization/21182] " vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-04-23 22:39 ` pinskia at gcc dot gnu dot org
@ 2005-04-23 22:49 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-04-23 22:54 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-04-23 22:49 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-04-23 22:49 -------
Aha!
I found out that gcc will use registers with -O3, but not with -O2.

# gcc -O3 serpent.c -S -o serpent-O3.s
# gcc -O2 serpent.c -S -o serpent-O2.s
# ls -l
-rw-r--r--  1 root root 27975 Apr 24 01:47 serpent-O2.s
-rw-r--r--  1 root root 21566 Apr 24 01:47 serpent-O3.s
# wc -l serpent-O2.s serpent-O3.s
 1558 serpent-O2.s
 1265 serpent-O3.s
 2823 total

I don't have 4.0.0 here yet...

-- 


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


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

* [Bug rtl-optimization/21182] gcc can use registers but uses stack instead
  2005-04-23 22:30 [Bug rtl-optimization/21182] New: gcc can use registers but uses stack instead vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (2 preceding siblings ...)
  2005-04-23 22:49 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-04-23 22:54 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-04-24 13:05 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-05-07 15:24 ` steven at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-04-23 22:54 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-04-23 22:54 -------
These are -O2 and -O3 code comparison.
-O3 code have all modified variables in registers
and thus is smaller and most likely faster.

serpent_encrypt:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %edi
        pushl   %esi
        pushl   %ebx
        subl    $256, %esp
        movl    8(%ebp), %edx
        movl    16(%ebp), %eax
        movl    12(%eax), %ebx
        movl    12(%edx), %ecx
        xorl    %ebx, %ecx
        movl    (%edx), %edi
        movl    %ecx, -20(%ebp)
        xorl    (%eax), %edi
        movl    8(%edx), %ecx
        movl    4(%edx), %ebx
        movl    -20(%ebp), %esi
        xorl    8(%eax), %ecx
        orl     %edi, -20(%ebp)
        xorl    4(%eax), %ebx
        xorl    %ebx, -20(%ebp)
        xorl    %esi, %edi
        xorl    %ecx, %esi
        andl    %edi, %ebx
        xorl    %edi, %ecx
        notl    %esi
        xorl    -20(%ebp), %edi
        movl    %edx, -16(%ebp)

serpent_encrypt:
        pushl   %ebp
        movl    %esp, %ebp
        pushl   %edi
        pushl   %esi
        pushl   %ebx
        pushl   %edx
        movl    8(%ebp), %edi
        movl    16(%ebp), %ecx
        movl    12(%edi), %eax
        xorl    12(%ecx), %eax
        movl    8(%edi), %esi
        movl    4(%edi), %edx
        movl    (%edi), %ebx
        xorl    8(%ecx), %esi
        xorl    4(%ecx), %edx
        xorl    (%ecx), %ebx
        movl    %eax, %ecx
        orl     %ebx, %ecx
        xorl    %eax, %ebx
        xorl    %esi, %eax
        xorl    %edx, %ecx
        notl    %eax
        andl    %ebx, %edx
        xorl    %eax, %edx
        xorl    %ebx, %esi
        xorl    %ecx, %ebx
        orl     %ebx, %eax
        xorl    %esi, %ebx
        andl    %edx, %esi
        xorl    %esi, %eax
        notl    %edx



-- 


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


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

* [Bug rtl-optimization/21182] gcc can use registers but uses stack instead
  2005-04-23 22:30 [Bug rtl-optimization/21182] New: gcc can use registers but uses stack instead vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (3 preceding siblings ...)
  2005-04-23 22:54 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-04-24 13:05 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
  2005-05-07 15:24 ` steven at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: vda at port dot imtp dot ilyichevsk dot odessa dot ua @ 2005-04-24 13:05 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From vda at port dot imtp dot ilyichevsk dot odessa dot ua  2005-04-24 13:05 -------
With 4.0.0: gcc -O2 gives the same result as gcc -O3,
which is better than gcc 3.4.3 -O2 but worse than 3.4.3 -O3.
For example:

        movl    %edx, -20(%ebp)
        orl     %ecx, %edi
        movl    %ebx, %esi
        xorl    %ecx, %esi
        andl    %eax, %ebx
        xorl    %edi, %ebx
        movl    %eax, %ecx
        notl    %ecx
        xorl    %ebx, %ecx
        orl     %edi, %eax
        xorl    %eax, %esi
        rorl    $19, %esi
        rorl    $29, -20(%ebp)
        xorl    %esi, %ebx
        xorl    -20(%ebp), %ecx
        xorl    -20(%ebp), %ebx
        rorl    $31, %ebx
        leal    0(,%esi,8), %edx

1) Why %edx was stored in -20(%ebp), there is no %edx usage
in the following insns. %edx value could stay in register
and we can continue to work on its value in register.
2) rorl $31, %ebx == roll $1, %ebx, but 1 bit roll insn is
smaller.


-- 


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


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

* [Bug rtl-optimization/21182] gcc can use registers but uses stack instead
  2005-04-23 22:30 [Bug rtl-optimization/21182] New: gcc can use registers but uses stack instead vda at port dot imtp dot ilyichevsk dot odessa dot ua
                   ` (4 preceding siblings ...)
  2005-04-24 13:05 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
@ 2005-05-07 15:24 ` steven at gcc dot gnu dot org
  5 siblings, 0 replies; 7+ messages in thread
From: steven at gcc dot gnu dot org @ 2005-05-07 15:24 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-07 15:23:12
               date|                            |


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


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

end of thread, other threads:[~2005-05-07 15:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-04-23 22:30 [Bug rtl-optimization/21182] New: gcc can use registers but uses stack instead vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-04-23 22:32 ` [Bug rtl-optimization/21182] " vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-04-23 22:39 ` pinskia at gcc dot gnu dot org
2005-04-23 22:49 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-04-23 22:54 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-04-24 13:05 ` vda at port dot imtp dot ilyichevsk dot odessa dot ua
2005-05-07 15:24 ` steven at gcc dot gnu 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).