From 3ba68b9eef2851dae8a9d1b18928c6fa2e3c5f87 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Wed, 13 Dec 2006 08:06:42 +0000 Subject: Change the interface to SCEVExpander::InsertCastOfTo to take a cast opcode so the decision of which opcode to use is pushed upward to the caller. Adjust the callers to pass the expected opcode. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32535 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Analysis/ScalarEvolutionExpander.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'include/llvm') diff --git a/include/llvm/Analysis/ScalarEvolutionExpander.h b/include/llvm/Analysis/ScalarEvolutionExpander.h index c3ea383..80e0a9d 100644 --- a/include/llvm/Analysis/ScalarEvolutionExpander.h +++ b/include/llvm/Analysis/ScalarEvolutionExpander.h @@ -88,7 +88,8 @@ namespace llvm { /// InsertCastOfTo - Insert a cast of V to the specified type, doing what /// we can to share the casts. - static Value *InsertCastOfTo(Value *V, const Type *Ty); + static Value *InsertCastOfTo(Instruction::CastOps opcode, Value *V, + const Type *Ty); protected: Value *expand(SCEV *S) { @@ -104,8 +105,20 @@ namespace llvm { Value *expandInTy(SCEV *S, const Type *Ty) { Value *V = expand(S); - if (Ty && V->getType() != Ty) - return InsertCastOfTo(V, Ty); + if (Ty && V->getType() != Ty) { + if (isa(Ty) && V->getType()->isInteger()) + return InsertCastOfTo(Instruction::IntToPtr, V, Ty); + else if (Ty->isInteger() && isa(V->getType())) + return InsertCastOfTo(Instruction::PtrToInt, V, Ty); + else if (Ty->getPrimitiveSizeInBits() == + V->getType()->getPrimitiveSizeInBits()) + return InsertCastOfTo(Instruction::BitCast, V, Ty); + else if (Ty->getPrimitiveSizeInBits() > + V->getType()->getPrimitiveSizeInBits()) + return InsertCastOfTo(Instruction::ZExt, V, Ty); + else + return InsertCastOfTo(Instruction::Trunc, V, Ty); + } return V; } @@ -119,7 +132,7 @@ namespace llvm { } Value *visitZeroExtendExpr(SCEVZeroExtendExpr *S) { - Value *V = expandInTy(S->getOperand(),S->getType()->getUnsignedVersion()); + Value *V = expandInTy(S->getOperand(), S->getType()); return CastInst::createZExtOrBitCast(V, S->getType(), "tmp.", InsertPt); } -- cgit v1.1