If a value is cast to its own type, then the cast
authorDuncan Sands <baldrick@free.fr>
Fri, 4 Apr 2008 08:28:13 +0000 (08:28 +0000)
committerDuncan Sands <baldrick@free.fr>
Fri, 4 Apr 2008 08:28:13 +0000 (08:28 +0000)
is not needed.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@49210 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/LLVMBuilder.h

index ef1817d3c16c1d580ce771fbb6e35c140c27f13b..2a7fc635d720ec0e281ea76042bb985df54e3163 100644 (file)
@@ -615,20 +615,24 @@ public:
                        const char *Name = "") {
     return CreateCast(Instruction::BitCast, V, DestTy, Name);
   }
-  
+
   Value *CreateCast(Instruction::CastOps Op, Value *V, const Type *DestTy,
                     const char *Name = "") {
+    if (V->getType() == DestTy)
+      return V;
     if (Constant *VC = dyn_cast<Constant>(V))
       return ConstantExpr::getCast(Op, VC, DestTy);
     return LLVMBuilder::CreateCast(Op, V, DestTy, Name);
   }
   Value *CreateIntCast(Value *V, const Type *DestTy, bool isSigned,
                        const char *Name = "") {
+    if (V->getType() == DestTy)
+      return V;
     if (Constant *VC = dyn_cast<Constant>(V))
       return ConstantExpr::getIntegerCast(VC, DestTy, isSigned);
     return LLVMBuilder::CreateIntCast(V, DestTy, isSigned, Name);
   }
-  
+
   //===--------------------------------------------------------------------===//
   // Instruction creation methods: Compare Instructions
   //===--------------------------------------------------------------------===//