Alignment of constant loads


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".