* serious code optimization bug in 2.8.0 / sparc
@ 1998-01-24 17:58 Ulrich Lauther
1998-01-24 22:58 ` Chris Johns
0 siblings, 1 reply; 2+ messages in thread
From: Ulrich Lauther @ 1998-01-24 17:58 UTC (permalink / raw)
To: egcs
I have sent the bug report below to gnu.g++.bug.
I don't have egcs available. Could someone check if it suffers the same
problem?
Of course, if someone had a patch ...
Thank you,
-ulrich
the following code snippet extracted from a larger project
produces wrong output when compiled with -O2 on
SunOS gomory 5.5.1 Generic sun4m sparc SUNW,SPARCstation-20
This did not happen with 2.7.2.1 and does not happen under Linux i*86
************************ test.C: ********************************
#include <stdio.h>
typedef unsigned long word;
static const int chunk_length = 4096;
static const int unit_size = 4;
typedef unsigned char u_char;
class chunk {
u_char tags[128];
static u_char tag_mask[64];
public:
static const int offset;
static const int offset_units;
inline static u_char* word2tag(const void* p, int& first_bit) {
chunk* pc = (chunk*) ((word) p & ~(chunk_length-1));
int off = ((word*) p - (word*) pc) - offset_units; // bit index
first_bit = off&7;
return pc->tags + off/8;
}
void chunk::set_tags(word* p, int words);
};
void chunk::set_tags(word* p, int words) {
// called after allocation to mark allocated memory
fprintf(stderr,"set_tags %p (%d) \n",p,words);
int first_bit;
// ********************** here is the problem ***********
// word2tag seems to set first_bit erreneously to 0,
// so that the index calculation below gives
// 0*8 + 7 = 7
// but it should give 2*8 + 7 = 23
//********************************************************
u_char* tag = word2tag(p,first_bit);
for (int last_bit = first_bit + words - 1; last_bit >= 0; last_bit -= 8) {
int index = first_bit*8 + (last_bit < 7 ? last_bit : 7);
fprintf(stderr,"%d\n", index);
*(tag++) |= tag_mask[first_bit*8 + (last_bit < 7 ? last_bit : 7)];
fprintf(stderr,"first: %d last: %d tag 0x%2x\n",
first_bit,last_bit,*(tag-1));
first_bit = 0;
}
} // set_tags
const int chunk::offset = 8+128; // first free index in bytes
const int chunk::offset_units = chunk::offset/unit_size;
u_char chunk::tag_mask[64];
int main() {
int last_bit = 14;
int first_bit;
chunk* c = (chunk*) memalign(4096,4096);
word* p = (word*) ((char*) c + 0x90);
c->set_tags(p,13);
}
************************************************************************
Wrong output with -O2:
set_tags 22090 (13)
7
first: 0 last: 14 tag 0x 0
6
first: 0 last: 6 tag 0x 0
************************************************************************
Correct output without optimization:
set_tags 22090 (13)
23
first: 2 last: 14 tag 0x 0
6
first: 0 last: 6 tag 0x 0
************************************************************************
compile statement:
Reading specs from /sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/specs
gcc version 2.8.0
/sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=8 -Dsparc -Dsun -Dunix -D__svr4__ -D__SVR4 -D__sparc__ -D__sun__ -D__unix__ -D__svr4__ -D__SVR4 -D__sparc -D__sun -D__unix -Asystem(unix) -Asystem(svr4) -D__EXCEPTIONS -D__OPTIMIZE__ -D__GCC_NEW_VARARGS__ -Acpu(sparc) -Amachine(sparc) test.C /var/tmp/cca002dS.ii
GNU CPP version 2.8.0 (sparc)
#include "..." search starts here:
#include <...> search starts here:
/sw/local/include/g++
/sw/local/sparc-sun-solaris2.5.1/include
/sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/include
/usr/include
End of search list.
/sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/cc1plus /var/tmp/cca002dS.ii -quiet -dumpbase test.cc -O2 -version -o /var/tmp/cca002dS.s
GNU C++ version 2.8.0 (sparc-sun-solaris2.5.1) compiled by GNU C version 2.8.0.
test.C: In function `int main()':
test.C:46: warning: implicit declaration of function `int memalign(...)'
/usr/ccs/bin/as -V -Qy -s -o /var/tmp/cca002dS1.o /var/tmp/cca002dS.s
/usr/ccs/bin/as: SC4.2 dev 30 Nov 1995
/usr/ccs/bin/ld -V -Y P,/usr/ccs/lib:/usr/lib -Qy -o testopt /sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/crt1.o /sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/crti.o /usr/ccs/lib/values-Xa.o /sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/crtbegin.o -L/sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0 -L/sw/local/sparc-sun-solaris2.5.1/lib -L/usr/ccs/bin -L/usr/ccs/lib -L/sw/local/lib /var/tmp/cca002dS1.o -lstdc++ -lm -lgcc -lc -lgcc /sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/crtend.o /sw/local/lib/gcc-lib/sparc-sun-solaris2.5.1/2.8.0/crtn.o
ld: Software Generation Utilities (SGU) SunOS/ELF (LK-2.0 (S/I) - versioning)
--
-lauther
----------------------------------------------------------------------------
Ulrich Lauther ph: +49 89 636 48834 fx: ... 636 42284
Siemens ZT SE 4 Internet: Ulrich.Lauther@mchp.siemens.de
--
-lauther
----------------------------------------------------------------------------
Ulrich Lauther ph: +49 89 636 48834 fx: ... 636 42284
Siemens ZT SE 4 Internet: Ulrich.Lauther@mchp.siemens.de
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: serious code optimization bug in 2.8.0 / sparc
1998-01-24 17:58 serious code optimization bug in 2.8.0 / sparc Ulrich Lauther
@ 1998-01-24 22:58 ` Chris Johns
0 siblings, 0 replies; 2+ messages in thread
From: Chris Johns @ 1998-01-24 22:58 UTC (permalink / raw)
To: Ulrich.Lauther; +Cc: egcs
Ulrich Lauther wrote:
>
> I have sent the bug report below to gnu.g++.bug.
> I don't have egcs available. Could someone check if it suffers the same
> problem?
Yes, 980115 suffers from the same problem.
> Of course, if someone had a patch ...
> Thank you,
Sorry.
$ gcc -v
Reading specs from
/opt/compilers/egcs/lib/gcc-lib/sparc-sun-solaris2.4/egcs-2.91.04/specs
gcc version egcs-2.91.04 980115 (gcc-2.8.0 release)
--
Chris Johns Networks, Plessey Asia Pacfic Pty. Ltd.
mailto:ccj@acm.org mailto:cjohns@plessey.com.au
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-01-24 22:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-01-24 17:58 serious code optimization bug in 2.8.0 / sparc Ulrich Lauther
1998-01-24 22:58 ` Chris Johns
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).