aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-08-03 22:07:33 +0000
committerDan Gohman <gohman@apple.com>2009-08-03 22:07:33 +0000
commit43ee5f7c08bd5a91cdd8681df20a7d1df26a1024 (patch)
tree2819e322a8671fd4e7a69ca28c325fe819735a43 /lib
parentc8bfb7a49d6de5a6259df7cbf3b320f232b0d022 (diff)
Add a new Constant::getIntegerValue helper function, and convert a
few places in InstCombine to use it, to fix problems handling pointer types. This fixes the recent llvm-gcc bootstrap error. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78005 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp12
-rw-r--r--lib/VMCore/Constants.cpp17
2 files changed, 21 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 4d2248e291..b9b4ccb6cf 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -1014,8 +1014,8 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) {
// all known
if ((RHSKnownOne & LHSKnownOne) == RHSKnownOne) {
- Constant *AndC = ConstantInt::get(VTy,
- ~RHSKnownOne & DemandedMask);
+ Constant *AndC = Constant::getIntegerValue(VTy,
+ ~RHSKnownOne & DemandedMask);
Instruction *And =
BinaryOperator::CreateAnd(I->getOperand(0), AndC, "tmp");
return InsertNewInstBefore(And, *I);
@@ -1406,12 +1406,8 @@ Value *InstCombiner::SimplifyDemandedUseBits(Value *V, APInt DemandedMask,
// If the client is only demanding bits that we know, return the known
// constant.
- if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask) {
- Constant *C = ConstantInt::get(VTy, RHSKnownOne);
- if (isa<PointerType>(V->getType()))
- C = ConstantExpr::getIntToPtr(C, V->getType());
- return C;
- }
+ if ((DemandedMask & (RHSKnownZero|RHSKnownOne)) == DemandedMask)
+ return Constant::getIntegerValue(VTy, RHSKnownOne);
return false;
}
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 7482154d83..e02e28a87e 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -70,6 +70,23 @@ Constant* Constant::getNullValue(const Type* Ty) {
}
}
+Constant* Constant::getIntegerValue(const Type* Ty, const APInt &V) {
+ const Type *ScalarTy = Ty->getScalarType();
+
+ // Create the base integer constant.
+ Constant *C = ConstantInt::get(Ty->getContext(), V);
+
+ // Convert an integer to a pointer, if necessary.
+ if (const PointerType *PTy = dyn_cast<PointerType>(ScalarTy))
+ C = ConstantExpr::getIntToPtr(C, PTy);
+
+ // Broadcast a scalar to a vector, if necessary.
+ if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
+ C = ConstantVector::get(std::vector<Constant *>(VTy->getNumElements(), C));
+
+ return C;
+}
+
Constant* Constant::getAllOnesValue(const Type* Ty) {
if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
return ConstantInt::get(Ty->getContext(),