diff options
author | Chris Lattner <sabre@nondot.org> | 2012-01-25 05:34:41 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2012-01-25 05:34:41 +0000 |
commit | 2ce8842641cc312628c4be836d34eb250e7c3f78 (patch) | |
tree | f204b808d00b11ad8e019e6698597cee33503640 /lib/CodeGen/CGExprScalar.cpp | |
parent | 9eb10ccab6bc1983ec25c65c3dd6fe2a0385103d (diff) |
reapply r148902:
"use the new ConstantVector::getSplat method where it makes sense."
Also simplify a bunch of code to use the Builder->getInt32 instead
of doing it the hard and ugly way. Much more progress could be made
here, but I don't plan to do it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148926 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/CodeGen/CGExprScalar.cpp')
-rw-r--r-- | lib/CodeGen/CGExprScalar.cpp | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/lib/CodeGen/CGExprScalar.cpp b/lib/CodeGen/CGExprScalar.cpp index e1342d3ce5..1833a9083d 100644 --- a/lib/CodeGen/CGExprScalar.cpp +++ b/lib/CodeGen/CGExprScalar.cpp @@ -610,12 +610,9 @@ Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, UnV = Builder.CreateInsertElement(UnV, Elt, Idx); // Splat the element across to all elements - SmallVector<llvm::Constant*, 16> Args; unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements(); - for (unsigned i = 0; i != NumElements; ++i) - Args.push_back(Builder.getInt32(0)); - - llvm::Constant *Mask = llvm::ConstantVector::get(Args); + llvm::Constant *Mask = llvm::ConstantVector::getSplat(NumElements, + Builder.getInt32(0)); llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat"); return Yay; } @@ -749,11 +746,8 @@ Value *ScalarExprEmitter::VisitShuffleVectorExpr(ShuffleVectorExpr *E) { (1 << llvm::Log2_32(LHSElts))-1); // Mask off the high bits of each shuffle index. - SmallVector<llvm::Constant *, 32> MaskV; - for (unsigned i = 0, e = MTy->getNumElements(); i != e; ++i) - MaskV.push_back(EltMask); - - Value* MaskBits = llvm::ConstantVector::get(MaskV); + Value *MaskBits = llvm::ConstantVector::getSplat(MTy->getNumElements(), + EltMask); Mask = Builder.CreateAnd(Mask, MaskBits, "mask"); // newv = undef @@ -1203,13 +1197,9 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) { UnV = Builder.CreateInsertElement(UnV, Elt, Idx); // Splat the element across to all elements - SmallVector<llvm::Constant*, 16> Args; unsigned NumElements = cast<llvm::VectorType>(DstTy)->getNumElements(); llvm::Constant *Zero = Builder.getInt32(0); - for (unsigned i = 0; i < NumElements; i++) - Args.push_back(Zero); - - llvm::Constant *Mask = llvm::ConstantVector::get(Args); + llvm::Constant *Mask = llvm::ConstantVector::getSplat(NumElements, Zero); llvm::Value *Yay = Builder.CreateShuffleVector(UnV, UnV, Mask, "splat"); return Yay; } @@ -2596,11 +2586,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { unsigned numElem = vecTy->getNumElements(); llvm::Type *elemType = vecTy->getElementType(); - std::vector<llvm::Constant*> Zvals; - for (unsigned i = 0; i < numElem; ++i) - Zvals.push_back(llvm::ConstantInt::get(elemType, 0)); - - llvm::Value *zeroVec = llvm::ConstantVector::get(Zvals); + llvm::Value *zeroVec = llvm::Constant::getNullValue(vecTy); llvm::Value *TestMSB = Builder.CreateICmpSLT(CondV, zeroVec); llvm::Value *tmp = Builder.CreateSExt(TestMSB, llvm::VectorType::get(elemType, |