summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-04-28 01:25:38 +0000
committerChris Lattner <sabre@nondot.org>2003-04-28 01:25:38 +0000
commitfcd1fe4f12a619c1b7b4c5ee9e2842b8b927223a (patch)
treed5950c1c80051364e00d215b11bfb04e1e5750d6 /llvm/lib/Transforms
parent9810b9485058b21e06783a7f4c11063074ee5662 (diff)
downloadbcm5719-llvm-fcd1fe4f12a619c1b7b4c5ee9e2842b8b927223a.tar.gz
bcm5719-llvm-fcd1fe4f12a619c1b7b4c5ee9e2842b8b927223a.zip
Create constant expression casts instead of constant instructions if possible
llvm-svn: 5968
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/LevelRaise.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/LevelRaise.cpp b/llvm/lib/Transforms/LevelRaise.cpp
index 50ed60c9037..2e9d8c2f8c8 100644
--- a/llvm/lib/Transforms/LevelRaise.cpp
+++ b/llvm/lib/Transforms/LevelRaise.cpp
@@ -504,8 +504,18 @@ bool RPR::PeepholeOptimize(BasicBlock *BB, BasicBlock::iterator &BI) {
PointerType *NewPFunTy = PointerType::get(NewFT);
// Create a new cast, inserting it right before the function call...
- CastInst *NewCast = new CastInst(CI->getCalledValue(), NewPFunTy,
- CI->getCalledValue()->getName()+"_c",CI);
+ Value *NewCast;
+ Constant *ConstantCallSrc = 0;
+ if (Constant *CS = dyn_cast<Constant>(CI->getCalledValue()))
+ ConstantCallSrc = CS;
+ else if (GlobalValue *GV = dyn_cast<GlobalValue>(CI->getCalledValue()))
+ ConstantCallSrc = ConstantPointerRef::get(GV);
+
+ if (ConstantCallSrc)
+ NewCast = ConstantExpr::getCast(ConstantCallSrc, NewPFunTy);
+ else
+ NewCast = new CastInst(CI->getCalledValue(), NewPFunTy,
+ CI->getCalledValue()->getName()+"_c",CI);
// Create a new call instruction...
CallInst *NewCall = new CallInst(NewCast,
OpenPOWER on IntegriCloud