From 1a0909fd7fa0599e844d9870981e2e84c22b3a04 Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Tue, 3 May 2016 18:09:06 +0000 Subject: [PATCH] [ImplicitNullChecks] Account for implicit-defs as well when updating the liveness. 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 | 19 ++++++++++++------- test/CodeGen/X86/implicit-null-check.ll | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/lib/CodeGen/ImplicitNullChecks.cpp b/lib/CodeGen/ImplicitNullChecks.cpp index dfd1be8c8ea..9b2bedb52c0 100644 --- a/lib/CodeGen/ImplicitNullChecks.cpp +++ b/lib/CodeGen/ImplicitNullChecks.cpp @@ -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(); diff --git a/test/CodeGen/X86/implicit-null-check.ll b/test/CodeGen/X86/implicit-null-check.ll index b4c9b5834c8..9a8a3a4369d 100644 --- a/test/CodeGen/X86/implicit-null-check.ll +++ b/test/CodeGen/X86/implicit-null-check.ll @@ -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 - \