Skip to content

Commit ee13fbe

Browse files
committed
CodeGen: ignore DEBUG_VALUE nodes in KILL tagging
DEBUG_VALUE nodes do not take part in code generation. Ignore them when performing KILL updates. Addresses PR23486. llvm-svn: 237211
1 parent 942fba9 commit ee13fbe

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

llvm/lib/CodeGen/ScheduleDAGInstrs.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,12 @@ static void toggleBundleKillFlag(MachineInstr *MI, unsigned Reg,
11151115
if (!MO->isReg() || MO->isDef() || Reg != MO->getReg())
11161116
continue;
11171117

1118+
// DEBUG_VALUE nodes do not contribute to code generation and should
1119+
// always be ignored. Failure to do so may result in trying to modify
1120+
// KILL flags on DEBUG_VALUE nodes, which is distressing.
1121+
if (MO->isDebug())
1122+
continue;
1123+
11181124
// If the register has the internal flag then it could be killing an
11191125
// internal def of the register. In this case, just skip. We only want
11201126
// to toggle the flag on operands visible outside the bundle.
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
; RUN: llc -mtriple thumbv7 -print-before=post-RA-sched -print-after=post-RA-sched %s -o /dev/null 2>&1 | FileCheck %s
2+
3+
; ModuleID = '<stdin>'
4+
target datalayout = "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64"
5+
target triple = "thumbv7"
6+
7+
%struct.s = type opaque
8+
9+
; Function Attrs: nounwind
10+
define arm_aapcscc i32 @f(%struct.s* %s, i32 %u, i8* %b, i32 %n) #0 {
11+
entry:
12+
tail call void @llvm.dbg.value(metadata %struct.s* %s, i64 0, metadata !19, metadata !28), !dbg !29
13+
tail call void @llvm.dbg.value(metadata i32 %u, i64 0, metadata !20, metadata !28), !dbg !29
14+
tail call void @llvm.dbg.value(metadata i8* %b, i64 0, metadata !21, metadata !28), !dbg !29
15+
tail call void @llvm.dbg.value(metadata i32 %n, i64 0, metadata !22, metadata !28), !dbg !29
16+
%cmp = icmp ult i32 %n, 4, !dbg !30
17+
br i1 %cmp, label %return, label %if.end, !dbg !32
18+
19+
if.end: ; preds = %entry
20+
tail call arm_aapcscc void @g(%struct.s* %s, i8* %b, i32 %n) #3, !dbg !33
21+
br label %return, !dbg !34
22+
23+
return: ; preds = %entry, %if.end
24+
%retval.0 = phi i32 [ 0, %if.end ], [ -1, %entry ]
25+
ret i32 %retval.0, !dbg !35
26+
}
27+
28+
; NOTE: This is checking that the register in the DEBUG_VALUE node is not
29+
; accidentally being marked as KILL. The DBG_VALUE node gets introduced in
30+
; If-Conversion, and gets bundled into the IT block. The Post RA Scheduler
31+
; attempts to schedule the Machine Instr, and tries to tag the register in the
32+
; debug value as KILL'ed, resulting in a DEBUG_VALUE node changing codegen! (or
33+
; hopefully, triggering an assert).
34+
35+
; CHECK: BUNDLE %ITSTATE<imp-def,dead>
36+
; CHECK: * DBG_VALUE %R1, %noreg, !"u"
37+
; CHECK-NOT: * DBG_VALUE %R1<kill>, %noreg, !"u"
38+
39+
declare arm_aapcscc void @g(%struct.s*, i8*, i32) #1
40+
41+
; Function Attrs: nounwind readnone
42+
declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #2
43+
44+
attributes #0 = { nounwind "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
45+
attributes #1 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
46+
attributes #2 = { nounwind readnone }
47+
attributes #3 = { nounwind }
48+
49+
!llvm.dbg.cu = !{!0}
50+
!llvm.module.flags = !{!23, !24, !25, !26}
51+
!llvm.ident = !{!27}
52+
53+
!0 = !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.7.0 (llvm/trunk 237059)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
54+
!1 = !DIFile(filename: "<stdin>", directory: "/Users/compnerd/Source/llvm")
55+
!2 = !{}
56+
!3 = !{!4}
57+
!4 = !DISubprogram(name: "f", scope: !5, file: !5, line: 9, type: !6, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: true, function: i32 (%struct.s*, i32, i8*, i32)* @f, variables: !18)
58+
!5 = !DIFile(filename: "<stdin>", directory: "/Users/compnerd/Source/llvm")
59+
!6 = !DISubroutineType(types: !7)
60+
!7 = !{!8, !9, !12, !13, !17}
61+
!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
62+
!9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 32, align: 32)
63+
!10 = !DIDerivedType(tag: DW_TAG_typedef, name: "s", file: !5, line: 5, baseType: !11)
64+
!11 = !DICompositeType(tag: DW_TAG_structure_type, name: "s", file: !5, line: 5, flags: DIFlagFwdDecl)
65+
!12 = !DIBasicType(name: "unsigned int", size: 32, align: 32, encoding: DW_ATE_unsigned)
66+
!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 32, align: 32)
67+
!14 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !15)
68+
!15 = !DIDerivedType(tag: DW_TAG_typedef, name: "uint8_t", file: !5, line: 2, baseType: !16)
69+
!16 = !DIBasicType(name: "unsigned char", size: 8, align: 8, encoding: DW_ATE_unsigned_char)
70+
!17 = !DIDerivedType(tag: DW_TAG_typedef, name: "size_t", file: !5, line: 3, baseType: !12)
71+
!18 = !{!19, !20, !21, !22}
72+
!19 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "s", arg: 1, scope: !4, file: !5, line: 9, type: !9)
73+
!20 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "u", arg: 2, scope: !4, file: !5, line: 9, type: !12)
74+
!21 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "b", arg: 3, scope: !4, file: !5, line: 9, type: !13)
75+
!22 = !DILocalVariable(tag: DW_TAG_arg_variable, name: "n", arg: 4, scope: !4, file: !5, line: 9, type: !17)
76+
!23 = !{i32 2, !"Dwarf Version", i32 4}
77+
!24 = !{i32 2, !"Debug Info Version", i32 3}
78+
!25 = !{i32 1, !"wchar_size", i32 4}
79+
!26 = !{i32 1, !"min_enum_size", i32 4}
80+
!27 = !{!"clang version 3.7.0 (llvm/trunk 237059)"}
81+
!28 = !DIExpression()
82+
!29 = !DILocation(line: 9, scope: !4)
83+
!30 = !DILocation(line: 10, scope: !31)
84+
!31 = distinct !DILexicalBlock(scope: !4, file: !5, line: 10)
85+
!32 = !DILocation(line: 10, scope: !4)
86+
!33 = !DILocation(line: 13, scope: !4)
87+
!34 = !DILocation(line: 14, scope: !4)
88+
!35 = !DILocation(line: 15, scope: !4)

0 commit comments

Comments
 (0)