use ConstantVector::getSplat in a few places.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@148929 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2012-01-25 06:02:56 +00:00
parent 4bb3f34b22
commit 4ca829e895
6 changed files with 23 additions and 53 deletions

View File

@ -1699,7 +1699,7 @@ SDValue SelectionDAGLegalize::ExpandBUILD_VECTOR(SDNode *Node) {
// If all elements are constants, create a load from the constant pool. // If all elements are constants, create a load from the constant pool.
if (isConstant) { if (isConstant) {
std::vector<Constant*> CV; SmallVector<Constant*, 16> CV;
for (unsigned i = 0, e = NumElems; i != e; ++i) { for (unsigned i = 0, e = NumElems; i != e; ++i) {
if (ConstantFPSDNode *V = if (ConstantFPSDNode *V =
dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) { dyn_cast<ConstantFPSDNode>(Node->getOperand(i))) {

View File

@ -7591,12 +7591,8 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op,
Constant *C0 = ConstantVector::get(CV0); Constant *C0 = ConstantVector::get(CV0);
SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 16); SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 16);
SmallVector<Constant*,2> CV1; Constant *C1 = ConstantVector::getSplat(2,
CV1.push_back( ConstantFP::get(*Context, APFloat(APInt(64, 0x4330000000000000ULL))));
ConstantFP::get(*Context, APFloat(APInt(64, 0x4330000000000000ULL))));
CV1.push_back(
ConstantFP::get(*Context, APFloat(APInt(64, 0x4530000000000000ULL))));
Constant *C1 = ConstantVector::get(CV1);
SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16); SDValue CPIdx1 = DAG.getConstantPool(C1, getPointerTy(), 16);
// Load the 64-bit value into an XMM register. // Load the 64-bit value into an XMM register.
@ -7878,15 +7874,14 @@ SDValue X86TargetLowering::LowerFABS(SDValue Op,
EVT EltVT = VT; EVT EltVT = VT;
if (VT.isVector()) if (VT.isVector())
EltVT = VT.getVectorElementType(); EltVT = VT.getVectorElementType();
SmallVector<Constant*,4> CV; Constant *C;
if (EltVT == MVT::f64) { if (EltVT == MVT::f64) {
Constant *C = ConstantFP::get(*Context, APFloat(APInt(64, ~(1ULL << 63)))); C = ConstantVector::getSplat(2,
CV.assign(2, C); ConstantFP::get(*Context, APFloat(APInt(64, ~(1ULL << 63)))));
} else { } else {
Constant *C = ConstantFP::get(*Context, APFloat(APInt(32, ~(1U << 31)))); C = ConstantVector::getSplat(4,
CV.assign(4, C); ConstantFP::get(*Context, APFloat(APInt(32, ~(1U << 31)))));
} }
Constant *C = ConstantVector::get(CV);
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx, SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
MachinePointerInfo::getConstantPool(), MachinePointerInfo::getConstantPool(),
@ -7904,15 +7899,12 @@ SDValue X86TargetLowering::LowerFNEG(SDValue Op, SelectionDAG &DAG) const {
EltVT = VT.getVectorElementType(); EltVT = VT.getVectorElementType();
NumElts = VT.getVectorNumElements(); NumElts = VT.getVectorNumElements();
} }
SmallVector<Constant*,8> CV; Constant *C;
if (EltVT == MVT::f64) { if (EltVT == MVT::f64)
Constant *C = ConstantFP::get(*Context, APFloat(APInt(64, 1ULL << 63))); C = ConstantFP::get(*Context, APFloat(APInt(64, 1ULL << 63)));
CV.assign(NumElts, C); else
} else { C = ConstantFP::get(*Context, APFloat(APInt(32, 1U << 31)));
Constant *C = ConstantFP::get(*Context, APFloat(APInt(32, 1U << 31))); C = ConstantVector::getSplat(NumElts, C);
CV.assign(NumElts, C);
}
Constant *C = ConstantVector::get(CV);
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx, SDValue Mask = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
MachinePointerInfo::getConstantPool(), MachinePointerInfo::getConstantPool(),
@ -10149,9 +10141,7 @@ SDValue X86TargetLowering::LowerShift(SDValue Op, SelectionDAG &DAG) const {
DAG.getConstant(23, MVT::i32)); DAG.getConstant(23, MVT::i32));
ConstantInt *CI = ConstantInt::get(*Context, APInt(32, 0x3f800000U)); ConstantInt *CI = ConstantInt::get(*Context, APInt(32, 0x3f800000U));
Constant *C = ConstantVector::getSplat(4, CI);
std::vector<Constant*> CV(4, CI);
Constant *C = ConstantVector::get(CV);
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16); SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
SDValue Addend = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx, SDValue Addend = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
MachinePointerInfo::getConstantPool(), MachinePointerInfo::getConstantPool(),

View File

@ -698,7 +698,7 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
hasNegative = true; hasNegative = true;
if (hasNegative) { if (hasNegative) {
std::vector<Constant *> Elts(VWidth); SmallVector<Constant *, 16> Elts(VWidth);
for (unsigned i = 0; i != VWidth; ++i) { for (unsigned i = 0; i != VWidth; ++i) {
if (ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV->getOperand(i))) { if (ConstantInt *RHS = dyn_cast<ConstantInt>(RHSV->getOperand(i))) {
if (RHS->isNegative()) if (RHS->isNegative())

View File

@ -851,8 +851,8 @@ Value *InstCombiner::SimplifyDemandedVectorElts(Value *V, APInt DemandedElts,
} }
// If we changed the constant, return it. // If we changed the constant, return it.
Constant *NewCP = ConstantVector::get(Elts); Constant *NewCV = ConstantVector::get(Elts);
return NewCP != CV ? NewCP : 0; return NewCV != CV ? NewCV : 0;
} }
if (ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(V)) { if (ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(V)) {

View File

@ -2157,8 +2157,7 @@ void SROA::RewriteMemIntrinUserOfAlloca(MemIntrinsic *MI, Instruction *Inst,
// If the requested value was a vector constant, create it. // If the requested value was a vector constant, create it.
if (EltTy->isVectorTy()) { if (EltTy->isVectorTy()) {
unsigned NumElts = cast<VectorType>(EltTy)->getNumElements(); unsigned NumElts = cast<VectorType>(EltTy)->getNumElements();
SmallVector<Constant*, 16> Elts(NumElts, StoreVal); StoreVal = ConstantVector::getSplat(NumElts, StoreVal);
StoreVal = ConstantVector::get(Elts);
} }
} }
new StoreInst(StoreVal, EltPtr, MI); new StoreInst(StoreVal, EltPtr, MI);

View File

@ -1873,46 +1873,27 @@ BinaryOperator *BinaryOperator::CreateNUWNeg(Value *Op, const Twine &Name,
BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name, BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name,
Instruction *InsertBefore) { Instruction *InsertBefore) {
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType()); Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
return new BinaryOperator(Instruction::FSub, return new BinaryOperator(Instruction::FSub, zero, Op,
zero, Op,
Op->getType(), Name, InsertBefore); Op->getType(), Name, InsertBefore);
} }
BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name, BinaryOperator *BinaryOperator::CreateFNeg(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd) { BasicBlock *InsertAtEnd) {
Value *zero = ConstantFP::getZeroValueForNegation(Op->getType()); Value *zero = ConstantFP::getZeroValueForNegation(Op->getType());
return new BinaryOperator(Instruction::FSub, return new BinaryOperator(Instruction::FSub, zero, Op,
zero, Op,
Op->getType(), Name, InsertAtEnd); Op->getType(), Name, InsertAtEnd);
} }
BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name, BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name,
Instruction *InsertBefore) { Instruction *InsertBefore) {
Constant *C; Constant *C = Constant::getAllOnesValue(Op->getType());
if (VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
C = Constant::getAllOnesValue(PTy->getElementType());
C = ConstantVector::get(
std::vector<Constant*>(PTy->getNumElements(), C));
} else {
C = Constant::getAllOnesValue(Op->getType());
}
return new BinaryOperator(Instruction::Xor, Op, C, return new BinaryOperator(Instruction::Xor, Op, C,
Op->getType(), Name, InsertBefore); Op->getType(), Name, InsertBefore);
} }
BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name, BinaryOperator *BinaryOperator::CreateNot(Value *Op, const Twine &Name,
BasicBlock *InsertAtEnd) { BasicBlock *InsertAtEnd) {
Constant *AllOnes; Constant *AllOnes = Constant::getAllOnesValue(Op->getType());
if (VectorType *PTy = dyn_cast<VectorType>(Op->getType())) {
// Create a vector of all ones values.
Constant *Elt = Constant::getAllOnesValue(PTy->getElementType());
AllOnes = ConstantVector::get(
std::vector<Constant*>(PTy->getNumElements(), Elt));
} else {
AllOnes = Constant::getAllOnesValue(Op->getType());
}
return new BinaryOperator(Instruction::Xor, Op, AllOnes, return new BinaryOperator(Instruction::Xor, Op, AllOnes,
Op->getType(), Name, InsertAtEnd); Op->getType(), Name, InsertAtEnd);
} }