From 72b9deb21f12469d025e96fdb9af6aa316f96a47 Mon Sep 17 00:00:00 2001 From: Markus Lavin Date: Thu, 3 Jan 2019 08:36:06 +0000 Subject: [PATCH] [CodeGen] Skip over dbg-instr in twoaddr pass A DBG_VALUE between a two-address instruction and a following COPY would prevent rescheduleMIBelowKill optimization inside TwoAddressInstructionPass. Differential Revision: https://reviews.llvm.org/D55987 llvm-svn: 350289 --- .../lib/CodeGen/TwoAddressInstructionPass.cpp | 9 ++++--- llvm/test/CodeGen/X86/twoaddr-dbg-value.mir | 27 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 llvm/test/CodeGen/X86/twoaddr-dbg-value.mir diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp index 2e2fe72e5395..4b72f6a84ca1 100644 --- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -929,9 +929,12 @@ rescheduleMIBelowKill(MachineBasicBlock::iterator &mi, MachineBasicBlock::iterator Begin = MI; MachineBasicBlock::iterator AfterMI = std::next(Begin); MachineBasicBlock::iterator End = AfterMI; - while (End->isCopy() && - regOverlapsSet(Defs, End->getOperand(1).getReg(), TRI)) { - Defs.push_back(End->getOperand(0).getReg()); + while (End != MBB->end()) { + End = skipDebugInstructionsForward(End, MBB->end()); + if (End->isCopy() && regOverlapsSet(Defs, End->getOperand(1).getReg(), TRI)) + Defs.push_back(End->getOperand(0).getReg()); + else + break; ++End; } diff --git a/llvm/test/CodeGen/X86/twoaddr-dbg-value.mir b/llvm/test/CodeGen/X86/twoaddr-dbg-value.mir new file mode 100644 index 000000000000..f2d6c5df5822 --- /dev/null +++ b/llvm/test/CodeGen/X86/twoaddr-dbg-value.mir @@ -0,0 +1,27 @@ +# RUN: llc -run-pass=livevars,twoaddressinstruction -mtriple=x86_64-- -o - %s | FileCheck %s +--- +name: foo +tracksRegLiveness: true +body: | + bb.0: + liveins: $edi + + %0:gr32 = COPY killed $edi + %1:gr32 = COPY killed %0 + %4:gr32 = XOR32ri8 %1, 1, implicit-def dead $eflags + DBG_VALUE %4 + %5:gr32 = COPY %4 + PUSH32r killed %1, implicit-def $esp, implicit $esp + $eax = COPY killed %5 + RETQ implicit killed $eax + +... + +# Verify that the DBG_VALUE instruction does not inhibit +# TwoAddressInstructionPass::rescheduleMIBelowKill optimization + +# CHECK: PUSH32r %1, implicit-def $esp, implicit $esp +# CHECK-NEXT: %2:gr32 = COPY killed %1 +# CHECK-NEXT: %2:gr32 = XOR32ri8 %2, 1, implicit-def dead $eflags +# CHECK-NEXT: DBG_VALUE %2 +# CHECK-NEXT: %3:gr32 = COPY killed %2