diff options
author | Chris Lattner <sabre@nondot.org> | 2003-04-28 01:25:38 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-04-28 01:25:38 +0000 |
commit | 95549281ecfcb99127cf0c18d4944900f54a9446 (patch) | |
tree | 0488c53f99dd5d213b16272c0efc7d5c701b5802 /lib/Transforms/LevelRaise.cpp | |
parent | 1fd95afab3d49d16c6d0e1e174e4537336548ab1 (diff) |
Create constant expression casts instead of constant instructions if possible
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5968 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms/LevelRaise.cpp')
-rw-r--r-- | lib/Transforms/LevelRaise.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/Transforms/LevelRaise.cpp b/lib/Transforms/LevelRaise.cpp index 50ed60c903..2e9d8c2f8c 100644 --- a/lib/Transforms/LevelRaise.cpp +++ b/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, |