aboutsummaryrefslogtreecommitdiffstats
path: root/lib/IR/Constants.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/IR/Constants.cpp')
-rw-r--r--lib/IR/Constants.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/IR/Constants.cpp b/lib/IR/Constants.cpp
index 70f7e01..2c6971c 100644
--- a/lib/IR/Constants.cpp
+++ b/lib/IR/Constants.cpp
@@ -53,12 +53,9 @@ bool Constant::isNegativeZeroValue() const {
if (SplatCFP && SplatCFP->isZero() && SplatCFP->isNegative())
return true;
- // However, vectors of zeroes which are floating point represent +0.0's.
- if (const ConstantAggregateZero *CAZ = dyn_cast<ConstantAggregateZero>(this))
- if (const VectorType *VT = dyn_cast<VectorType>(CAZ->getType()))
- if (VT->getElementType()->isFloatingPointTy())
- // As it's a CAZ, we know it's the zero bit-pattern (ie, +0.0) in each element.
- return false;
+ // We've already handled true FP case; any other FP vectors can't represent -0.0.
+ if (getType()->isFPOrFPVectorTy())
+ return false;
// Otherwise, just use +0.0.
return isNullValue();
@@ -240,18 +237,21 @@ void Constant::destroyConstantImpl() {
delete this;
}
-/// canTrap - Return true if evaluation of this constant could trap. This is
-/// true for things like constant expressions that could divide by zero.
-bool Constant::canTrap() const {
- assert(getType()->isFirstClassType() && "Cannot evaluate aggregate vals!");
+static bool canTrapImpl(const Constant *C,
+ SmallPtrSet<const ConstantExpr *, 4> &NonTrappingOps) {
+ assert(C->getType()->isFirstClassType() && "Cannot evaluate aggregate vals!");
// The only thing that could possibly trap are constant exprs.
- const ConstantExpr *CE = dyn_cast<ConstantExpr>(this);
- if (!CE) return false;
+ const ConstantExpr *CE = dyn_cast<ConstantExpr>(C);
+ if (!CE)
+ return false;
// ConstantExpr traps if any operands can trap.
- for (unsigned i = 0, e = getNumOperands(); i != e; ++i)
- if (CE->getOperand(i)->canTrap())
- return true;
+ for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) {
+ if (ConstantExpr *Op = dyn_cast<ConstantExpr>(CE->getOperand(i))) {
+ if (NonTrappingOps.insert(Op) && canTrapImpl(Op, NonTrappingOps))
+ return true;
+ }
+ }
// Otherwise, only specific operations can trap.
switch (CE->getOpcode()) {
@@ -270,6 +270,13 @@ bool Constant::canTrap() const {
}
}
+/// canTrap - Return true if evaluation of this constant could trap. This is
+/// true for things like constant expressions that could divide by zero.
+bool Constant::canTrap() const {
+ SmallPtrSet<const ConstantExpr *, 4> NonTrappingOps;
+ return canTrapImpl(this, NonTrappingOps);
+}
+
/// isThreadDependent - Return true if the value can vary between threads.
bool Constant::isThreadDependent() const {
SmallPtrSet<const Constant*, 64> Visited;