Create constant expression casts instead of constant instructions if possible
authorChris Lattner <sabre@nondot.org>
Mon, 28 Apr 2003 01:25:38 +0000 (01:25 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 28 Apr 2003 01:25:38 +0000 (01:25 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@5968 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/LevelRaise.cpp

index 50ed60c903705aa8bf87825dff9b76c4cede3938..2e9d8c2f8c810bdf5faec48d6714d789535e6d99 100644 (file)
@@ -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,