public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
* Re: optimization/4108: optimizer produces incorrect assembly output for a bit test equality expression
@ 2002-04-02 20:14 rth
  0 siblings, 0 replies; 3+ messages in thread
From: rth @ 2002-04-02 20:14 UTC (permalink / raw)
  To: ben, gcc-bugs, gcc-prs, nobody, rth

Synopsis: optimizer produces incorrect assembly output for a bit test equality expression

Responsible-Changed-From-To: unassigned->rth
Responsible-Changed-By: rth
Responsible-Changed-When: Tue Apr  2 20:14:09 2002
Responsible-Changed-Why:
    .

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4108


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

* Re: optimization/4108: optimizer produces incorrect assembly output for a bit test equality expression
@ 2002-04-02 20:48 rth
  0 siblings, 0 replies; 3+ messages in thread
From: rth @ 2002-04-02 20:48 UTC (permalink / raw)
  To: ben, gcc-bugs, gcc-prs, rth

Synopsis: optimizer produces incorrect assembly output for a bit test equality expression

State-Changed-From-To: open->closed
State-Changed-By: rth
State-Changed-When: Tue Apr  2 20:48:50 2002
State-Changed-Why:
    Reproducable in 3.1 20020324, but not 3.1 20020402.
    Probably fixed by
    
    Thu Mar 28 16:33:13 2002  Jeffrey A Law  (law@redhat.com)
    
            * combine.c (simplify_and_const_int): Make sure to apply mask
            when force_to_mode returns a constant integer.  PR3311.

http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=4108


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

* optimization/4108: optimizer produces incorrect assembly output for a bit test equality expression
@ 2001-08-23 19:06 ben
  0 siblings, 0 replies; 3+ messages in thread
From: ben @ 2001-08-23 19:06 UTC (permalink / raw)
  To: gcc-gnats

>Number:         4108
>Category:       optimization
>Synopsis:       optimizer produces incorrect assembly output for a bit test equality expression
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 23 19:06:02 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     Ben Ross
>Release:        3.0.1
>Organization:
Proximity Pty Ltd
>Environment:
System: Linux mantis 2.4.2-2 #1 Sun Apr 8 20:41:30 EDT 2001 i686 unknown
Architecture: i686

	
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc-3.0.1/configure --prefix=/usr/local/gcc3 --enable-shared=libstdc++
>Description:
In a particular circumstance, the optimizer makes an incorrect assumption about the value
of a given expression, only if one of the inputs is a particular value. This assumption
results in assembly output with a constant value for the expression such that the expression
is completely optimized into a constant.

The expression is as follows:

byte & bit == bit

where byte and bit are of type short. Iff bit == 0x8000 and byte is only known at runtime
the optimizer incorrectly assumes this expression always evaluates to 0. When bit is some
other value, e.g. 0x0001, the assembly version of the expression is output and the program
executes correctly. Observing the difference in assembly output for different values of bit
reveals a combination of a right shift (shrl) and bitwise and with constant 1 (andl) being
used to (correctly) evaluate the expression where the amount of right-shift depends on the
value of bit.

Pure speculation follows:

Perhaps in the case where bit == 0x8000 the right-shift is shifting this value to 0, which
could cause the optimizer to assume the lhs of the original expression is always 0 causing
it to produce constant 0.
>How-To-Repeat:
I have put together a test program. Compiling without the optimizer produces the following
(correct) output:

testbyte = 0xffff8332 checkbit = 1

Compiling with -O2 produces:

testbyte = 0xffff8332 checkbit = 0

Here is the compiler output during the compile:

Reading specs from /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/specs
Configured with: ../gcc-3.0.1/configure --prefix=/usr/local/gcc3 --enable-shared=libstdc++
Thread model: single
gcc version 3.0.1
 /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/cc1plus -v -D__GNUC__=3 -D__GNUC_MINOR__=0 -D__GNUC_PATCHLEVEL__=1 -D__ELF__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -Asystem=posix -D__OPTIMIZE__ -D__STDC_HOSTED__=1 -D_GNU_SOURCE -Acpu=i386 -Amachine=i386 -Di386 -D__i386 -D__i386__ -D__tune_i686__ -D__tune_pentiumpro__ bittest.C -D__GNUG__=3 -D__GXX_DEPRECATED -D__EXCEPTIONS -D__GXX_ABI_VERSION=100 -quiet -dumpbase bittest.C -O2 -version -o /tmp/ccvEmfPh.s
GNU CPP version 3.0.1 (cpplib) (i386 Linux/ELF)
GNU C++ version 3.0.1 (i686-pc-linux-gnu)
        compiled by GNU C version 3.0.1.
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/local/gcc3/i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/gcc3/include/g++-v3
 /usr/local/gcc3/include/g++-v3/i686-pc-linux-gnu
 /usr/local/gcc3/include/g++-v3/backward
 /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/include
 /usr/include
End of search list.
 as --traditional-format -V -Qy -o /tmp/cc43wWkx.o /tmp/ccvEmfPh.s
GNU assembler version 2.10.91 (i386-redhat-linux) using BFD version 2.10.91.0.2
 /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/crtbegin.o -L/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1 -L/usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/../../.. /tmp/cc43wWkx.o -lstdc++ -lm -lgcc -lc -lgcc /usr/local/gcc3/lib/gcc-lib/i686-pc-linux-gnu/3.0.1/crtend.o /usr/lib/crtn.o

And here is a uuencoded bzipped tar file (bittest.tar.bz2) containing the following files:

-rw-r--r-- ben/px          521 2001-08-20 11:44:26 bittest.C
-rw-r--r-- ben/px        26018 2001-08-20 11:48:49 bittest.ii

the first is the test program and the second is the preprocessed version.

begin 644 bittest.tar.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(2&D`-M0ZHGD[ERN\@!O*J7]``PZD4,4MO;M5]
MO%019=G4"1(UD@X6'N-$A:1D"'"&'C'!N"&T$N=&B^\UHJ?\95.`'6KXC0:J
MK]Y`>"ASY37XGI26Q"9HZLDGX<:"$DD5BSYIB!U2M%`#>(2'"QNL#OG52!=J
MRID<+]DX8`5`VSK':+N)5I=1F815`T:->U<0L@+MINJ\0H[9JA"$!A(119YE
2H016`+23_XNY(IPH2'?%,E"`
`
end
>Fix:
This isn't a real fix, but in the case where bit only has one bit set
then doing the following is equivalent, and produces the correct output:

byte & bit

Of course, if bit has more than one bit set, then the compiler might
produce the correct output (I didn't test this)
>Release-Note:
>Audit-Trail:
>Unformatted:


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

end of thread, other threads:[~2002-04-03  4:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-04-02 20:14 optimization/4108: optimizer produces incorrect assembly output for a bit test equality expression rth
  -- strict thread matches above, loose matches on Subject: below --
2002-04-02 20:48 rth
2001-08-23 19:06 ben

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