aboutsummaryrefslogtreecommitdiffstats
path: root/lib/VMCore
diff options
context:
space:
mode:
Diffstat (limited to 'lib/VMCore')
-rw-r--r--lib/VMCore/Constants.cpp21
-rw-r--r--lib/VMCore/Instructions.cpp44
2 files changed, 31 insertions, 34 deletions
diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp
index 1a650cc..243365e 100644
--- a/lib/VMCore/Constants.cpp
+++ b/lib/VMCore/Constants.cpp
@@ -378,10 +378,9 @@ bool ConstantExpr::isCompare() const {
/// specify the full Instruction::OPCODE identifier.
///
Constant *ConstantExpr::getNeg(Constant *C) {
- if (!C->getType()->isFloatingPoint())
- return get(Instruction::Sub, getNullValue(C->getType()), C);
- else
- return get(Instruction::Sub, ConstantFP::get(C->getType(), -0.0), C);
+ return get(Instruction::Sub,
+ ConstantExpr::getZeroValueForNegationExpr(C->getType()),
+ C);
}
Constant *ConstantExpr::getNot(Constant *C) {
assert(isa<ConstantInt>(C) && "Cannot NOT a nonintegral type!");
@@ -1882,6 +1881,20 @@ Constant *ConstantExpr::getShuffleVector(Constant *V1, Constant *V2,
return getShuffleVectorTy(V1->getType(), V1, V2, Mask);
}
+Constant *ConstantExpr::getZeroValueForNegationExpr(const Type *Ty) {
+ if ((const PackedType *PTy = dyn_cast<PackedType>(Ty)) &&
+ PTy->getElementType()->isFloatingPoint()) {
+ std::vector<Constant*> zeros(PTy->getNumElements(),
+ ConstantFP::get(PTy->getElementType(), -0.0));
+ return ConstantPacked::get(PTy, zeros);
+ }
+
+ if (Ty->isFloatingPoint())
+ return ConstantFP::get(Ty, -0.0);
+
+ return Constant::getNullValue(Ty);
+}
+
// destroyConstant - Remove the constant from the constant table...
//
void ConstantExpr::destroyConstant() {
diff --git a/lib/VMCore/Instructions.cpp b/lib/VMCore/Instructions.cpp
index f98f7cb..0d40ee7 100644
--- a/lib/VMCore/Instructions.cpp
+++ b/lib/VMCore/Instructions.cpp
@@ -1092,26 +1092,18 @@ BinaryOperator *BinaryOperator::create(BinaryOps Op, Value *S1, Value *S2,
BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
Instruction *InsertBefore) {
- if (!Op->getType()->isFloatingPoint())
- return new BinaryOperator(Instruction::Sub,
- Constant::getNullValue(Op->getType()), Op,
- Op->getType(), Name, InsertBefore);
- else
- return new BinaryOperator(Instruction::Sub,
- ConstantFP::get(Op->getType(), -0.0), Op,
- Op->getType(), Name, InsertBefore);
+ Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType());
+ return new BinaryOperator(Instruction::Sub,
+ zero, Op,
+ Op->getType(), Name, InsertBefore);
}
BinaryOperator *BinaryOperator::createNeg(Value *Op, const std::string &Name,
BasicBlock *InsertAtEnd) {
- if (!Op->getType()->isFloatingPoint())
- return new BinaryOperator(Instruction::Sub,
- Constant::getNullValue(Op->getType()), Op,
- Op->getType(), Name, InsertAtEnd);
- else
- return new BinaryOperator(Instruction::Sub,
- ConstantFP::get(Op->getType(), -0.0), Op,
- Op->getType(), Name, InsertAtEnd);
+ Value *zero = ConstantExpr::getZeroValueForNegationExpr(Op->getType());
+ return new BinaryOperator(Instruction::Sub,
+ zero, Op,
+ Op->getType(), Name, InsertAtEnd);
}
BinaryOperator *BinaryOperator::createNot(Value *Op, const std::string &Name,
@@ -1153,10 +1145,8 @@ static inline bool isConstantAllOnes(const Value *V) {
bool BinaryOperator::isNeg(const Value *V) {
if (const BinaryOperator *Bop = dyn_cast<BinaryOperator>(V))
if (Bop->getOpcode() == Instruction::Sub)
- if (!V->getType()->isFloatingPoint())
- return Bop->getOperand(0) == Constant::getNullValue(Bop->getType());
- else
- return Bop->getOperand(0) == ConstantFP::get(Bop->getType(), -0.0);
+ return Bop->getOperand(0) ==
+ ConstantExpr::getZeroValueForNegationExpr(Bop->getType());
return false;
}
@@ -1913,9 +1903,7 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
assert(Op0Ty == Op1Ty &&
"Both operands to ICmp instruction are not of the same type!");
// Check that the operands are the right type
- assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) ||
- (isa<PackedType>(Op0Ty) &&
- cast<PackedType>(Op0Ty)->getElementType()->isInteger()) &&
+ assert((Op0Ty->isInteger() || isa<PointerType>(Op0Ty)) &&
"Invalid operand types for ICmp instruction");
return;
}
@@ -1927,8 +1915,7 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
assert(Op0Ty == Op1Ty &&
"Both operands to FCmp instruction are not of the same type!");
// Check that the operands are the right type
- assert(Op0Ty->isFloatingPoint() || (isa<PackedType>(Op0Ty) &&
- cast<PackedType>(Op0Ty)->getElementType()->isFloatingPoint()) &&
+ assert(Op0Ty->isFloatingPoint() &&
"Invalid operand types for FCmp instruction");
}
@@ -1948,9 +1935,7 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
assert(Op0Ty == Op1Ty &&
"Both operands to ICmp instruction are not of the same type!");
// Check that the operands are the right type
- assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) ||
- (isa<PackedType>(Op0Ty) &&
- cast<PackedType>(Op0Ty)->getElementType()->isInteger()) &&
+ assert(Op0Ty->isInteger() || isa<PointerType>(Op0Ty) &&
"Invalid operand types for ICmp instruction");
return;
}
@@ -1962,8 +1947,7 @@ CmpInst::CmpInst(OtherOps op, unsigned short predicate, Value *LHS, Value *RHS,
assert(Op0Ty == Op1Ty &&
"Both operands to FCmp instruction are not of the same type!");
// Check that the operands are the right type
- assert(Op0Ty->isFloatingPoint() || (isa<PackedType>(Op0Ty) &&
- cast<PackedType>(Op0Ty)->getElementType()->isFloatingPoint()) &&
+ assert(Op0Ty->isFloatingPoint() &&
"Invalid operand types for FCmp instruction");
}