[Bug c++/37096] New: conditional evaluation incorrect with -O3

2008-08-12 Thread erik dot moller at cycos dot com
// system: core duo, 2.4 GHz, 64bit debian sid, vanilla kernel 2.6.26.2
// I stumbled over this using gcc 4.3.1 (Debian 4.3.1-8)
// compiler switches: -O3 -mssse3
// there were no compiler warnings / errors.

const int32_t nCC_[16] = 
{
3, 2, 2, 1, 1, 1, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0
};

int32_t Residual4x4( int16_t *pAR, int32_t &nCost )
{
int32_t nRun = 0;

for( int i=0 ; i<16 ; ++i )
if ( const int v = pAR[i] ) {
nCost += ( abs(v) > 1 ) ? 16 : nCC_[nRun];
nRun = 0;
} else
++nRun;
}

// the above code calculates nCost uncorrectly (leading to a segfault later on)
// when I use the compiler switch -O2 or replace the conditional assignment by
an if / else
// construct, everything works fine.
// gcc 4.2 works fine too. (-with -O3 -msse2)


-- 
   Summary: conditional evaluation incorrect with -O3
   Product: gcc
   Version: 4.3.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: erik dot moller at cycos dot com


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



[Bug middle-end/37096] conditional evaluation incorrect with -O3

2008-08-18 Thread erik dot moller at cycos dot com


--- Comment #3 from erik dot moller at cycos dot com  2008-08-18 16:20 
---
Created an attachment (id=16084)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16084&action=view)
main() for the testcase


-- 


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



[Bug middle-end/37096] conditional evaluation incorrect with -O3

2008-08-18 Thread erik dot moller at cycos dot com


--- Comment #4 from erik dot moller at cycos dot com  2008-08-18 16:20 
---
Created an attachment (id=16085)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16085&action=view)
the test case

it's as minimal I could get it...


-- 


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



[Bug middle-end/37096] conditional evaluation incorrect with -O3

2008-08-18 Thread erik dot moller at cycos dot com


--- Comment #5 from erik dot moller at cycos dot com  2008-08-18 16:22 
---

the printf("shouldn't happen: %d\n", pAR[0]) happens when debug flags -O2 or
-O3 and -msse2 are set.
the printf("nz: %d\n", nZ); seems to do something awful...

void fun(short *pAR)
{
const short tmp = Transform4x4(pAR);
pAR[0] = 0;

int nZ = 0;
for( int i=0; i<4 ; ++i )
if ( pAR[i] ) {
++nZ;
}

printf("nz: %d\n", nZ);
if ( pAR[0] )
printf("shouldn't happen: %d\n", pAR[0]);
pAR[0] = tmp;
}


-- 


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



[Bug middle-end/37096] conditional evaluation incorrect with -O3

2008-09-08 Thread erik dot moller at cycos dot com


--- Comment #6 from erik dot moller at cycos dot com  2008-09-08 10:54 
---
bug is still in 4.3.2


-- 

erik dot moller at cycos dot com changed:

   What|Removed |Added

Version|4.3.1   |4.3.2


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



[Bug target/37096] conditional evaluation incorrect with -O3

2008-09-12 Thread erik dot moller at cycos dot com


--- Comment #9 from erik dot moller at cycos dot com  2008-09-12 11:33 
---
true, -fno-strict-aliasing makes even -O3 work... I don't know about the
liasing, the example is very simple, can that happen when the SSE2 intrinsics
are involved?


-- 


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