From 38dc4f06af12a16efb52ee09d63182cd6a1775c6 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 4 Nov 2002 05:46:37 +0000 Subject: [PATCH] Be more generous about level raising constant expressions don't force each constant to one particular type. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@4525 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/ExprTypeConvert.cpp | 44 ++++++++++++++---------------- 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/lib/Transforms/ExprTypeConvert.cpp b/lib/Transforms/ExprTypeConvert.cpp index 28b92896a88..aa183d24ebf 100644 --- a/lib/Transforms/ExprTypeConvert.cpp +++ b/lib/Transforms/ExprTypeConvert.cpp @@ -139,22 +139,18 @@ bool ExpressionConvertableToType(Value *V, const Type *Ty, ValueTypeCache::iterator CTMI = CTMap.find(V); if (CTMI != CTMap.end()) return CTMI->second == Ty; + // If it's a constant... all constants can be converted to a different type We + // just ask the constant propogator to see if it can convert the value... + // + if (Constant *CPV = dyn_cast(V)) + return ConstantFoldCastInstruction(CPV, Ty); + + CTMap[V] = Ty; if (V->getType() == Ty) return true; // Expression already correct type! Instruction *I = dyn_cast(V); - if (I == 0) { - // It's not an instruction, check to see if it's a constant... all constants - // can be converted to an equivalent value (except pointers, they can't be - // const prop'd in general). We just ask the constant propogator to see if - // it can convert the value... - // - if (Constant *CPV = dyn_cast(V)) - if (ConstantFoldCastInstruction(CPV, Ty)) - return true; // Don't worry about deallocating, it's a constant. - - return false; // Otherwise, we can't convert! - } + if (I == 0) return false; // Otherwise, we can't convert! switch (I->getOpcode()) { case Instruction::Cast: @@ -323,18 +319,18 @@ Value *ConvertExpressionToType(Value *V, const Type *Ty, ValueMapCache &VMC) { DEBUG(cerr << "CETT: " << (void*)V << " " << V); Instruction *I = dyn_cast(V); - if (I == 0) - if (Constant *CPV = cast(V)) { - // Constants are converted by constant folding the cast that is required. - // We assume here that all casts are implemented for constant prop. - Value *Result = ConstantFoldCastInstruction(CPV, Ty); - assert(Result && "ConstantFoldCastInstruction Failed!!!"); - assert(Result->getType() == Ty && "Const prop of cast failed!"); - - // Add the instruction to the expression map - VMC.ExprMap[V] = Result; - return Result; - } + if (I == 0) { + Constant *CPV = cast(V)) { + // Constants are converted by constant folding the cast that is required. + // We assume here that all casts are implemented for constant prop. + Value *Result = ConstantFoldCastInstruction(CPV, Ty); + assert(Result && "ConstantFoldCastInstruction Failed!!!"); + assert(Result->getType() == Ty && "Const prop of cast failed!"); + + // Add the instruction to the expression map + //VMC.ExprMap[V] = Result; + return Result; + } BasicBlock *BB = I->getParent(); -- 2.34.1