[llvm-commits] CVS: llvm/lib/VMCore/Constants.cpp Instructions.cpp
Reid Spencer
reid at x10sys.com
Sat Jan 20 16:30:04 PST 2007
Changes in directory llvm/lib/VMCore:
Constants.cpp updated: 1.202 -> 1.203
Instructions.cpp updated: 1.64 -> 1.65
---
Log message:
For PR970: http://llvm.org/PR970 :
Clean up handling of isFloatingPoint() and dealing with PackedType.
Patch by Gordon Henriksen!
---
Diffs of the changes: (+31 -34)
Constants.cpp | 21 +++++++++++++++++----
Instructions.cpp | 44 ++++++++++++++------------------------------
2 files changed, 31 insertions(+), 34 deletions(-)
Index: llvm/lib/VMCore/Constants.cpp
diff -u llvm/lib/VMCore/Constants.cpp:1.202 llvm/lib/VMCore/Constants.cpp:1.203
--- llvm/lib/VMCore/Constants.cpp:1.202 Fri Jan 19 15:13:56 2007
+++ llvm/lib/VMCore/Constants.cpp Sat Jan 20 18:29:26 2007
@@ -378,10 +378,9 @@
/// 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 @@
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() {
Index: llvm/lib/VMCore/Instructions.cpp
diff -u llvm/lib/VMCore/Instructions.cpp:1.64 llvm/lib/VMCore/Instructions.cpp:1.65
--- llvm/lib/VMCore/Instructions.cpp:1.64 Tue Jan 16 20:46:11 2007
+++ llvm/lib/VMCore/Instructions.cpp Sat Jan 20 18:29:26 2007
@@ -1092,26 +1092,18 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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");
}
More information about the llvm-commits
mailing list