[LLVMdev] Alignment of constant loads

Stefanus Du Toit sdt at rapidmind.com
Fri Sep 12 11:33:11 PDT 2008


Hi,

We've noticed that constant loads, e.g. of v4f32 types, are not  
aligned to the preferred alignment but rather to the ABI alignment, at  
least on x86. This seems to stem from SelectionDAG::getLoad() being  
called with an alignment of 0, which then does:

   if (Alignment == 0)  // Ensure that codegen never sees alignment 0
     Alignment = getMVTAlignment(VT);

Inside getMVTAlignment, the ABI alignment is retrieved for the given VT.

It appears that constants are already aligned to the preferred  
alignment, given this code in ScheduleDAG::AddOperand():

   } else if (ConstantPoolSDNode *CP =  
dyn_cast<ConstantPoolSDNode>(Op)) {
    [...]
       Align = TM.getTargetData()->getPreferredTypeAlignmentShift(Type);

(note there is a curious FIXME there about alignment of vector types  
-- I think this may be a relic since getPreferredTypeAlignmentShift  
should not return zero for vector types -- correct me if I'm wrong!)

Do you have a suggestion as to how we can make it so that loads for  
constants are aligned to the preferred alignment, rather than the ABI  
alignment? We're not sure where this should be "fixed".

Thanks!

Stefanus

--
Stefanus Du Toit <stefanus.dutoit at rapidmind.com>
   RapidMind Inc.
   phone: +1 519 885 5455 x116 -- fax: +1 519 885 1463






More information about the llvm-dev mailing list