This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization o2 vs o3 issue
- From: Andrew Haley <aph at redhat dot com>
- To: manish_baphna at yahoo dot com
- Cc: gcc-help at gcc dot gnu dot org, John Fine <johnsfine at verizon dot net>
- Date: Mon, 22 Dec 2008 11:20:32 +0000
- Subject: Re: Optimization o2 vs o3 issue
- References: <131231.91512.qm@web94715.mail.in2.yahoo.com>
Manish Baphna wrote:
> A quick update, Though I couldn't really found real issue , I found
> an interesting solution which worked. magic word is 'volatile' :)
>
>
> Original two lines were
>
> dout.data[15 - count]
> = (uint8_t)(((long long unsigned int)
> (*(soc_cpr_dbusdataout_->sig_value_upper))
> & (mask << ((8+count)*8)))>>((8+count)*8));
>
> cout << "Dout data " << (uint64_t)((dout.data)[15-count]) << endl;
>
> What I did was inserting this line just above Line#1
> volatile uint32_t shift_val = ((8+count)*8) ;
> and used this in above Line#1 , and then I removed Line#2 and this time it worked.
> ( First I tried without using 'volatile' and it didn't help )
> Another workaround that did the same thing was making
> count as volatile.
Interesting. Is this a multi-threaded application? The other
possibility is an array bounds overflow.
> These two lines are in for loop which goes for count = 0 to 7 , I
> don't know why compiler is being lazy here to read it everytime
> unless I make it volatile.
The compiler isn't supposed to read it everytime unless you make it
volatile.
> Should it be logged as bug in gcc somewhere ?
Not until you can come up with a test cases that someone else can run.
Andrew.