From 3b9922f99c96bafd2c3ecb7f7fa4a8a4fc9cc9dc Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 14 May 2003 17:51:05 +0000 Subject: [PATCH] Remove unnecessary casts git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6201 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/VMCore/ConstantFold.cpp | 4 ++-- lib/VMCore/Constants.cpp | 23 ++++++++++++----------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/lib/VMCore/ConstantFold.cpp b/lib/VMCore/ConstantFold.cpp index db8cc4487c1..d5f98bd201e 100644 --- a/lib/VMCore/ConstantFold.cpp +++ b/lib/VMCore/ConstantFold.cpp @@ -91,7 +91,7 @@ Constant *ConstantFoldCastInstruction(const Constant *V, const Type *DestTy) { if (const ConstantExpr *CE = dyn_cast(V)) if (CE->getOpcode() == Instruction::Cast) { - Constant *Op = (Constant*)cast(CE->getOperand(0)); + Constant *Op = const_cast(CE->getOperand(0)); // Try to not produce a cast of a cast, which is almost always redundant. if (!Op->getType()->isFloatingPoint() && !CE->getType()->isFloatingPoint() && @@ -166,7 +166,7 @@ Constant *ConstantFoldGetElementPtr(const Constant *C, dyn_cast(cast(C->getType())->getElementType())) if (CAT->getElementType() == SAT->getElementType()) return ConstantExpr::getGetElementPtr( - (Constant*)cast(CE->getOperand(0)), IdxList); + (Constant*)CE->getOperand(0), IdxList); return 0; } diff --git a/lib/VMCore/Constants.cpp b/lib/VMCore/Constants.cpp index 499452c4251..04d46e58673 100644 --- a/lib/VMCore/Constants.cpp +++ b/lib/VMCore/Constants.cpp @@ -411,30 +411,31 @@ void ConstantPointerRef::replaceUsesOfWithOnConstant(Value *From, Value *To) { } } -void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *To) { - assert(isa(To) && "Cannot make Constant refer to non-constant!"); +void ConstantExpr::replaceUsesOfWithOnConstant(Value *From, Value *ToV) { + assert(isa(ToV) && "Cannot make Constant refer to non-constant!"); + Constant *To = cast(ToV); Constant *Replacement = 0; if (getOpcode() == Instruction::GetElementPtr) { std::vector Indices; - Constant *Pointer = cast(getOperand(0)); + Constant *Pointer = getOperand(0); Indices.reserve(getNumOperands()-1); - if (Pointer == From) Pointer = cast(To); + if (Pointer == From) Pointer = To; for (unsigned i = 1, e = getNumOperands(); i != e; ++i) { - Constant *Val = cast(getOperand(i)); - if (Val == From) Val = cast(To); + Constant *Val = getOperand(i); + if (Val == From) Val = To; Indices.push_back(Val); } Replacement = ConstantExpr::getGetElementPtr(Pointer, Indices); } else if (getOpcode() == Instruction::Cast) { assert(getOperand(0) == From && "Cast only has one use!"); - Replacement = ConstantExpr::getCast(cast(To), getType()); + Replacement = ConstantExpr::getCast(To, getType()); } else if (getNumOperands() == 2) { - Constant *C1 = cast(getOperand(0)); - Constant *C2 = cast(getOperand(1)); - if (C1 == From) C1 = cast(To); - if (C2 == From) C2 = cast(To); + Constant *C1 = getOperand(0); + Constant *C2 = getOperand(1); + if (C1 == From) C1 = To; + if (C2 == From) C2 = To; Replacement = ConstantExpr::get(getOpcode(), C1, C2); } else { assert(0 && "Unknown ConstantExpr type!");