aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-11-09 01:08:10 +0000
committerChris Lattner <sabre@nondot.org>2001-11-09 01:08:10 +0000
commitcf1ae7cea168e59f347192b7452dc2a447745d40 (patch)
tree497197d1256d82bc76a1229193f5028d8a9c56aa /lib/Transforms
parent0bf7bad0c31194beaf743007b6f5dabb1ddca0c7 (diff)
Remove false optimization that basically broke everything
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1219 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/ExprTypeConvert.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp
index f6fdb7e187..4619c24c11 100644
--- a/lib/Transforms/ExprTypeConvert.cpp
+++ b/lib/Transforms/ExprTypeConvert.cpp
@@ -65,6 +65,8 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
// ExpressionConvertableToType - Return true if it is possible
bool ExpressionConvertableToType(Value *V, const Type *Ty,
ValueTypeCache &CTMap) {
+ if (V->getType() == Ty) return true; // Expression already correct type!
+
// Expression type must be holdable in a register.
if (!isFirstClassType(Ty))
return false;
@@ -73,16 +75,6 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
if (CTMI != CTMap.end()) return CTMI->second == Ty;
CTMap[V] = Ty;
- // Expressions are only convertable if all of the users of the expression can
- // have this value converted. This makes use of the map to avoid infinite
- // recursion.
- //
- if (isa<Instruction>(V)) {
- for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I)
- if (!OperandConvertableToType(*I, V, Ty, CTMap))
- return false;
- }
-
Instruction *I = dyn_cast<Instruction>(V);
if (I == 0) {
// It's not an instruction, check to see if it's a constant... all constants
@@ -96,7 +88,16 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
return false; // Otherwise, we can't convert!
}
- if (I->getType() == Ty) return false; // Expression already correct type!
+
+ // Expressions are only convertable if all of the users of the expression can
+ // have this value converted. This makes use of the map to avoid infinite
+ // recursion.
+ //
+ if (isa<Instruction>(V)) {
+ for (Value::use_iterator I = V->use_begin(), E = V->use_end(); I != E; ++I)
+ if (!OperandConvertableToType(*I, V, Ty, CTMap))
+ return false;
+ }
switch (I->getOpcode()) {
case Instruction::Cast:
@@ -116,7 +117,13 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
case Instruction::Load: {
LoadInst *LI = cast<LoadInst>(I);
- if (LI->hasIndices()) return false;
+ if (LI->hasIndices()) {
+ // We can't convert a load expression if it has indices... unless they are
+ // all zero.
+ const vector<ConstPoolVal*> &CPV = LI->getIndices();
+ for (unsigned i = 0; i < CPV.size(); ++i)
+ if (!CPV[i]->isNullValue()) return false;
+ }
return ExpressionConvertableToType(LI->getPtrOperand(),
PointerType::get(Ty), CTMap);
@@ -226,7 +233,15 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
case Instruction::Load: {
LoadInst *LI = cast<LoadInst>(I);
- assert(!LI->hasIndices());
+#ifndef NDEBUG
+ if (LI->hasIndices()) {
+ // We can't convert a load expression if it has indices... unless they are
+ // all zero.
+ const vector<ConstPoolVal*> &CPV = LI->getIndices();
+ for (unsigned i = 0; i < CPV.size(); ++i)
+ assert(CPV[i]->isNullValue() && "Load index not 0!");
+ }
+#endif
Res = new LoadInst(ConstPoolVal::getNullConstant(PointerType::get(Ty)),
Name);
VMC.ExprMap[I] = Res;
@@ -393,7 +408,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
}
// FALLTHROUGH
case Instruction::Sub: {
- CTMap[I] = Ty;
Value *OtherOp = I->getOperand((V == I->getOperand(0)) ? 1 : 0);
return RetValConvertableToType(I, Ty, CTMap) &&
ExpressionConvertableToType(OtherOp, Ty, CTMap);
@@ -408,7 +422,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
// FALL THROUGH
case Instruction::Shl:
assert(I->getOperand(0) == V);
- CTMap[I] = Ty;
return RetValConvertableToType(I, Ty, CTMap);
case Instruction::Load:
@@ -432,8 +445,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
// See if the leaf type is compatible with the old return type...
if (TD.getTypeSize(Ty) != TD.getTypeSize(LI->getType()))
return false;
-
- CTMap[LI] = Ty;
return RetValConvertableToType(LI, Ty, CTMap);
}
return false;
@@ -442,7 +453,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
if (TD.getTypeSize(PVTy) != TD.getTypeSize(LI->getType()))
return false;
- CTMap[LI] = PVTy;
return RetValConvertableToType(LI, PVTy, CTMap);
}
return false;
@@ -473,7 +483,6 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
}
case Instruction::PHINode: {
- CTMap[I] = Ty;
PHINode *PN = cast<PHINode>(I);
for (unsigned i = 0; i < PN->getNumIncomingValues(); ++i)
if (!ExpressionConvertableToType(PN->getIncomingValue(i), Ty, CTMap))