Skip to content

Commit 4c2e012

Browse files
committed
[GlobalISel] Fix a combine causing DBG_VALUE with dangling vregs.
We should use MachineInstr::eraseFromParentAndMarkDBGValuesForRemoval() instead of eraseFromParent(). We should probably use that in other places too but fix this issue which affects clang bootstrap builds for now.
1 parent bfb7736 commit 4c2e012

File tree

2 files changed

+108
-2
lines changed

2 files changed

+108
-2
lines changed

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,8 +1932,8 @@ void CombinerHelper::applyShiftOfShiftedLogic(MachineInstr &MI,
19321932
Builder.buildInstr(MatchInfo.Logic->getOpcode(), {Dest}, {Shift1, Shift2});
19331933

19341934
// These were one use so it's safe to remove them.
1935-
MatchInfo.Shift2->eraseFromParent();
1936-
MatchInfo.Logic->eraseFromParent();
1935+
MatchInfo.Shift2->eraseFromParentAndMarkDBGValuesForRemoval();
1936+
MatchInfo.Logic->eraseFromParentAndMarkDBGValuesForRemoval();
19371937

19381938
MI.eraseFromParent();
19391939
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc < %s -global-isel -mtriple=arm64-linux-gnu -global-isel-abort=1 | FileCheck %s
3+
target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
4+
target triple = "arm64-apple-ios9.0.0"
5+
6+
; Check we don't fall back due to hitting a DBG_VALUE with a deleted vreg.
7+
8+
%0 = type { %1, %3, %5, %8, i8, i32, i8, i64, [4096 x %9], i64, i64, [4096 x %11], i64, i64, %13, %21, i8*, %35, i64, [504 x i8] }
9+
%1 = type { [32 x %2] }
10+
%2 = type { i32, i32 }
11+
%3 = type { [32 x %4] }
12+
%4 = type { i64, i64 }
13+
%5 = type { [32 x %6] }
14+
%6 = type { %7, %7 }
15+
%7 = type { i8, [64 x i8] }
16+
%8 = type { [1024 x %7], %7 }
17+
%9 = type { %10*, i64 }
18+
%10 = type { i8*, i8*, i8, i8 }
19+
%11 = type { %12*, %12* }
20+
%12 = type { i64, i64 }
21+
%13 = type { %14 }
22+
%14 = type { %15*, %17, %19 }
23+
%15 = type { %16* }
24+
%16 = type <{ %15, %16*, %15*, i8, [7 x i8] }>
25+
%17 = type { %18 }
26+
%18 = type { %15 }
27+
%19 = type { %20 }
28+
%20 = type { i64 }
29+
%21 = type { %22 }
30+
%22 = type <{ %23, %30, %32, %33, [4 x i8] }>
31+
%23 = type { %24 }
32+
%24 = type { %25, %27 }
33+
%25 = type { %26** }
34+
%26 = type { %26* }
35+
%27 = type { %28 }
36+
%28 = type { %29 }
37+
%29 = type { %20 }
38+
%30 = type { %31 }
39+
%31 = type { %26 }
40+
%32 = type { %20 }
41+
%33 = type { %34 }
42+
%34 = type { float }
43+
%35 = type { [1024 x i64] }
44+
45+
@global = external hidden global %0, align 512
46+
47+
define void @baz(i8* %arg) !dbg !6 {
48+
; CHECK-LABEL: baz:
49+
; CHECK: .Lfunc_begin0:
50+
; CHECK-NEXT: .file 1 "/" "tmp.ll"
51+
; CHECK-NEXT: .loc 1 1 0 // tmp.ll:1:0
52+
; CHECK-NEXT: .cfi_startproc
53+
; CHECK-NEXT: // %bb.0: // %bb
54+
; CHECK-NEXT: //DEBUG_VALUE: baz:3 <- undef
55+
; CHECK-NEXT: .loc 1 4 1 prologue_end // tmp.ll:4:1
56+
; CHECK-NEXT: lsl x8, x0, #4
57+
; CHECK-NEXT: .loc 1 0 0 is_stmt 0 // tmp.ll:0:0
58+
; CHECK-NEXT: adrp x9, global+202752
59+
; CHECK-NEXT: .loc 1 4 1 // tmp.ll:4:1
60+
; CHECK-NEXT: and x8, x8, #0x1ff0
61+
; CHECK-NEXT: .loc 1 0 0 // tmp.ll:0:0
62+
; CHECK-NEXT: add x9, x9, :lo12:global+202752
63+
; CHECK-NEXT: .loc 1 5 1 is_stmt 1 // tmp.ll:5:1
64+
; CHECK-NEXT: str xzr, [x9, x8]
65+
; CHECK-NEXT: .loc 1 6 1 // tmp.ll:6:1
66+
; CHECK-NEXT: ret
67+
; CHECK-NEXT: .Ltmp0:
68+
bb:
69+
%tmp = ptrtoint i8* %arg to i64, !dbg !14
70+
%tmp1 = shl i64 %tmp, 1, !dbg !15
71+
%tmp2 = and i64 %tmp1, 1022, !dbg !16
72+
call void @llvm.dbg.value(metadata i64 %tmp2, metadata !12, metadata !DIExpression()), !dbg !16
73+
%tmp3 = getelementptr inbounds %0, %0* @global, i64 0, i32 17, i32 0, i64 %tmp2, !dbg !17
74+
store i64 0, i64* %tmp3, align 16, !dbg !18
75+
ret void, !dbg !19
76+
}
77+
78+
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
79+
declare void @llvm.dbg.value(metadata, metadata, metadata) #1
80+
81+
attributes #1 = { nofree nosync nounwind readnone speculatable willreturn }
82+
83+
!llvm.module.flags = !{!0}
84+
!llvm.dbg.cu = !{!1}
85+
!llvm.debugify = !{!4, !5}
86+
87+
!0 = !{i32 2, !"Debug Info Version", i32 3}
88+
!1 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !3)
89+
!2 = !DIFile(filename: "tmp.ll", directory: "/")
90+
!3 = !{}
91+
!4 = !{i32 6}
92+
!5 = !{i32 4}
93+
!6 = distinct !DISubprogram(name: "baz", linkageName: "baz", scope: null, file: !2, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !1, retainedNodes: !8)
94+
!7 = !DISubroutineType(types: !3)
95+
!8 = !{!9, !11, !12, !13}
96+
!9 = !DILocalVariable(name: "1", scope: !6, file: !2, line: 1, type: !10)
97+
!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
98+
!11 = !DILocalVariable(name: "2", scope: !6, file: !2, line: 2, type: !10)
99+
!12 = !DILocalVariable(name: "3", scope: !6, file: !2, line: 3, type: !10)
100+
!13 = !DILocalVariable(name: "4", scope: !6, file: !2, line: 4, type: !10)
101+
!14 = !DILocation(line: 1, column: 1, scope: !6)
102+
!15 = !DILocation(line: 2, column: 1, scope: !6)
103+
!16 = !DILocation(line: 3, column: 1, scope: !6)
104+
!17 = !DILocation(line: 4, column: 1, scope: !6)
105+
!18 = !DILocation(line: 5, column: 1, scope: !6)
106+
!19 = !DILocation(line: 6, column: 1, scope: !6)

0 commit comments

Comments
 (0)