GlobalISel: avoid inserting redundant COPYs for bitcasts.

If the value produced by the bitcast hasn't been referenced yet, we can simply
reuse the input register avoiding an unnecessary COPY instruction.

llvm-svn: 278245
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index a5f62cf..4ea0951 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -166,8 +166,11 @@
 
 bool IRTranslator::translateBitCast(const CastInst &CI) {
   if (LLT{*CI.getDestTy()} == LLT{*CI.getSrcTy()}) {
-    MIRBuilder.buildCopy(getOrCreateVReg(CI),
-                         getOrCreateVReg(*CI.getOperand(0)));
+    unsigned &Reg = ValToVReg[&CI];
+    if (Reg)
+      MIRBuilder.buildCopy(Reg, getOrCreateVReg(*CI.getOperand(0)));
+    else
+      Reg = getOrCreateVReg(*CI.getOperand(0));
     return true;
   }
   return translateCast(TargetOpcode::G_BITCAST, CI);