public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: optimization/7476: constant variable tested in loop
@ 2002-08-02 16:16 Andrew Pinski
0 siblings, 0 replies; 4+ messages in thread
From: Andrew Pinski @ 2002-08-02 16:16 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR optimization/7476; it has been noted by GNATS.
From: Andrew Pinski <pinskia@physics.uc.edu>
To: Kevin Ryde <user42@zip.com.au>
Cc: gcc-gnats@gcc.gnu.org
Subject: Re: optimization/7476: constant variable tested in loop
Date: Fri, 2 Aug 2002 19:12:02 -0400
This has been fixed in at least gcc 3.3 20020802 (experimental):
.file "foo.c"
.text
.align 2
.p2align 4,,15
.globl foo
.type foo, @function
foo:
pushl %ebp
movl $9, %eax
movl %esp, %ebp
.p2align 4,,15
.L7:
decl %eax
jns .L7
popl %ebp
ret
.size foo, .-foo
.ident "GCC: (GNU) 3.3 20020802 (experimental)"
which is compared to gcc 3.1.1:
.file "foo.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "hello"
.text
.align 2
.p2align 4,,15
.globl foo
.type foo,@function
foo:
pushl %ebp
movl %esp, %ebp
pushl %esi
xorl %esi, %esi
pushl %ebx
movl $9, %ebx
subl $16, %esp
.p2align 4,,15
.L7:
testl %esi, %esi
jne .L10
.L4:
decl %ebx
jns .L7
addl $16, %esp
popl %ebx
popl %esi
popl %ebp
ret
.p2align 4,,7
.L10:
movl $.LC0, (%esp)
call puts
jmp .L4
.Lfe1:
.size foo,.Lfe1-foo
.ident "GCC: (GNU) 3.1.1"
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: optimization/7476: constant variable tested in loop
@ 2002-12-06 13:35 bangerth
0 siblings, 0 replies; 4+ messages in thread
From: bangerth @ 2002-12-06 13:35 UTC (permalink / raw)
To: gcc-bugs, gcc-prs, nobody, user42
Synopsis: constant variable tested in loop
State-Changed-From-To: open->closed
State-Changed-By: bangerth
State-Changed-When: Fri Dec 6 13:35:33 2002
State-Changed-Why:
This works on the mainline, i.e. what will become 3.3
http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7476
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: optimization/7476: constant variable tested in loop
@ 2002-08-02 19:36 Daniel Berlin
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Berlin @ 2002-08-02 19:36 UTC (permalink / raw)
To: nobody; +Cc: gcc-prs
The following reply was made to PR optimization/7476; it has been noted by GNATS.
From: Daniel Berlin <dberlin@dberlin.org>
To: Kevin Ryde <user42@zip.com.au>
Cc: gcc-gnats@gcc.gnu.org, <nobody@gcc.gnu.org>,
<gcc-prs@gcc.gnu.org>, <gcc-bugs@gcc.gnu.org>
Subject: Re: optimization/7476: constant variable tested in loop
Date: Fri, 2 Aug 2002 22:27:50 -0400 (EDT)
Fixed by the local cprop stuff Jan added to the mainline.
.file "testconst.c"
.text
.align 2
.p2align 4,,15
.globl foo
.type foo, @function
foo:
pushl %ebp
movl $9, %eax
movl %esp, %ebp
.p2align 4,,15
.L7:
decl %eax
jns .L7
popl %ebp
ret
.size foo, .-foo
.ident "GCC: (GNU) 3.3 20020729 (experimental)
On Sat, 3 Aug 2002, Kevin Ryde wrote:
>
> >Number: 7476
> >Category: optimization
> >Synopsis: constant variable tested in loop
> >Confidential: no
> >Severity: non-critical
> >Priority: low
> >Responsible: unassigned
> >State: open
> >Class: pessimizes-code
> >Submitter-Id: net
> >Arrival-Date: Fri Aug 02 16:06:01 PDT 2002
> >Closed-Date:
> >Last-Modified:
> >Originator:
> >Release: 3.1.1 20020606 (Debian prerelease) (Debian testing/unstable)
> >Organization:
> >Environment:
> System: Linux blah 2.2.15 #1 Tue Apr 25 17:13:48 EST 2000 i586 unknown
> Architecture: i586
> <machine, os, target, libraries (multiple lines)>
> host: i386-pc-linux-gnu
> build: i386-pc-linux-gnu
> target: i386-pc-linux-gnu
> configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds1/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/g++-v3-3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux
>
> >Description:
> A constant variable tested within a loop doesn't seem to be
> recognised as constant.
>
> >How-To-Repeat:
> The file foo.c below compiled with
>
> gcc-3.1 -O9 -S foo.c
>
> produces the foo.s below. Notice that it still contains a call to
> "puts", despite the "cond" variable in the source always being false.
>
> Outside a loop such a construct seems to be recognised as constant and
> the dependent code goes dead, but within a loop that doesn't seem to
> happen.
>
> I'm not sure if it's too much to expect something like this in a loop
> to go dead. I guess in the presence of gotos or loops it's not always
> too easy to be certain something really is constant. A variable
> written only once with a constant value like this might be tractable
> though.
>
> For what it's worth this arose within gmp where the "cond" condition
> tested was sometimes a compile-time constant, or sometimes a runtime
> test, depending on the configuration. It had seemed like a good idea
> just to put the result in a variable in either case, and let the
> optimizer drop unused code in the constant case.
>
>
>
> --=-=-=
> Content-Type: text/x-csrc
> Content-Disposition: attachment; filename=foo.c
>
> void
> foo (void)
> {
> int cond = 0;
> int i;
>
> for (i = 0; i < 10; i++)
> if (cond)
> puts ("hello");
> }
>
> --=-=-=
> Content-Disposition: attachment; filename=foo.s
>
> .file "foo.c"
> .section .rodata.str1.1,"aMS",@progbits,1
> .LC0:
> .string "hello"
> .text
> .align 2
> .p2align 2,,3
> .globl foo
> .type foo,@function
> foo:
> pushl %ebp
> movl %esp, %ebp
> pushl %esi
> pushl %ebx
> xorl %esi, %esi
> movl $9, %ebx
> .p2align 2,,3
> .L7:
> testl %esi, %esi
> jne .L10
> .L4:
> decl %ebx
> jns .L7
> leal -8(%ebp), %esp
> popl %ebx
> popl %esi
> leave
> ret
> .p2align 2,,3
> .L10:
> subl $12, %esp
> pushl $.LC0
> call puts
> addl $16, %esp
> jmp .L4
> .Lfe1:
> .size foo,.Lfe1-foo
> .ident "GCC: (GNU) 3.1.1 20020703 (Debian prerelease)"
>
> --=-=-=--
> >Fix:
> >Release-Note:
> >Audit-Trail:
> >Unformatted:
> --=-=-=
>
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* optimization/7476: constant variable tested in loop
@ 2002-08-02 16:06 Kevin Ryde
0 siblings, 0 replies; 4+ messages in thread
From: Kevin Ryde @ 2002-08-02 16:06 UTC (permalink / raw)
To: gcc-gnats
>Number: 7476
>Category: optimization
>Synopsis: constant variable tested in loop
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: pessimizes-code
>Submitter-Id: net
>Arrival-Date: Fri Aug 02 16:06:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:
>Release: 3.1.1 20020606 (Debian prerelease) (Debian testing/unstable)
>Organization:
>Environment:
System: Linux blah 2.2.15 #1 Tue Apr 25 17:13:48 EST 2000 i586 unknown
Architecture: i586
<machine, os, target, libraries (multiple lines)>
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: /mnt/data/gcc-3.1/gcc-3.1-3.1.1ds1/src/configure -v --enable-languages=c,c++,java,f77,proto,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/g++-v3-3.1 --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --enable-clocale=gnu --enable-threads=posix --enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
A constant variable tested within a loop doesn't seem to be
recognised as constant.
>How-To-Repeat:
The file foo.c below compiled with
gcc-3.1 -O9 -S foo.c
produces the foo.s below. Notice that it still contains a call to
"puts", despite the "cond" variable in the source always being false.
Outside a loop such a construct seems to be recognised as constant and
the dependent code goes dead, but within a loop that doesn't seem to
happen.
I'm not sure if it's too much to expect something like this in a loop
to go dead. I guess in the presence of gotos or loops it's not always
too easy to be certain something really is constant. A variable
written only once with a constant value like this might be tractable
though.
For what it's worth this arose within gmp where the "cond" condition
tested was sometimes a compile-time constant, or sometimes a runtime
test, depending on the configuration. It had seemed like a good idea
just to put the result in a variable in either case, and let the
optimizer drop unused code in the constant case.
--=-=-=
Content-Type: text/x-csrc
Content-Disposition: attachment; filename=foo.c
void
foo (void)
{
int cond = 0;
int i;
for (i = 0; i < 10; i++)
if (cond)
puts ("hello");
}
--=-=-=
Content-Disposition: attachment; filename=foo.s
.file "foo.c"
.section .rodata.str1.1,"aMS",@progbits,1
.LC0:
.string "hello"
.text
.align 2
.p2align 2,,3
.globl foo
.type foo,@function
foo:
pushl %ebp
movl %esp, %ebp
pushl %esi
pushl %ebx
xorl %esi, %esi
movl $9, %ebx
.p2align 2,,3
.L7:
testl %esi, %esi
jne .L10
.L4:
decl %ebx
jns .L7
leal -8(%ebp), %esp
popl %ebx
popl %esi
leave
ret
.p2align 2,,3
.L10:
subl $12, %esp
pushl $.LC0
call puts
addl $16, %esp
jmp .L4
.Lfe1:
.size foo,.Lfe1-foo
.ident "GCC: (GNU) 3.1.1 20020703 (Debian prerelease)"
--=-=-=--
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:
--=-=-=
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2002-12-06 21:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-02 16:16 optimization/7476: constant variable tested in loop Andrew Pinski
-- strict thread matches above, loose matches on Subject: below --
2002-12-06 13:35 bangerth
2002-08-02 19:36 Daniel Berlin
2002-08-02 16:06 Kevin Ryde
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).