[ImplicitNullChecks] Properly update the live-in of the block of the memory operation.

We basically replace:
HoistBB:
cond_br NullBB, NotNullBB

NullBB:
  ...

NotNullBB:
  <reg> = load

into
HoistBB
<reg> = load_faulting_op NullBB
uncond_br NotNullBB

NullBB:
  ...

NotNullBB: ## <reg> is now live-in of NotNullBB
  ...

This partially fixes the machine verifier error for
test/CodeGen/X86/implicit-null-check.ll, but it still fails because
of the implicit CFG structure.

llvm-svn: 267817
diff --git a/llvm/lib/CodeGen/ImplicitNullChecks.cpp b/llvm/lib/CodeGen/ImplicitNullChecks.cpp
index 2c03f72..c923ddd 100644
--- a/llvm/lib/CodeGen/ImplicitNullChecks.cpp
+++ b/llvm/lib/CodeGen/ImplicitNullChecks.cpp
@@ -397,7 +397,16 @@
     // check earlier ensures that this bit of code motion is legal.  We do not
     // touch the successors list for any basic block since we haven't changed
     // control flow, we've just made it implicit.
-    insertFaultingLoad(NC.MemOperation, NC.CheckBlock, HandlerLabel);
+    MachineInstr *FaultingLoad =
+        insertFaultingLoad(NC.MemOperation, NC.CheckBlock, HandlerLabel);
+    // Now the value of the MemOperation, if any, is live-in of block
+    // of MemOperation.
+    unsigned Reg = FaultingLoad->getOperand(0).getReg();
+    if (Reg) {
+      MachineBasicBlock *MBB = NC.MemOperation->getParent();
+      if (!MBB->isLiveIn(Reg))
+        MBB->addLiveIn(Reg);
+    }
     NC.MemOperation->eraseFromParent();
     NC.CheckOperation->eraseFromParent();