[llvm] r340326 - [RegisterCoalescer] Use substPhysReg in reMaterializeTrivialDef

Bjorn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 21 12:47:33 PDT 2018


Author: bjope
Date: Tue Aug 21 12:47:32 2018
New Revision: 340326

URL: http://llvm.org/viewvc/llvm-project?rev=340326&view=rev
Log:
[RegisterCoalescer] Use substPhysReg in reMaterializeTrivialDef

Summary:
When RegisterCoalescer::reMaterializeTrivialDef is substituting
a register use in a DBG_VALUE instruction, and the old register
is a subreg, and the new register is a physical register,
then we need to use substPhysReg in order to extract the correct
subreg.

Reviewers: wmi, aprantl

Reviewed By: wmi

Subscribers: hiraditya, MatzeB, qcolombet, tpr, llvm-commits

Differential Revision: https://reviews.llvm.org/D50844

Added:
    llvm/trunk/test/CodeGen/X86/coalesce-dbg-value-subreg-rewrite.mir
Modified:
    llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp

Modified: llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp?rev=340326&r1=340325&r2=340326&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp (original)
+++ llvm/trunk/lib/CodeGen/RegisterCoalescer.cpp Tue Aug 21 12:47:32 2018
@@ -1436,7 +1436,10 @@ bool RegisterCoalescer::reMaterializeTri
     for (MachineOperand &UseMO : MRI->use_operands(SrcReg)) {
       MachineInstr *UseMI = UseMO.getParent();
       if (UseMI->isDebugValue()) {
-        UseMO.setReg(DstReg);
+        if (TargetRegisterInfo::isPhysicalRegister(DstReg))
+          UseMO.substPhysReg(DstReg, *TRI);
+        else
+          UseMO.setReg(DstReg);
         // Move the debug value directly after the def of the rematerialized
         // value in DstReg.
         MBB->splice(std::next(NewMI.getIterator()), UseMI->getParent(), UseMI);

Added: llvm/trunk/test/CodeGen/X86/coalesce-dbg-value-subreg-rewrite.mir
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/coalesce-dbg-value-subreg-rewrite.mir?rev=340326&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/coalesce-dbg-value-subreg-rewrite.mir (added)
+++ llvm/trunk/test/CodeGen/X86/coalesce-dbg-value-subreg-rewrite.mir Tue Aug 21 12:47:32 2018
@@ -0,0 +1,51 @@
+# RUN: llc -O0 -mtriple x86_64-pc-linux-gnu -run-pass simple-register-coalescing -verify-coalescing -o - %s | FileCheck %s
+
+--- |
+  define i16 @main() {
+  entry:
+    call void @llvm.dbg.value(metadata i8 0, metadata !11, metadata !DIExpression()), !dbg !13
+    ret i16 0
+  }
+
+  ; Function Attrs: nounwind readnone speculatable
+  declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+  !llvm.dbg.cu = !{!0}
+  !llvm.module.flags = !{!3, !4, !5}
+  !llvm.ident = !{!6}
+
+  !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
+  !1 = !DIFile(filename: "tmp.c", directory: "")
+  !2 = !{}
+  !3 = !{i32 2, !"Dwarf Version", i32 4}
+  !4 = !{i32 2, !"Debug Info Version", i32 3}
+  !5 = !{i32 1, !"wchar_size", i32 1}
+  !6 = !{!"clang"}
+  !7 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !8, isLocal: false, isDefinition: true, scopeLine: 4, isOptimized: false, unit: !0, retainedNodes: !2)
+  !8 = !DISubroutineType(types: !9)
+  !9 = !{!10}
+  !10 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
+  !11 = !DILocalVariable(name: "c", scope: !7, file: !1, line: 5, type: !12)
+  !12 = !DIBasicType(name: "mytype", size: 16)
+  !13 = !DILocation(line: 5, column: 11, scope: !7)
+
+...
+---
+name:            main
+tracksRegLiveness: true
+body:             |
+  bb.0.entry:
+    %0:gr16_abcd = MOV16ri 0
+    DBG_VALUE debug-use %0.sub_8bit:gr16_abcd, debug-use $noreg, !11, !DIExpression(), debug-location !13
+    undef %6.sub_8bit:gr16_abcd = COPY killed %0.sub_8bit
+    dead $dx = COPY killed %6
+
+...
+
+# Verify that we get $dl in the DBG_VALUE (and not $dx.sub_8bit as we used to
+# do before the bugfix, which resulted in "Bad machine code: Illegal
+# subregister index for physical register").
+#
+# CHECK:      bb.0.entry:
+# CHECK-NEXT:    $dx = MOV16ri 0
+# CHECK-NEXT:    DBG_VALUE debug-use $dl,




More information about the llvm-commits mailing list