]> granicus.if.org Git - llvm/commitdiff
[ImplicitNullChecks] Account for implicit-defs as well when updating the liveness.
authorQuentin Colombet <qcolombet@apple.com>
Tue, 3 May 2016 18:09:06 +0000 (18:09 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Tue, 3 May 2016 18:09:06 +0000 (18:09 +0000)
The replaced load may have implicit-defs and those defs may be used
in the block of the original load. Make sure to update the liveness
accordingly.

This is a generalization of r267817.

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

lib/CodeGen/ImplicitNullChecks.cpp
test/CodeGen/X86/implicit-null-check.ll

index dfd1be8c8eaecd02c3d3c8cc45887be7849cad14..9b2bedb52c04e6eecbf646f38900ccb74a780356 100644 (file)
@@ -398,13 +398,18 @@ void ImplicitNullChecks::rewriteNullChecks(
     // control flow, we've just made it implicit.
     MachineInstr *FaultingLoad =
         insertFaultingLoad(NC.MemOperation, NC.CheckBlock, NC.NullSucc);
-    // 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);
+    // Now the values defined by MemOperation, if any, are live-in of
+    // the block of MemOperation.
+    // The original load operation may define implicit-defs alongside
+    // the loaded value.
+    MachineBasicBlock *MBB = NC.MemOperation->getParent();
+    for (const MachineOperand &MO : FaultingLoad->operands()) {
+      if (!MO.isReg() || !MO.isDef())
+        continue;
+      unsigned Reg = MO.getReg();
+      if (!Reg || MBB->isLiveIn(Reg))
+        continue;
+      MBB->addLiveIn(Reg);
     }
     NC.MemOperation->eraseFromParent();
     NC.CheckOperation->eraseFromParent();
index b4c9b5834c81dcb01d6b0a519336f6a8a73bc1b3..9a8a3a4369d331fabfa1fa645c47fedd09134f58 100644 (file)
@@ -1,4 +1,4 @@
-; RUN: llc -O3 -mtriple=x86_64-apple-macosx -enable-implicit-null-checks < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -O3 -mtriple=x86_64-apple-macosx -enable-implicit-null-checks < %s | FileCheck %s
 
 ; RUN: llc < %s -mtriple=x86_64-apple-macosx -enable-implicit-null-checks \
 ; RUN:    | llvm-mc -triple x86_64-apple-macosx -filetype=obj -o - \