[LLVMdev] Making GEP into vector illegal?

Mon Ping Wang wangmp at apple.com
Tue Oct 14 16:57:45 PDT 2008


On Oct 14, 2008, at 1:54 PM, Eli Friedman wrote:

> On Tue, Oct 14, 2008 at 1:34 PM, Daniel M Gessel <gessel at apple.com>  
> wrote:
>> In Joe programmer language (i.e. C ;) ), are we basically talking
>> about disallowing:
>>
>> float4 a;
>> float* ptr_z = &a.z;
>>
>> ?
>
>
> That's my reading as well; the argument for not allowing it is just to
> make optimization easier.  We don't allow addressing individual bits
> either, and compilers obviously have to work around that for
> bitfields.
>
> AFAIK, both clang and gcc currently don't allow constructs like  
> "&a.z".
>

Yes, that is what we are talking about and Eli is right that it is to  
make optimization easier.

>> Won't programmers just resort to:
>>
>> float4 a;
>> float* ptr_z = (float*)(&a) + 3;
>>
>> ?
>
> Maybe... although note that with gcc vector intrinsics, this violates
> strict aliasing.  gcc does allow you to use a slightly more elaborate
> workaround with a union, though.
>

Sure, someone can write that.  Of course, they are making assumptions  
on how the float4 is stored in memory.  From the point of view of the  
IR, that is fine.  We are not generating a GEP into a vector type but  
GEP from a float pointer.  Someone may get worse performance though if  
someone writes code like that.

   -- Mon Ping



More information about the llvm-dev mailing list