aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2001-12-05 19:39:15 +0000
committerChris Lattner <sabre@nondot.org>2001-12-05 19:39:15 +0000
commitac0077e1434a1b0d227ac6a3c4e4a0d0a309af28 (patch)
tree6f92c2ae04915e770dc849c0329910b8ab542ae7
parent0da29c8ec143ab319921b9686dead638a61067d8 (diff)
downloadexternal_llvm-ac0077e1434a1b0d227ac6a3c4e4a0d0a309af28.tar.gz
external_llvm-ac0077e1434a1b0d227ac6a3c4e4a0d0a309af28.tar.bz2
external_llvm-ac0077e1434a1b0d227ac6a3c4e4a0d0a309af28.zip
Fix a few bugs. Fix pessimization handling sized arrays
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1422 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/ExprTypeConvert.cpp22
1 files changed, 15 insertions, 7 deletions
diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp
index f71687abe8..7226be3b95 100644
--- a/lib/Transforms/ExprTypeConvert.cpp
+++ b/lib/Transforms/ExprTypeConvert.cpp
@@ -317,6 +317,8 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty,
Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) {
+ if (V->getType() == Ty) return V; // Already where we need to be?
+
ValueMapCache::ExprMapTy::iterator VMCI = VMC.ExprMap.find(V);
if (VMCI != VMC.ExprMap.end()) {
assert(VMCI->second->getType() == Ty);
@@ -623,17 +625,17 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty,
return ExpressionConvertableToType(I->getOperand(1), PointerType::get(Ty),
CTMap);
} else if (const PointerType *PT = dyn_cast<PointerType>(Ty)) {
- if (isa<ArrayType>(PT->getElementType()))
- return false; // Avoid getDataSize on unsized array type!
+ const Type *ElTy = PT->getElementType();
+ if (ArrayType *AT = dyn_cast<ArrayType>(ElTy))
+ ElTy = AT->getElementType(); // Avoid getDataSize on unsized array type!
assert(V == I->getOperand(1));
// Must move the same amount of data...
- if (TD.getTypeSize(PT->getElementType()) !=
- TD.getTypeSize(I->getOperand(0)->getType())) return false;
+ if (TD.getTypeSize(ElTy) != TD.getTypeSize(I->getOperand(0)->getType()))
+ return false;
// Can convert store if the incoming value is convertable...
- return ExpressionConvertableToType(I->getOperand(0), PT->getElementType(),
- CTMap);
+ return ExpressionConvertableToType(I->getOperand(0), ElTy, CTMap);
}
return false;
}
@@ -794,7 +796,13 @@ static void ConvertOperandToType(User *U, Value *OldVal, Value *NewVal,
Res->setOperand(1, ConvertExpressionToType(I->getOperand(1), NewPT, VMC));
} else { // Replace the source pointer
const Type *ValTy = cast<PointerType>(NewTy)->getElementType();
- Res = new StoreInst(Constant::getNullConstant(ValTy), NewVal);
+ vector<Value*> Indices;
+ while (ArrayType *AT = dyn_cast<ArrayType>(ValTy)) {
+ Indices.push_back(ConstantUInt::get(Type::UIntTy, 0));
+ ValTy = AT->getElementType();
+ }
+
+ Res = new StoreInst(Constant::getNullConstant(ValTy), NewVal, Indices);
VMC.ExprMap[I] = Res;
Res->setOperand(0, ConvertExpressionToType(I->getOperand(0), ValTy, VMC));
}