On Thu, May 7, 2009 at 3:05 PM, Andrew Haley <a...@redhat.com> wrote:
> Dave Korn wrote:
>> Andrew Haley wrote:
>>> eCos@ wrote:
>>
>>>> ===============================================
>>>> int *p;
>>>>
>>>> int main(void)
>>>> {
>>>>         p++;
>>>>         __asm__ __volatile__ (""::);
>>>>         p++;
>>>> }
>>>> ===============================================
>>
>>>> assembly code is like:
>>>> 'addl $4, %eax'
>>>> 'addl $4, %eax'
>>
>>>> ===============================================
>>>> int *p;
>>>>
>>>> int main(void)
>>>> {
>>>>         p++;
>>>>         __asm__ __volatile__ (""::);
>>>>         p+=8;
>>>> }
>>>> ===============================================
>>
>>>> According to the assembly code, we found that gcc merge the 'p++' & 'p+=8'
>>>> and generate 'addl $36, p'
>>
>>> If you really need a memory barrier, you have to use one:
>>
>>   So, this is a real bug then - but it's a missed optimisation in the first
>> case, not a bogus one in the second case?
>
> There's certainly something seriously screwy about it.  Both of these
> are optimized identically until the very last tree optimization pass,
> where they diverge.

Well, the obvious missed optimization is that the alias oracle
currently treats all asms with VOPs as clobbering/using all
memory.

Richard.

> p.c.122t.uncprop:
>
> ;; Function main (main)
>
> main ()
> {
>  int * p.1;
>  int * p.0;
>
> <bb 2>:
>  p.0_1 = p;
>  p.1_2 = p.0_1 + 4;
>  __asm__ __volatile__("");
>  p.1_4 = p.1_2 + 4;
>  p = p.1_4;
>  return;
>
> }
>
>
>
> ;; Function main2 (main2)
>
> main2 ()
> {
>  int * p.4;
>  int * p.3;
>  int * p.2;
>
> <bb 2>:
>  p.2_1 = p;
>  p.3_2 = p.2_1 + 4;
>  __asm__ __volatile__("");
>  p.4_4 = p.3_2 + 8;
>  p = p.4_4;
>  return;
>
> }
>
>
> p.c.123t.optimized:
>
> ;; Function main (main)
>
> Analyzing Edge Insertions.
> main ()
> {
>  int * p.1;
>
> <bb 2>:
>  p.1 = p + 4;
>  __asm__ __volatile__("");
>  p = [pointer_plus_expr] p.1 + 4;
>  return;
>
> }
>
>
>
> ;; Function main2 (main2)
>
> Analyzing Edge Insertions.
> main2 ()
> {
> <bb 2>:
>  __asm__ __volatile__("");
>  p = [pointer_plus_expr] (p + 4) + 8;
>  return;
>
> }
>
> Andrew.
>

Reply via email to