[llvm] 1de516d - [StackColoring] Pre-commit of test case showing a debug invariance bug

Bjorn Pettersson via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 14 10:25:08 PDT 2021


Author: Bjorn Pettersson
Date: 2021-09-14T19:21:55+02:00
New Revision: 1de516d7ae7e568a0ae28b79d2a91521bff79689

URL: https://github.com/llvm/llvm-project/commit/1de516d7ae7e568a0ae28b79d2a91521bff79689
DIFF: https://github.com/llvm/llvm-project/commit/1de516d7ae7e568a0ae28b79d2a91521bff79689.diff

LOG: [StackColoring] Pre-commit of test case showing a debug invariance bug

Having DBG_VALUE instructions referencing a stack slot while being outside
of the LIFETIME_START/LIFETIME_END markers for that stack slot is perhaps
not always ideal (from a debugging perspective), but it might happen during
codegen that we end up with such situations (e.g. positioning of the
DBG_VALUE instruction for a SDDbgOperand::FRAMEIX at ISel is a bit sloppy
in that context).

This patch adds a test case showing that StackColoring currently isn't
debug invariant, and that the position of DBG_VALUE instructions referencing
the stack slots might impact the decision making regarding stack slot reuse.

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

Added: 
    llvm/test/CodeGen/X86/StackColoring-dbg-invariance.mir

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/llvm/test/CodeGen/X86/StackColoring-dbg-invariance.mir b/llvm/test/CodeGen/X86/StackColoring-dbg-invariance.mir
new file mode 100644
index 0000000000000..8f250a690c33f
--- /dev/null
+++ b/llvm/test/CodeGen/X86/StackColoring-dbg-invariance.mir
@@ -0,0 +1,117 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
+# RUN: llc -mcpu=corei7 -no-stack-coloring=false -run-pass=stack-coloring -o - %s | FileCheck %s
+
+# Difference between test_1 and test_2 is that there is a DBG_VALUE in test_1.
+# If transformation is debug invariant the resulting LEA instruction should be
+# the same (i.e. we should reuse the same stack slot).
+
+--- |
+  ; ModuleID = '<stdin>'
+  source_filename = "StackColoring-dbg-invariance.ll"
+  target datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+  target triple = "x86_64-apple-macosx10.8.0"
+
+  ; Function Attrs: argmemonly nofree nosync nounwind willreturn
+  declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #0
+
+  ; Function Attrs: argmemonly nofree nosync nounwind willreturn
+  declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #0
+
+  define i32 @test_1(i32 %in) #1 !dbg !5 {
+  entry:
+    %a1 = alloca [14 x i8*], align 8
+    %a4 = alloca [11 x i8*], align 8
+    call void @llvm.dbg.value(metadata [11 x i8*]* %a4, metadata !9, metadata !DIExpression()), !dbg !11
+    ret i32 0
+  }
+
+  define i32 @test_2(i32 %in) #1 !dbg !12 {
+  entry:
+    %a1 = alloca [14 x i8*], align 8
+    %a4 = alloca [11 x i8*], align 8
+    ret i32 0
+  }
+
+  ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
+  declare void @llvm.dbg.value(metadata, metadata, metadata) #2
+
+  attributes #0 = { argmemonly nofree nosync nounwind willreturn "target-cpu"="corei7" }
+  attributes #1 = { "target-cpu"="corei7" }
+
+  !llvm.dbg.cu = !{!0}
+  !llvm.debugify = !{!2, !3}
+  !llvm.module.flags = !{!4}
+
+  !0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
+  !1 = !DIFile(filename: "StackColoring-dbg-invariance.ll", directory: "/")
+  !2 = !{i32 27}
+  !3 = !{i32 18}
+  !4 = !{i32 2, !"Debug Info Version", i32 3}
+  !5 = distinct !DISubprogram(name: "test_1", linkageName: "test_1", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
+  !6 = !DISubroutineType(types: !7)
+  !7 = !{}
+  !8 = !{!9}
+  !9 = !DILocalVariable(name: "4", scope: !5, file: !1, line: 4, type: !10)
+  !10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
+  !11 = !DILocation(line: 4, column: 1, scope: !5)
+  !12 = distinct !DISubprogram(name: "test_2", linkageName: "test_2", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
+
+...
+---
+name:            test_1
+alignment:       16
+tracksRegLiveness: true
+stack:
+  - { id: 0, name: a1, type: default, offset: 0, size: 112, alignment: 8,
+      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+  - { id: 3, name: a4, type: default, offset: 0, size: 88, alignment: 8,
+      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+body:             |
+  bb.0.entry:
+    liveins: $edi
+
+    ; CHECK-LABEL: name: test_1
+    ; CHECK: liveins: $edi
+    ; CHECK: DBG_VALUE %stack.1.a4, $noreg, !9, !DIExpression(), debug-location !11
+    ; CHECK: [[LEA64r:%[0-9]+]]:gr64 = LEA64r %stack.0.a1, 1, $noreg, 0, $noreg
+    ; CHECK: [[LEA64r1:%[0-9]+]]:gr64 = LEA64r %stack.1.a4, 1, $noreg, 0, $noreg
+    ; CHECK: RET 0
+    DBG_VALUE %stack.3.a4, $noreg, !9, !DIExpression(), debug-location !11
+    LIFETIME_START %stack.3.a4
+    LIFETIME_START %stack.0.a1
+    %0:gr64 = LEA64r %stack.0.a1, 1, $noreg, 0, $noreg
+    LIFETIME_END %stack.0.a1
+    %1:gr64 = LEA64r %stack.3.a4, 1, $noreg, 0, $noreg
+    LIFETIME_END %stack.3.a4
+    RET 0
+...
+---
+name:            test_2
+alignment:       16
+tracksRegLiveness: true
+stack:
+  - { id: 0, name: a1, type: default, offset: 0, size: 112, alignment: 8,
+      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+  - { id: 3, name: a4, type: default, offset: 0, size: 88, alignment: 8,
+      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
+      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
+body:             |
+  bb.0.entry:
+    liveins: $edi
+
+    ; CHECK-LABEL: name: test_2
+    ; CHECK: liveins: $edi
+    ; CHECK: [[LEA64r:%[0-9]+]]:gr64 = LEA64r %stack.0.a1, 1, $noreg, 0, $noreg
+    ; CHECK: [[LEA64r1:%[0-9]+]]:gr64 = LEA64r %stack.0.a1, 1, $noreg, 0, $noreg
+    ; CHECK: RET 0
+    LIFETIME_START %stack.3.a4
+    LIFETIME_START %stack.0.a1
+    %0:gr64 = LEA64r %stack.0.a1, 1, $noreg, 0, $noreg
+    LIFETIME_END %stack.0.a1
+    %1:gr64 = LEA64r %stack.3.a4, 1, $noreg, 0, $noreg
+    LIFETIME_END %stack.3.a4
+    RET 0
+...


        


More information about the llvm-commits mailing list