[LLVMdev] Alignment of constant loads

Dan Gohman gohman at apple.com
Mon Sep 15 15:52:21 PDT 2008


On Sep 15, 2008, at 2:45 PM, Paul Redmond wrote:

> Hi Dan,

Hi Paul,

>
>> It looks like the best way to do this is to visit the handful of
>> places in legalize that create loads from constant pools and
>> add alignment parameters to the getLoad/getExtLoad calls.
>>
>> If you move the handling of Alignment==0 out of ScheduleDAGEmit.cpp
>> and into SelectionDAG::getConstantPool, you can then have legalize
>> read the alignment from the node, instead of making its own
>> decision:
>>   cast<ConstantPoolSDNode>(CPIdx)->getAlignment()
>>
>>
> I followed your suggestion but I've come across a bit of a snag. If  
> you get the alignment in LegalizeDAG using:
>
> SDValue CPIdx = DAG.getConstantPool(LLVMC, TLI.getPointerTy());
> unsigned Alignment = cast<ConstantPoolSDNode>(CPIdx)->getAlignment();
>
> The ConstantPoolSDNode is created using MVT i32 (TLI.getPointerTy())  
> and the alignment is 4 bytes. It seems there is not enough  
> information to know that the final MVT will be v4f32 so passing the  
> alignment to getLoad/getExtLoad in LegalizeDAG will still generate  
> unaligned loads for constant vectors.
>
> Any ideas?


In SelectionDAG::getConstantPool, while VT is the type of the
constant pool entry address, C is the actual constant, so the code
should look at C->getType() when it needs to compute the alignment.
That should allow it to obtain the desired alignment and set up the
ConstantPoolSDNode correctly. Then the LegalizeDAG code you show
above should work.

Dan




More information about the llvm-dev mailing list