[PATCH] D70597: [PHIEliminate] skip dbg instruction when LowerPHINode
Chris Ye via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 24 05:37:42 PST 2020
yechunliang updated this revision to Diff 246187.
yechunliang added a comment.
updated patch:
[PHIEliminate] splice dbg instruction when LowerPHINode
DBG_VALUEs between PHI and LABEL will block PHI lownering after LABEL, move all DBG_VALUEs after Label before PHI lowering.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D70597/new/
https://reviews.llvm.org/D70597
Files:
llvm/lib/CodeGen/PHIElimination.cpp
llvm/test/CodeGen/X86/phi-node-elimination-dbg-invariant.mir
Index: llvm/test/CodeGen/X86/phi-node-elimination-dbg-invariant.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/phi-node-elimination-dbg-invariant.mir
@@ -0,0 +1,30 @@
+# RUN: llc -mtriple=x86_64-- -run-pass phi-node-elimination -o - %s | FileCheck %s
+# Debug instruction should not impact PHI node lowering after LABEL, move DBG_VALUEs
+# after LABEL before PHI lowering.
+# Fix issue: https://bugs.llvm.org/show_bug.cgi?id=43859
+
+---
+name: test1
+tracksRegLiveness: true
+body: |
+ ; Verify PHI lowering with a debug instruction between PHI and LABEL,
+ ; skip debug instruction and insert copy instruction after LABEL.
+ ; CHECK-LABEL: name: test1
+ ; CHECK: bb.2:
+ ; CHECK: EH_LABEL 0
+ ; CHECK-NEXT: %1:gr32 = COPY %3
+ ; CHECK-NEXT: DBG_VALUE %1
+ ; CHECK-NEXT: DBG_VALUE %2
+ bb.0:
+ %0:gr32 = IMPLICIT_DEF
+ JMP_1 %bb.2
+
+ bb.1:
+
+ bb.2:
+ %1:gr32 = PHI %0, %bb.0, %2, %bb.1
+ DBG_VALUE %1
+ EH_LABEL 0
+ DBG_VALUE %2
+ %2:gr32 = ADD32ri8 killed %1, 1, implicit-def $eflags
+...
Index: llvm/lib/CodeGen/PHIElimination.cpp
===================================================================
--- llvm/lib/CodeGen/PHIElimination.cpp
+++ llvm/lib/CodeGen/PHIElimination.cpp
@@ -199,6 +199,21 @@
return Changed;
}
+void spliceDebugInstructionForward(MachineBasicBlock &MBB,
+ MachineBasicBlock::iterator From,
+ MachineBasicBlock::iterator To) {
+ if (From == To)
+ return;
+
+ for (MachineBasicBlock::iterator Inst = std::prev(To); Inst != From; --Inst) {
+ MachineBasicBlock::iterator where = std::next(To);
+ if(Inst->isDebugInstr()) {
+ MBB.splice(where, &MBB, Inst);
+ Inst = std::prev(Inst);
+ }
+ }
+}
+
/// EliminatePHINodes - Eliminate phi nodes by inserting copy instructions in
/// predecessor basic blocks.
bool PHIElimination::EliminatePHINodes(MachineFunction &MF,
@@ -207,8 +222,11 @@
return false; // Quick exit for basic blocks without PHIs.
// Get an iterator to the last PHI node.
- MachineBasicBlock::iterator LastPHIIt =
- std::prev(MBB.SkipPHIsAndLabels(MBB.begin()));
+ MachineBasicBlock::iterator LastPHIIt = skipDebugInstructionsBackward(
+ std::prev(MBB.SkipPHIsLabelsAndDebug(MBB.begin())), MBB.begin());
+
+ if (LastPHIIt->isLabel())
+ spliceDebugInstructionForward(MBB, MBB.begin(), LastPHIIt);
while (MBB.front().isPHI())
LowerPHINode(MBB, LastPHIIt);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70597.246187.patch
Type: text/x-patch
Size: 2547 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200224/503ea181/attachment.bin>
More information about the llvm-commits
mailing list