This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Why doesn't combine like volatiles? (volatile_ok again, sorry!)


On Mon, 2005-11-28 at 14:10 +0100, Paolo Bonzini wrote:
> Then, I don't know if it would be legal to optimize
> 
>    struct r {
>      unsigned int x : 7;
>      volatile unsigned int y : 1;
>    };
> 
>    struct r my_reg;
> 
> So that my_reg.x is accessed with a non-volatile mem, and my_reg.y is 
> accessed with a volatile one.  Would such an optimization be possible 
> within the Ada compile-time rules?

procedure P is

   type T7 is mod 2**7;
   type T1 is mod 2;
   pragma Volatile (T1);

   type R is record
      X : T7;
      Y : T1;
   end record;
   for R'Size use 8;
   for R'Alignment use 1;
   for R use record
      X at 0 range  0 ..  6;
      Y at 0 range  7 ..  7;
   end record;

   Z : R;
   A : T7;
   B : T1;
begin
   Z.X := 127;
   Z.Y := 1;
   A := Z.X;
   B := Z.Y;
end P;

trunk gcc -O2 -S p.adb on x86-linux gives:

_ada_p:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $16, %esp
        movb    $1, -1(%ebp)
        leave
        ret

My understanding is that B := Z.Y implied memory read should not be
optimized away since it is a volatile read and thus an external effect,
so this looks like a bug to me. (If this is not supported, GNAT should
fail at compile time.)

Z.X write and read are correctly optimized away: non volatile
read and write have no external effects here.

Laurent



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]