Pass alignment on ByVal parameters, from FE, all
the way through.  It is now used for codegen.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47484 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 96dde98..62610db 100644
--- a/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -3118,6 +3118,7 @@
     Entry.isSRet  = CS.paramHasAttr(attrInd, ParamAttr::StructRet);
     Entry.isNest  = CS.paramHasAttr(attrInd, ParamAttr::Nest);
     Entry.isByVal = CS.paramHasAttr(attrInd, ParamAttr::ByVal);
+    Entry.Alignment = CS.getParamAlignment(attrInd);
     Args.push_back(Entry);
   }
 
@@ -4146,6 +4147,10 @@
       const Type *ElementTy = Ty->getElementType();
       unsigned FrameAlign = Log2_32(getByValTypeAlignment(ElementTy));
       unsigned FrameSize  = getTargetData()->getABITypeSize(ElementTy);
+      // For ByVal, alignment should be passed from FE.  BE will guess if
+      // this info is not there but there are cases it cannot get right.
+      if (F.getParamAlignment(j))
+        FrameAlign = Log2_32(F.getParamAlignment(j));
       Flags |= (FrameAlign << ISD::ParamFlags::ByValAlignOffs);
       Flags |= (FrameSize  << ISD::ParamFlags::ByValSizeOffs);
     }
@@ -4255,6 +4260,10 @@
       const Type *ElementTy = Ty->getElementType();
       unsigned FrameAlign = Log2_32(getByValTypeAlignment(ElementTy));
       unsigned FrameSize  = getTargetData()->getABITypeSize(ElementTy);
+      // For ByVal, alignment should come from FE.  BE will guess if this
+      // info is not there but there are cases it cannot get right.
+      if (Args[i].Alignment)
+        FrameAlign = Log2_32(Args[i].Alignment);
       Flags |= (FrameAlign << ISD::ParamFlags::ByValAlignOffs);
       Flags |= (FrameSize  << ISD::ParamFlags::ByValSizeOffs);
     }