summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2012-02-06 21:56:39 +0000
committerChris Lattner <sabre@nondot.org>2012-02-06 21:56:39 +0000
commit7302d80490feabfc8a01bee0fa698aab55169544 (patch)
treea2e302de0cd9bbed2d37ef67132f6f43ba8587e0
parent705f4813afb13ed850386cbb4b56688abb6412ab (diff)
downloadllvm-7302d80490feabfc8a01bee0fa698aab55169544.tar.gz
llvm-7302d80490feabfc8a01bee0fa698aab55169544.tar.bz2
llvm-7302d80490feabfc8a01bee0fa698aab55169544.tar.xz
Remove some dead code and tidy things up now that vectors use ConstantDataVector
instead of always using ConstantVector. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@149912 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/PatternMatch.h23
-rw-r--r--lib/Analysis/ConstantFolding.cpp32
-rw-r--r--lib/Analysis/ValueTracking.cpp15
-rw-r--r--lib/Target/TargetLoweringObjectFile.cpp17
-rw-r--r--lib/Target/X86/X86ISelLowering.cpp12
-rw-r--r--lib/Transforms/InstCombine/InstCombineCasts.cpp15
-rw-r--r--lib/Transforms/InstCombine/InstCombineMulDivRem.cpp27
-rw-r--r--lib/Transforms/InstCombine/InstructionCombining.cpp12
-rw-r--r--lib/VMCore/ConstantFold.cpp16
9 files changed, 40 insertions, 129 deletions
diff --git a/include/llvm/Support/PatternMatch.h b/include/llvm/Support/PatternMatch.h
index 221fa8b3eb..8c68fcb691 100644
--- a/include/llvm/Support/PatternMatch.h
+++ b/include/llvm/Support/PatternMatch.h
@@ -98,13 +98,6 @@ struct apint_match {
Res = &CI->getValue();
return true;
}
- // FIXME: Remove this.
- if (ConstantVector *CV = dyn_cast<ConstantVector>(V))
- if (ConstantInt *CI =
- dyn_cast_or_null<ConstantInt>(CV->getSplatValue())) {
- Res = &CI->getValue();
- return true;
- }
if (ConstantDataVector *CV = dyn_cast<ConstantDataVector>(V))
if (ConstantInt *CI =
dyn_cast_or_null<ConstantInt>(CV->getSplatValue())) {
@@ -151,10 +144,6 @@ struct cst_pred_ty : public Predicate {
bool match(ITy *V) {
if (const ConstantInt *CI = dyn_cast<ConstantInt>(V))
return this->isValue(CI->getValue());
- // FIXME: Remove this.
- if (const ConstantVector *CV = dyn_cast<ConstantVector>(V))
- if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CV->getSplatValue()))
- return this->isValue(CI->getValue());
if (const ConstantDataVector *CV = dyn_cast<ConstantDataVector>(V))
if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CV->getSplatValue()))
return this->isValue(CI->getValue());
@@ -176,14 +165,6 @@ struct api_pred_ty : public Predicate {
return true;
}
- // FIXME: remove.
- if (const ConstantVector *CV = dyn_cast<ConstantVector>(V))
- if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CV->getSplatValue()))
- if (this->isValue(CI->getValue())) {
- Res = &CI->getValue();
- return true;
- }
-
if (const ConstantDataVector *CV = dyn_cast<ConstantDataVector>(V))
if (ConstantInt *CI = dyn_cast_or_null<ConstantInt>(CV->getSplatValue()))
if (this->isValue(CI->getValue())) {
@@ -632,9 +613,7 @@ struct not_match {
}
private:
bool matchIfNot(Value *LHS, Value *RHS) {
- return (isa<ConstantInt>(RHS) || isa<ConstantDataVector>(RHS) ||
- // FIXME: Remove CV.
- isa<ConstantVector>(RHS)) &&
+ return (isa<ConstantInt>(RHS) || isa<ConstantDataVector>(RHS)) &&
cast<Constant>(RHS)->isAllOnesValue() &&
L.match(LHS);
}
diff --git a/lib/Analysis/ConstantFolding.cpp b/lib/Analysis/ConstantFolding.cpp
index 48e75a1d5d..6e2a8d4756 100644
--- a/lib/Analysis/ConstantFolding.cpp
+++ b/lib/Analysis/ConstantFolding.cpp
@@ -54,37 +54,35 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
// Handle a vector->integer cast.
if (IntegerType *IT = dyn_cast<IntegerType>(DestTy)) {
- // FIXME: Remove ConstantVector support.
- if ((!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C)) ||
- // TODO: Handle big endian someday.
- !TD.isLittleEndian())
+ ConstantDataVector *CDV = dyn_cast<ConstantDataVector>(C);
+ if (CDV == 0)
return ConstantExpr::getBitCast(C, DestTy);
- unsigned NumSrcElts = C->getType()->getVectorNumElements();
+ unsigned NumSrcElts = CDV->getType()->getNumElements();
+
+ Type *SrcEltTy = CDV->getType()->getElementType();
// If the vector is a vector of floating point, convert it to vector of int
// to simplify things.
- if (C->getType()->getVectorElementType()->isFloatingPointTy()) {
- unsigned FPWidth =
- C->getType()->getVectorElementType()->getPrimitiveSizeInBits();
+ if (SrcEltTy->isFloatingPointTy()) {
+ unsigned FPWidth = SrcEltTy->getPrimitiveSizeInBits();
Type *SrcIVTy =
VectorType::get(IntegerType::get(C->getContext(), FPWidth), NumSrcElts);
// Ask VMCore to do the conversion now that #elts line up.
C = ConstantExpr::getBitCast(C, SrcIVTy);
+ CDV = cast<ConstantDataVector>(C);
}
// Now that we know that the input value is a vector of integers, just shift
// and insert them into our result.
- unsigned BitShift =
- TD.getTypeAllocSizeInBits(C->getType()->getVectorElementType());
+ unsigned BitShift = TD.getTypeAllocSizeInBits(SrcEltTy);
APInt Result(IT->getBitWidth(), 0);
for (unsigned i = 0; i != NumSrcElts; ++i) {
- // FIXME: Rework when we have ConstantDataVector.
- ConstantInt *Elt=dyn_cast_or_null<ConstantInt>(C->getAggregateElement(i));
- if (Elt == 0) // Elt must be a constant expr or something.
- return ConstantExpr::getBitCast(C, DestTy);
-
- Result |= Elt->getValue().zextOrSelf(IT->getBitWidth()) << i*BitShift;
+ Result <<= BitShift;
+ if (TD.isLittleEndian())
+ Result |= CDV->getElementAsInteger(NumSrcElts-i-1);
+ else
+ Result |= CDV->getElementAsInteger(i);
}
return ConstantInt::get(IT, Result);
@@ -103,7 +101,6 @@ static Constant *FoldBitCast(Constant *C, Type *DestTy,
}
// If this is a bitcast from constant vector -> vector, fold it.
- // FIXME: Remove ConstantVector support.
if (!isa<ConstantDataVector>(C) && !isa<ConstantVector>(C))
return ConstantExpr::getBitCast(C, DestTy);
@@ -350,7 +347,6 @@ static bool ReadDataFromGlobal(Constant *C, uint64_t ByteOffset,
// not reached.
}
- // FIXME: Remove ConstantVector
if (isa<ConstantArray>(C) || isa<ConstantVector>(C) ||
isa<ConstantDataSequential>(C)) {
Type *EltTy = cast<SequentialType>(C->getType())->getElementType();
diff --git a/lib/Analysis/ValueTracking.cpp b/lib/Analysis/ValueTracking.cpp
index 1a18247fdd..b5811f2e8a 100644
--- a/lib/Analysis/ValueTracking.cpp
+++ b/lib/Analysis/ValueTracking.cpp
@@ -88,19 +88,8 @@ void llvm::ComputeMaskedBits(Value *V, const APInt &Mask,
return;
}
// Handle a constant vector by taking the intersection of the known bits of
- // each element.
- // FIXME: Remove.
- if (ConstantVector *CV = dyn_cast<ConstantVector>(V)) {
- KnownZero.setAllBits(); KnownOne.setAllBits();
- for (unsigned i = 0, e = CV->getNumOperands(); i != e; ++i) {
- APInt KnownZero2(BitWidth, 0), KnownOne2(BitWidth, 0);
- ComputeMaskedBits(CV->getOperand(i), Mask, KnownZero2, KnownOne2,
- TD, Depth);
- KnownZero &= KnownZero2;
- KnownOne &= KnownOne2;
- }
- return;
- }
+ // each element. There is no real need to handle ConstantVector here, because
+ // we don't handle undef in any particularly useful way.
if (ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(V)) {
// We know that CDS must be a vector of integers. Take the intersection of
// each element.
diff --git a/lib/Target/TargetLoweringObjectFile.cpp b/lib/Target/TargetLoweringObjectFile.cpp
index ec3b1946f3..1589604346 100644
--- a/lib/Target/TargetLoweringObjectFile.cpp
+++ b/lib/Target/TargetLoweringObjectFile.cpp
@@ -77,23 +77,6 @@ static bool isSuitableForBSS(const GlobalVariable *GV, bool NoZerosInBSS) {
/// than ConstantDataSequential::isString because we allow 2 & 4 byte strings.
static bool IsNullTerminatedString(const Constant *C) {
// First check: is we have constant array terminated with zero
- if (const ConstantArray *CVA = dyn_cast<ConstantArray>(C)) {
- ArrayType *ATy = cast<ArrayType>(C->getType());
- if (ATy->getNumElements() == 0) return false;
-
- ConstantInt *Null =
- dyn_cast<ConstantInt>(CVA->getOperand(ATy->getNumElements()-1));
- if (Null == 0 || !Null->isZero())
- return false; // Not null terminated.
-
- // Verify that the null doesn't occur anywhere else in the string.
- for (unsigned i = 0, e = ATy->getNumElements()-1; i != e; ++i)
- // Reject constantexpr elements etc.
- if (!isa<ConstantInt>(CVA->getOperand(i)) ||
- CVA->getOperand(i) == Null)
- return false;
- return true;
- }
if (const ConstantDataSequential *CDS = dyn_cast<ConstantDataSequential>(C)) {
unsigned NumElts = CDS->getNumElements();
assert(NumElts != 0 && "Can't have an empty CDS");
diff --git a/lib/Target/X86/X86ISelLowering.cpp b/lib/Target/X86/X86ISelLowering.cpp
index 0310a15b1d..8bf72d15e8 100644
--- a/lib/Target/X86/X86ISelLowering.cpp
+++ b/lib/Target/X86/X86ISelLowering.cpp
@@ -7527,12 +7527,8 @@ SDValue X86TargetLowering::LowerUINT_TO_FP_i64(SDValue Op,
LLVMContext *Context = DAG.getContext();
// Build some magic constants.
- SmallVector<Constant*,4> CV0;
- CV0.push_back(ConstantInt::get(*Context, APInt(32, 0x43300000)));
- CV0.push_back(ConstantInt::get(*Context, APInt(32, 0x45300000)));
- CV0.push_back(ConstantInt::get(*Context, APInt(32, 0)));
- CV0.push_back(ConstantInt::get(*Context, APInt(32, 0)));
- Constant *C0 = ConstantVector::get(CV0);
+ const uint32_t CV0[] = { 0x43300000, 0x45300000, 0, 0 };
+ Constant *C0 = ConstantDataVector::get(*Context, CV0);
SDValue CPIdx0 = DAG.getConstantPool(C0, getPointerTy(), 16);
SmallVector<Constant*,2> CV1;
@@ -10249,8 +10245,8 @@ SDValue X86TargetLowering::LowerShift(SDValue Op, SelectionDAG &DAG) const {
Op = DAG.getNode(X86ISD::VSHLI, dl, VT, Op.getOperand(1),
DAG.getConstant(23, MVT::i32));
- ConstantInt *CI = ConstantInt::get(*Context, APInt(32, 0x3f800000U));
- Constant *C = ConstantVector::getSplat(4, CI);
+ const uint32_t CV[] = { 0x3f800000U, 0x3f800000U, 0x3f800000U, 0x3f800000U};
+ Constant *C = ConstantDataVector::get(*Context, CV);
SDValue CPIdx = DAG.getConstantPool(C, getPointerTy(), 16);
SDValue Addend = DAG.getLoad(VT, dl, DAG.getEntryNode(), CPIdx,
MachinePointerInfo::getConstantPool(),
diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp
index f5a7629e2e..c5ddb75dbf 100644
--- a/lib/Transforms/InstCombine/InstCombineCasts.cpp
+++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp
@@ -1421,16 +1421,15 @@ static Instruction *OptimizeVectorResize(Value *InVal, VectorType *DestTy,
// Now that the element types match, get the shuffle mask and RHS of the
// shuffle to use, which depends on whether we're increasing or decreasing the
// size of the input.
- SmallVector<Constant*, 16> ShuffleMask;
+ SmallVector<uint32_t, 16> ShuffleMask;
Value *V2;
- IntegerType *Int32Ty = Type::getInt32Ty(SrcTy->getContext());
if (SrcTy->getNumElements() > DestTy->getNumElements()) {
// If we're shrinking the number of elements, just shuffle in the low
// elements from the input and use undef as the second shuffle input.
V2 = UndefValue::get(SrcTy);
for (unsigned i = 0, e = DestTy->getNumElements(); i != e; ++i)
- ShuffleMask.push_back(ConstantInt::get(Int32Ty, i));
+ ShuffleMask.push_back(i);
} else {
// If we're increasing the number of elements, shuffle in all of the
@@ -1439,14 +1438,16 @@ static Instruction *OptimizeVectorResize(Value *InVal, VectorType *DestTy,
V2 = Constant::getNullValue(SrcTy);
unsigned SrcElts = SrcTy->getNumElements();
for (unsigned i = 0, e = SrcElts; i != e; ++i)
- ShuffleMask.push_back(ConstantInt::get(Int32Ty, i));
+ ShuffleMask.push_back(i);
// The excess elements reference the first element of the zero input.
- ShuffleMask.append(DestTy->getNumElements()-SrcElts,
- ConstantInt::get(Int32Ty, SrcElts));
+ for (unsigned i = 0, e = DestTy->getNumElements()-SrcElts; i != e; ++i)
+ ShuffleMask.push_back(SrcElts);
}
- return new ShuffleVectorInst(InVal, V2, ConstantVector::get(ShuffleMask));
+ return new ShuffleVectorInst(InVal, V2,
+ ConstantDataVector::get(V2->getContext(),
+ ShuffleMask));
}
static bool isMultipleOfTypeSize(unsigned Value, Type *Ty) {
diff --git a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
index 60be1ddca2..5168e2a113 100644
--- a/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
+++ b/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp
@@ -256,31 +256,18 @@ Instruction *InstCombiner::visitFMul(BinaryOperator &I) {
bool Changed = SimplifyAssociativeOrCommutative(I);
Value *Op0 = I.getOperand(0), *Op1 = I.getOperand(1);
- // Simplify mul instructions with a constant RHS...
+ // Simplify mul instructions with a constant RHS.
if (Constant *Op1C = dyn_cast<Constant>(Op1)) {
if (ConstantFP *Op1F = dyn_cast<ConstantFP>(Op1C)) {
// "In IEEE floating point, x*1 is not equivalent to x for nans. However,
// ANSI says we can drop signals, so we can do this anyway." (from GCC)
if (Op1F->isExactlyValue(1.0))
return ReplaceInstUsesWith(I, Op0); // Eliminate 'fmul double %X, 1.0'
- } else if (Op1C->getType()->isVectorTy()) {
- // FIXME: Remove.
- if (ConstantVector *Op1V = dyn_cast<ConstantVector>(Op1C)) {
- // As above, vector X*splat(1.0) -> X in all defined cases.
- if (Constant *Splat = Op1V->getSplatValue()) {
- if (ConstantFP *F = dyn_cast<ConstantFP>(Splat))
- if (F->isExactlyValue(1.0))
- return ReplaceInstUsesWith(I, Op0);
- }
- }
- if (ConstantDataVector *Op1V = dyn_cast<ConstantDataVector>(Op1C)) {
- // As above, vector X*splat(1.0) -> X in all defined cases.
- if (Constant *Splat = Op1V->getSplatValue()) {
- if (ConstantFP *F = dyn_cast<ConstantFP>(Splat))
- if (F->isExactlyValue(1.0))
- return ReplaceInstUsesWith(I, Op0);
- }
- }
+ } else if (ConstantDataVector *Op1V = dyn_cast<ConstantDataVector>(Op1C)) {
+ // As above, vector X*splat(1.0) -> X in all defined cases.
+ if (ConstantFP *F = dyn_cast_or_null<ConstantFP>(Op1V->getSplatValue()))
+ if (F->isExactlyValue(1.0))
+ return ReplaceInstUsesWith(I, Op0);
}
// Try to fold constant mul into select arguments.
@@ -718,7 +705,7 @@ Instruction *InstCombiner::visitSRem(BinaryOperator &I) {
if (hasNegative && !hasMissing) {
SmallVector<Constant *, 16> Elts(VWidth);
for (unsigned i = 0; i != VWidth; ++i) {
- Elts[i] = C->getAggregateElement(i);
+ Elts[i] = C->getAggregateElement(i); // Handle undef, etc.
if (ConstantInt *RHS = dyn_cast<ConstantInt>(Elts[i])) {
if (RHS->isNegative())
Elts[i] = cast<ConstantInt>(ConstantExpr::getNeg(RHS));
diff --git a/lib/Transforms/InstCombine/InstructionCombining.cpp b/lib/Transforms/InstCombine/InstructionCombining.cpp
index 0294d2a5ac..318256a9b7 100644
--- a/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -495,10 +495,8 @@ Value *InstCombiner::dyn_castNegVal(Value *V) const {
if (ConstantInt *C = dyn_cast<ConstantInt>(V))
return ConstantExpr::getNeg(C);
- if (Constant *C = dyn_cast<Constant>(V))
- // FIXME: Remove ConstantVector
- if ((isa<ConstantVector>(C) || isa<ConstantDataVector>(C)) &&
- C->getType()->getVectorElementType()->isIntegerTy())
+ if (ConstantDataVector *C = dyn_cast<ConstantDataVector>(V))
+ if (C->getType()->getElementType()->isIntegerTy())
return ConstantExpr::getNeg(C);
return 0;
@@ -516,10 +514,8 @@ Value *InstCombiner::dyn_castFNegVal(Value *V) const {
if (ConstantFP *C = dyn_cast<ConstantFP>(V))
return ConstantExpr::getFNeg(C);
- if (Constant *C = dyn_cast<Constant>(V))
- // FIXME: Remove ConstantVector
- if ((isa<ConstantVector>(C) || isa<ConstantDataVector>(C)) &&
- C->getType()->getVectorElementType()->isFloatingPointTy())
+ if (ConstantDataVector *C = dyn_cast<ConstantDataVector>(V))
+ if (C->getType()->getElementType()->isFloatingPointTy())
return ConstantExpr::getFNeg(C);
return 0;
diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp
index f73e7a76d1..b743287adf 100644
--- a/lib/VMCore/ConstantFold.cpp
+++ b/lib/VMCore/ConstantFold.cpp
@@ -693,7 +693,6 @@ Constant *llvm::ConstantFoldSelectInstruction(Constant *Cond,
if (Cond->isNullValue()) return V2;
if (Cond->isAllOnesValue()) return V1;
- // FIXME: Remove ConstantVector
// If the condition is a vector constant, fold the result elementwise.
if (ConstantVector *CondV = dyn_cast<ConstantVector>(Cond)) {
SmallVector<Constant*, 16> Result;
@@ -710,21 +709,6 @@ Constant *llvm::ConstantFoldSelectInstruction(Constant *Cond,
if (Result.size() == V1->getType()->getVectorNumElements())
return ConstantVector::get(Result);
}
- if (ConstantDataVector *CondV = dyn_cast<ConstantDataVector>(Cond)) {
- SmallVector<Constant*, 16> Result;
- for (unsigned i = 0, e = V1->getType()->getVectorNumElements(); i != e;++i){
- uint64_t Cond = CondV->getElementAsInteger(i);
-
- Constant *Res = (Cond ? V2 : V1)->getAggregateElement(i);
- if (Res == 0) break;
- Result.push_back(Res);
- }
-
- // If we were able to build the vector, return it.
- if (Result.size() == V1->getType()->getVectorNumElements())
- return ConstantVector::get(Result);
- }
-
if (isa<UndefValue>(Cond)) {
if (isa<UndefValue>(V1)) return V1;