[PATCH] D104394: [MachineCopyPropagation] Fix differences in code gen when compiling with -g

Alexandru Octavian Buțiu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 16 08:59:13 PDT 2021


predator5047 created this revision.
predator5047 added reviewers: bzEq, bogner, lattner, gberry.
predator5047 added a project: LLVM.
Herald added subscribers: pengfei, hiraditya.
predator5047 requested review of this revision.
Herald added a subscriber: llvm-commits.

Fixes bugs 50580 <https://bugs.llvm.org/show_bug.cgi?id=50580> and 49446 <https://bugs.llvm.org/show_bug.cgi?id=49446>

When compiling with -g "DBG_VALUE <reg>"  instructions are added in the MIR, if such a instruction is inserted between instructions that use <reg> then MachineCopyPropagation invalidates <reg> , this causes some copies  to not be propagated and causes differences in code generation (ex bugs 50580 and 49446 ).  DBG_VALUE instructions should be ignored  since they don't actually modify the register.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104394

Files:
  llvm/lib/CodeGen/MachineCopyPropagation.cpp
  llvm/test/CodeGen/X86/machine-copy-dbgvalue.mir


Index: llvm/test/CodeGen/X86/machine-copy-dbgvalue.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/machine-copy-dbgvalue.mir
@@ -0,0 +1,18 @@
+# RUN: llc -mtriple=i686-- -run-pass machine-cp -verify-machineinstrs -o - %s | FileCheck %s
+
+
+---
+# Test that machine copy propagation ignores DBG_VALUE
+# CHECK-LABEL: name: foo
+# CHECK: bb.0:
+# CHECK-NEXT: $rax = MOV64ri 31
+# CHECK-NEXT: DBG_VALUE $rcx, $noreg
+# CHECK-NEXT: RETQ implicit killed $rax
+name: foo
+body: |
+  bb.0:
+    renamable $rcx = MOV64ri 31
+    DBG_VALUE $rcx, $noreg
+    $rax = COPY renamable killed $rcx
+    RETQ implicit killed $rax
+...
Index: llvm/lib/CodeGen/MachineCopyPropagation.cpp
===================================================================
--- llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -866,6 +866,8 @@
 
       if (!MO.getReg())
         continue;
+      if (MO.isDebug())
+        continue;
 
       if (MO.isDef())
         Tracker.invalidateRegister(MO.getReg().asMCReg(), *TRI);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104394.352438.patch
Type: text/x-patch
Size: 1100 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210616/0c60cfdf/attachment.bin>


More information about the llvm-commits mailing list