[PATCH] D70597: [PHIEliminate] skip dbg instruction when LowerPHINode

Chris Ye via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 06:05:48 PST 2019


yechunliang updated this revision to Diff 230639.

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,48 @@
+# RUN: llc -mtriple=x86_64-- -run-pass phi-node-elimination -o - %s | FileCheck %s
+# Debug instruction should not impact PHI node lower when
+# the PHI node is at the top of the specified block
+# Fix issue: https://bugs.llvm.org/show_bug.cgi?id=43859
+
+---
+name:            test1
+tracksRegLiveness: true
+registers:
+body:             |
+  ; Verify PHI lowering without Debug instruction exist
+  ; CHECK-LABEL: name: test1
+  ; CHECK: bb.2:
+  ; CHECK: EH_LABEL 0
+  ; CHECK: %1:gr32 = COPY %3
+  bb.0:
+    %0:gr32 = IMPLICIT_DEF
+    JMP_1 %bb.2
+
+  bb.1:
+
+  bb.2:
+    %1:gr32 = PHI %0:gr32, %bb.0, %2:gr32, %bb.1
+    EH_LABEL 0
+    %2:gr32 = ADD32ri8 killed %1:gr32, 1, implicit-def $eflags
+...
+
+---
+name:            test2
+tracksRegLiveness: true
+body:             |
+  ; Verify PHI lowering with Debug instruction exist
+  ; CHECK-LABEL: name: test2
+  ; CHECK: bb.2:
+  ; CHECK: EH_LABEL 0
+  ; CHECK: %1:gr32 = COPY %3
+  bb.0:
+    %0:gr32 = IMPLICIT_DEF
+    JMP_1 %bb.2
+
+  bb.1:
+
+  bb.2:
+    %1:gr32 = PHI %0:gr32, %bb.0, %2:gr32, %bb.1
+    DBG_VALUE
+    EH_LABEL 0
+    %2:gr32 = ADD32ri8 killed %1:gr32, 1, implicit-def $eflags
+...
Index: llvm/lib/CodeGen/PHIElimination.cpp
===================================================================
--- llvm/lib/CodeGen/PHIElimination.cpp
+++ llvm/lib/CodeGen/PHIElimination.cpp
@@ -207,8 +207,9 @@
     return false;   // Quick exit for basic blocks without PHIs.
 
   // Get an iterator to the last PHI node.
+  // Skip debug instruction to avoid impacting PHI lower.
   MachineBasicBlock::iterator LastPHIIt =
-    std::prev(MBB.SkipPHIsAndLabels(MBB.begin()));
+    std::prev(MBB.SkipPHIsLabelsAndDebug(MBB.begin()));
 
   while (MBB.front().isPHI())
     LowerPHINode(MBB, LastPHIIt);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70597.230639.patch
Type: text/x-patch
Size: 2004 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191122/54b3312c/attachment.bin>


More information about the llvm-commits mailing list