add a fastpath to ConstantExpr::getBitCast to handle the case when an obviously
authorChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 06:55:54 +0000 (06:55 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 21 Mar 2009 06:55:54 +0000 (06:55 +0000)
unneeded bitcast is requested.  This is common for frontends who just unconditionally
cast even if the target is often the right type already.  THis prevents going into
getFoldedCast which switches on the opcode and does a bunch of other stuff before
doing the same opzn.

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

lib/VMCore/Constants.cpp

index ed1e04ad547ed24082618216cf65a150964bcd1a..6c99a1ffe88e6f2473816be6a845a2da649b8e66 100644 (file)
@@ -1996,6 +1996,11 @@ Constant *ConstantExpr::getBitCast(Constant *C, const Type *DstTy) {
   unsigned DstBitSize = DstTy->getPrimitiveSizeInBits();
 #endif
   assert(SrcBitSize == DstBitSize && "BitCast requires types of same width");
+  
+  // It is common to ask for a bitcast of a value to its own type, handle this
+  // speedily.
+  if (C->getType() == DstTy) return C;
+  
   return getFoldedCast(Instruction::BitCast, C, DstTy);
 }