From 882572aa68041e6b79b4ffb092621ecff5615fe1 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Mon, 26 Nov 2001 16:53:50 +0000 Subject: [PATCH] * Implement more powerful expr analysis of cast instructions git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1335 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/Expressions.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/Analysis/Expressions.cpp b/lib/Analysis/Expressions.cpp index ed04f1d818a..dd922124969 100644 --- a/lib/Analysis/Expressions.cpp +++ b/lib/Analysis/Expressions.cpp @@ -284,21 +284,30 @@ ExprType analysis::ClassifyExpression(Value *Expr) { case Instruction::Cast: { ExprType Src(ClassifyExpression(I->getOperand(0))); - if (Src.ExprTy != ExprType::Constant) - return I; - const ConstPoolInt *Offs = Src.Offset; - if (Offs == 0) return ExprType(); - const Type *DestTy = I->getType(); if (DestTy->isPointerType()) DestTy = Type::ULongTy; // Pointer types are represented as ulong - assert(DestTy->isIntegral() && "Can only handle integral types!"); + /* + if (!Src.getExprType(0)->isLosslesslyConvertableTo(DestTy)) { + if (Src.ExprTy != ExprType::Constant) + return I; // Converting cast, and not a constant value... + } + */ - const ConstPoolVal *CPV =ConstRules::get(*Offs)->castTo(Offs, DestTy); - if (!CPV) return I; - assert(CPV->getType()->isIntegral() && "Must have an integral type!"); - return cast(CPV); + const ConstPoolInt *Offset = Src.Offset; + const ConstPoolInt *Scale = Src.Scale; + if (Offset) { + const ConstPoolVal *CPV = ConstantFoldCastInstruction(Offset, DestTy); + if (!CPV) return I; + Offset = cast(CPV); + } + if (Scale) { + const ConstPoolVal *CPV = ConstantFoldCastInstruction(Scale, DestTy); + if (!CPV) return I; + Scale = cast(CPV); + } + return ExprType(Scale, Src.Var, Offset); } // end case Instruction::Cast // TODO: Handle SUB, SHR?