This is the mail archive of the gcc-patches@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: [patch] for PR 18040


* Zack Weinberg:

> If I have understood correctly, then my suggestion would be that you
> should have Gigi translate this code to GENERIC equivalent to the
> following C example:
>
> int foo(void)
> {
>   typedef int arr[100000];
>   typedef struct { int f1; int f2[999999]; } r;
>
>   arr var;
>
>   return ((r *) &var)->f1 + var[2000];
> }

Unfortunately, var doesn't have to be addressable.  Consider the
following example:

with Ada.Unchecked_Conversion;

procedure Bar is

   type T is mod 2**4;
   type Foo is record
      A, B : T;
   end record;
   pragma Pack (Foo);
   for Foo'Size use 8;

   type U is mod 2**2;
   type Baz is record
      A, B : U;
   end record;
   pragma Pack (Baz);
   for Baz'Size use 4;

   Var1 : Foo;
   pragma Import (Ada, Var1);

   Var2 : U;
   pragma Import (Ada, Var2);

   function Convert is new Ada.Unchecked_Conversion (T, Baz);

begin
   Var2 := Convert (Var1.B).B;
end Bar;

However, this looks much like the distinction between by-copy and
by-reference types that is already needed for function calls.

For the example above, all versions of GNAT I've tested (GNAT 3.15p,
GCC 3.4, mainline) generate somewhat questionable code which involves
bit operations on registers that are only partly defined (the
undefined bits are subsequently masked away, though).  For example,
GNAT 3.15p generates:

        movb var1,%al
        shrb $4,%al
        shrl $2,%eax
        andl $3,%eax
        movb %al,var2
        ret

Still not optimal, but mainline looks worse:

        movzbl  var1, %eax
        andl    $-16, %edx
        shrb    $4, %al
        orl     %eax, %edx
        movl    %edx, %eax
        shrb    $2, %al
        andl    $3, %eax
        movb    %al, var2
        ret

> The only catch is that alias analysis must understand that rp aliases
> var.  This may require some adjustment to GNAT's alias set logic.

I'm not sure if this is actually required by the language, but
real-world code probably needs this.


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