Fixed generating incorrect aligned stores that I backout of r53031
authorMon P Wang <wangmp@apple.com>
Sat, 5 Jul 2008 20:40:31 +0000 (20:40 +0000)
committerMon P Wang <wangmp@apple.com>
Sat, 5 Jul 2008 20:40:31 +0000 (20:40 +0000)
that fixed problems in EmitStackConvert where the source and target type
have different alignment by creating a stack slot with the max
alignment of source and target type.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53150 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/CodeGen/SelectionDAG.h
lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
lib/CodeGen/SelectionDAG/SelectionDAG.cpp

index 7ebc698bad36ec3c5c119b2b8a5ef3702a2030ed..4f532ba43bf6ca208b4a89cec906850d0d66c20e 100644 (file)
@@ -589,9 +589,10 @@ public:
   void dump() const;
 
   /// CreateStackTemporary - Create a stack temporary, suitable for holding the
-  /// specified value type.
-  SDOperand CreateStackTemporary(MVT VT);
-
+  /// specified value type.  If minAlign is specified, the slot size will have
+  /// at least that alignment.
+  SDOperand CreateStackTemporary(MVT VT, unsigned minAlign = 1);
+  
   /// FoldSetCC - Constant fold a setcc to true or false.
   SDOperand FoldSetCC(MVT VT, SDOperand N1,
                       SDOperand N2, ISD::CondCode Cond);
index d929ec01c315504b72d4c0db8f3bebd362428f4d..3695580a92b575a169b587a010f968b3ee27da7a 100644 (file)
@@ -4871,35 +4871,41 @@ SDOperand SelectionDAGLegalize::EmitStackConvert(SDOperand SrcOp,
                                                  MVT SlotVT,
                                                  MVT DestVT) {
   // Create the stack frame object.
-  SDOperand FIPtr = DAG.CreateStackTemporary(SlotVT);
-
+  unsigned SrcAlign = TLI.getTargetData()->getPrefTypeAlignment(
+                                          SrcOp.getValueType().getTypeForMVT());
+  SDOperand FIPtr = DAG.CreateStackTemporary(SlotVT, SrcAlign);
+  
   FrameIndexSDNode *StackPtrFI = cast<FrameIndexSDNode>(FIPtr);
   int SPFI = StackPtrFI->getIndex();
-
+  
   unsigned SrcSize = SrcOp.getValueType().getSizeInBits();
   unsigned SlotSize = SlotVT.getSizeInBits();
   unsigned DestSize = DestVT.getSizeInBits();
+  unsigned DestAlign = TLI.getTargetData()->getPrefTypeAlignment(
+                                                        DestVT.getTypeForMVT());
   
   // Emit a store to the stack slot.  Use a truncstore if the input value is
   // later than DestVT.
   SDOperand Store;
+  
   if (SrcSize > SlotSize)
     Store = DAG.getTruncStore(DAG.getEntryNode(), SrcOp, FIPtr,
-                              PseudoSourceValue::getFixedStack(),
-                              SPFI, SlotVT);
+                              PseudoSourceValue::getFixedStack(), SPFI, SlotVT, 
+                              false, SrcAlign);
   else {
     assert(SrcSize == SlotSize && "Invalid store");
     Store = DAG.getStore(DAG.getEntryNode(), SrcOp, FIPtr,
-                         PseudoSourceValue::getFixedStack(),
-                         SPFI);
+                         PseudoSourceValue::getFixedStack(), SPFI,
+                         false, SrcAlign);
   }
   
   // Result is a load from the stack slot.
   if (SlotSize == DestSize)
-    return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0);
+    return DAG.getLoad(DestVT, Store, FIPtr, NULL, 0, false, DestAlign);
   
   assert(SlotSize < DestSize && "Unknown extension!");
-  return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, NULL, 0, SlotVT);
+  return DAG.getExtLoad(ISD::EXTLOAD, DestVT, Store, FIPtr, NULL, 0, SlotVT,
+                        false, DestAlign);
 }
 
 SDOperand SelectionDAGLegalize::ExpandSCALAR_TO_VECTOR(SDNode *Node) {
index c457c4bb767a60fa6c7a26e60867dc33a7d1d95c..d6a38be667f8c830686bf7fbc49fc8988d4def1d 100644 (file)
@@ -1080,16 +1080,17 @@ SDOperand SelectionDAG::getMemOperand(const MachineMemOperand &MO) {
 
 /// CreateStackTemporary - Create a stack temporary, suitable for holding the
 /// specified value type.
-SDOperand SelectionDAG::CreateStackTemporary(MVT VT) {
+SDOperand SelectionDAG::CreateStackTemporary(MVT VT, unsigned minAlign) {
   MachineFrameInfo *FrameInfo = getMachineFunction().getFrameInfo();
   unsigned ByteSize = VT.getSizeInBits()/8;
   const Type *Ty = VT.getTypeForMVT();
-  unsigned StackAlign = (unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty);
+  unsigned StackAlign =
+  std::max((unsigned)TLI.getTargetData()->getPrefTypeAlignment(Ty), minAlign);
+  
   int FrameIdx = FrameInfo->CreateStackObject(ByteSize, StackAlign);
   return getFrameIndex(FrameIdx, TLI.getPointerTy());
 }
 
-
 SDOperand SelectionDAG::FoldSetCC(MVT VT, SDOperand N1,
                                   SDOperand N2, ISD::CondCode Cond) {
   // These setcc operations always fold.