From 6e8fbad67554e0a605af59d072b4129a8706681e Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 30 Nov 2006 17:32:29 +0000 Subject: [PATCH] One more bugfix, 3 cases of making casts explicit. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32043 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/IPO/GlobalOpt.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp index e0dfbe5aec6..d6a8a85800c 100644 --- a/lib/Transforms/IPO/GlobalOpt.cpp +++ b/lib/Transforms/IPO/GlobalOpt.cpp @@ -572,7 +572,8 @@ static bool OptimizeAwayTrappingUsesOfValue(Value *V, Constant *NewV) { } } else if (CastInst *CI = dyn_cast(I)) { Changed |= OptimizeAwayTrappingUsesOfValue(CI, - ConstantExpr::getCast(NewV, CI->getType())); + ConstantExpr::getCast(CI->getOpcode(), + NewV, CI->getType())); if (CI->use_empty()) { Changed = true; CI->eraseFromParent(); @@ -670,7 +671,7 @@ static void ConstantPropUsersOf(Value *V) { /// variable, and transforms the program as if it always contained the result of /// the specified malloc. Because it is always the result of the specified /// malloc, there is no reason to actually DO the malloc. Instead, turn the -/// malloc into a global, and any laods of GV as uses of the new global. +/// malloc into a global, and any loads of GV as uses of the new global. static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, MallocInst *MI) { DOUT << "PROMOTING MALLOC GLOBAL: " << *GV << " MALLOC = " << *MI; @@ -707,7 +708,8 @@ static GlobalVariable *OptimizeGlobalAddressOfMalloc(GlobalVariable *GV, Constant *RepValue = NewGV; if (NewGV->getType() != GV->getType()->getElementType()) - RepValue = ConstantExpr::getCast(RepValue, GV->getType()->getElementType()); + RepValue = ConstantExpr::getCast(Instruction::BitCast, + RepValue, GV->getType()->getElementType()); // If there is a comparison against null, we will insert a global bool to // keep track of whether the global was initialized yet or not. @@ -1056,7 +1058,8 @@ static bool OptimizeOnceStoredGlobal(GlobalVariable *GV, Value *StoredOnceVal, GV->getInitializer()->isNullValue()) { if (Constant *SOVC = dyn_cast(StoredOnceVal)) { if (GV->getInitializer()->getType() != SOVC->getType()) - SOVC = ConstantExpr::getCast(SOVC, GV->getInitializer()->getType()); + SOVC = ConstantExpr::getCast(Instruction::BitCast, + SOVC, GV->getInitializer()->getType()); // Optimize away any trapping uses of the loaded value. if (OptimizeAwayTrappingUsesOfLoads(GV, SOVC)) @@ -1507,7 +1510,7 @@ static GlobalVariable *InstallGlobalCtors(GlobalVariable *GCL, if (!GCL->use_empty()) { Constant *V = NGV; if (V->getType() != GCL->getType()) - V = ConstantExpr::getCast(V, GCL->getType()); + V = ConstantExpr::getCast(Instruction::BitCast, V, GCL->getType()); GCL->replaceAllUsesWith(V); } GCL->eraseFromParent();