From d485e4eb5cd7cc73e9a33e904f0f3e5d032b85ee Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 9 Jun 2008 15:21:47 +0000 Subject: [PATCH] Handle empty aggregate values. llvm-svn: 52150 --- .../CodeGen/SelectionDAG/SelectionDAGISel.cpp | 43 ++++++++++--------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp index 189a1f195a98..92eee9beb9f7 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp @@ -649,10 +649,6 @@ public: void setCurrentBasicBlock(MachineBasicBlock *MBB) { CurMBB = MBB; } - SDOperand getLoadFrom(const Type *Ty, SDOperand Ptr, - const Value *SV, SDOperand Root, - bool isVolatile, unsigned Alignment); - SDOperand getValue(const Value *V); void setValue(const Value *V, SDOperand NewN) { @@ -1169,6 +1165,8 @@ SDOperand SelectionDAGLowering::getValue(const Value *V) { assert((isa(C) || isa(C)) && "Unknown array constant!"); unsigned NumElts = ATy->getNumElements(); + if (NumElts == 0) + return SDOperand(); // empty array MVT EltVT = TLI.getValueType(ATy->getElementType()); SmallVector Constants(NumElts); SmallVector ValueVTs(NumElts, EltVT); @@ -1189,6 +1187,8 @@ SDOperand SelectionDAGLowering::getValue(const Value *V) { assert((isa(C) || isa(C)) && "Unknown struct constant!"); unsigned NumElts = STy->getNumElements(); + if (NumElts == 0) + return SDOperand(); // empty struct SmallVector Constants(NumElts); SmallVector ValueVTs(NumElts); for (unsigned i = 0, e = NumElts; i != e; ++i) { @@ -2850,7 +2850,19 @@ void SelectionDAGLowering::visitAlloca(AllocaInst &I) { } void SelectionDAGLowering::visitLoad(LoadInst &I) { - SDOperand Ptr = getValue(I.getOperand(0)); + const Value *SV = I.getOperand(0); + SDOperand Ptr = getValue(SV); + + const Type *Ty = I.getType(); + bool isVolatile = I.isVolatile(); + unsigned Alignment = I.getAlignment(); + + SmallVector ValueVTs; + SmallVector Offsets; + ComputeValueVTs(TLI, Ty, ValueVTs, &Offsets); + unsigned NumValues = ValueVTs.size(); + if (NumValues == 0) + return; SDOperand Root; if (I.isVolatile()) @@ -2860,19 +2872,6 @@ void SelectionDAGLowering::visitLoad(LoadInst &I) { Root = DAG.getRoot(); } - setValue(&I, getLoadFrom(I.getType(), Ptr, I.getOperand(0), - Root, I.isVolatile(), I.getAlignment())); -} - -SDOperand SelectionDAGLowering::getLoadFrom(const Type *Ty, SDOperand Ptr, - const Value *SV, SDOperand Root, - bool isVolatile, - unsigned Alignment) { - SmallVector ValueVTs; - SmallVector Offsets; - ComputeValueVTs(TLI, Ty, ValueVTs, &Offsets); - unsigned NumValues = ValueVTs.size(); - SmallVector Values(NumValues); SmallVector Chains(NumValues); MVT PtrVT = Ptr.getValueType(); @@ -2893,9 +2892,9 @@ SDOperand SelectionDAGLowering::getLoadFrom(const Type *Ty, SDOperand Ptr, else PendingLoads.push_back(Chain); - return DAG.getNode(ISD::MERGE_VALUES, - DAG.getVTList(&ValueVTs[0], NumValues), - &Values[0], NumValues); + setValue(&I, DAG.getNode(ISD::MERGE_VALUES, + DAG.getVTList(&ValueVTs[0], NumValues), + &Values[0], NumValues)); } @@ -2909,6 +2908,8 @@ void SelectionDAGLowering::visitStore(StoreInst &I) { SmallVector Offsets; ComputeValueVTs(TLI, SrcV->getType(), ValueVTs, &Offsets); unsigned NumValues = ValueVTs.size(); + if (NumValues == 0) + return; SDOperand Root = getRoot(); SmallVector Chains(NumValues);