diff options
author | Chris Lattner <sabre@nondot.org> | 2001-11-14 11:02:49 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2001-11-14 11:02:49 +0000 |
commit | d5b48ca422089a17fa6ba2945d3f8b46fff7d689 (patch) | |
tree | b15922c1bc493fbcc56e16ac2b4963d91845c9f5 /lib/Transforms/ExprTypeConvert.cpp | |
parent | 84dce16fb193b46d473dc4165f2ca71bd0f622d1 (diff) |
Better heuristics for handling arrays
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1296 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/ExprTypeConvert.cpp')
-rw-r--r-- | lib/Transforms/ExprTypeConvert.cpp | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp index 8379115350..f8052b2494 100644 --- a/lib/Transforms/ExprTypeConvert.cpp +++ b/lib/Transforms/ExprTypeConvert.cpp @@ -95,7 +95,17 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty, // We can convert the expr if the cast destination type is losslessly // convertable to the requested type. if (!losslessCastableTypes(Ty, I->getType())) return false; - break; +#if 1 + // We also do not allow conversion of a cast that casts from a ptr to array + // of X to a *X. For example: cast [4 x %List *] * %val to %List * * + // + if (PointerType *SPT = dyn_cast<PointerType>(I->getOperand(0)->getType())) + if (PointerType *DPT = dyn_cast<PointerType>(I->getType())) + if (ArrayType *AT = dyn_cast<ArrayType>(SPT->getValueType())) + if (AT->getElementType() == DPT->getValueType()) + return false; +#endif + return true; case Instruction::Add: case Instruction::Sub: @@ -395,6 +405,7 @@ bool RetValConvertableToType(Value *V, const Type *Ty, // static bool OperandConvertableToType(User *U, Value *V, const Type *Ty, ValueTypeCache &CTMap) { + // TODO: IS THIS A BUG???? if (V->getType() == Ty) return true; // Already the right type? // Expression type must be holdable in a register. @@ -409,7 +420,19 @@ static bool OperandConvertableToType(User *U, Value *V, const Type *Ty, assert(I->getOperand(0) == V); // We can convert the expr if the cast destination type is losslessly // convertable to the requested type. - return losslessCastableTypes(Ty, I->getOperand(0)->getType()); + if (!losslessCastableTypes(Ty, I->getOperand(0)->getType())) + return false; +#if 1 + // We also do not allow conversion of a cast that casts from a ptr to array + // of X to a *X. For example: cast [4 x %List *] * %val to %List * * + // + if (PointerType *SPT = dyn_cast<PointerType>(I->getOperand(0)->getType())) + if (PointerType *DPT = dyn_cast<PointerType>(I->getType())) + if (ArrayType *AT = dyn_cast<ArrayType>(SPT->getValueType())) + if (AT->getElementType() == DPT->getValueType()) + return false; +#endif + return true; case Instruction::Add: if (V == I->getOperand(0) && isa<CastInst>(I->getOperand(1))) { |