119 lines · plain
1; RUN: llc %s -stop-after=finalize-isel -o - \2; RUN: | FileCheck %s --implicit-check-not=DBG_3 4;; Hand written to test scenario we can definitely run into in the wild. This5;; file name includes "diamond" because the idea is that we lose (while6;; optimizing) one of the diamond branches which was empty except for a debug7;; intrinsic. In this case, the debug intrinsic linked to the common-and-sunk8;; store now in if.end. So we've got this:9;;10;; entry: ; -> br if.then, if.end11;; mem(a) = !1912;; dbg(a) = !21 ; dbg and mem disagree, don't use mem loc.13;; if.then: ; -> br if.end14;; dbg(a) = !2015;; if.end:16;; mem(a) = !20 ; two preds disagree that !20 is the last assignment, don't17;; ; use mem loc.18;; ; This feels highly unfortunate, and highlights the need to reinstate the19;; ; memory location at call sites leaking the address (in an ideal world,20;; ; the memory location would always be in use at that point and so this21;; ; wouldn't be necessary).22;; esc(a) ; force the memory location23 24;; In real world examples this is caused by InstCombine sinking common code25;; followed by SimplifyCFG deleting empty-except-for-dbg blocks.26 27; CHECK-DAG: ![[A:[0-9]+]] = !DILocalVariable(name: "a",28; CHECK-LABEL: bb.0.entry:29; CHECK: DBG_VALUE $edi, $noreg, ![[A]], !DIExpression()30; CHECK-LABEL: bb.1.if.then:31; CHECK: DBG_VALUE 0, $noreg, ![[A]], !DIExpression()32 33;; === TODO / WISHLIST ===34; LEBAL-KCEHC: bb.2.if.end:35; KCEHC: CALL64pcrel32 target-flags(x86-plt) @es36; KCEHC: DBG_VALUE %stack.0.a.addr, $noreg, ![[A]], !DIExpression(DW_OP_deref)37 38target triple = "x86_64-unknown-linux-gnu"39 40@g = dso_local local_unnamed_addr global ptr null, align 8, !dbg !041 42define dso_local noundef i32 @_Z1fiii(i32 noundef %a, i32 noundef %b, i32 noundef %c) local_unnamed_addr #0 !dbg !12 {43entry:44 %a.addr = alloca i32, align 4, !DIAssignID !1945 call void @llvm.dbg.assign(metadata i1 undef, metadata !16, metadata !DIExpression(), metadata !19, metadata ptr %a.addr, metadata !DIExpression()), !dbg !2046 call void @llvm.dbg.assign(metadata i32 %a, metadata !16, metadata !DIExpression(), metadata !21, metadata ptr %a.addr, metadata !DIExpression()), !dbg !2047 %tobool.not = icmp eq i32 %c, 048 br i1 %tobool.not, label %if.then, label %if.end49 50if.then:51 call void @e()52 call void @llvm.dbg.assign(metadata i32 0, metadata !16, metadata !DIExpression(), metadata !22, metadata ptr %a.addr, metadata !DIExpression()), !dbg !2053 br label %if.end54 55if.end: ; preds = %do.body56 store i32 0, ptr %a.addr, align 4, !DIAssignID !2257 call void @es(ptr %a.addr)58 ret i32 059}60 61declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #262declare void @e()63declare void @es(ptr)64 65!llvm.dbg.cu = !{!2}66!llvm.module.flags = !{!7, !8, !9, !10, !1000}67!llvm.ident = !{!11}68 69!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())70!1 = distinct !DIGlobalVariable(name: "g", scope: !2, file: !3, line: 4, type: !5, isLocal: false, isDefinition: true)71!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)72!3 = !DIFile(filename: "test.cpp", directory: "/")73!4 = !{!0}74!5 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !6, size: 64)75!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)76!7 = !{i32 7, !"Dwarf Version", i32 5}77!8 = !{i32 2, !"Debug Info Version", i32 3}78!9 = !{i32 1, !"wchar_size", i32 4}79!10 = !{i32 7, !"uwtable", i32 1}80!11 = !{!"clang version 14.0.0"}81!12 = distinct !DISubprogram(name: "f", linkageName: "_Z1fiii", scope: !3, file: !3, line: 5, type: !13, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15)82!13 = !DISubroutineType(types: !14)83!14 = !{!6, !6, !6, !6}84!15 = !{!16, !17, !18}85!16 = !DILocalVariable(name: "a", arg: 1, scope: !12, file: !3, line: 5, type: !6)86!17 = !DILocalVariable(name: "b", arg: 2, scope: !12, file: !3, line: 5, type: !6)87!18 = !DILocalVariable(name: "c", arg: 3, scope: !12, file: !3, line: 5, type: !6)88!19 = distinct !DIAssignID()89!20 = !DILocation(line: 0, scope: !12)90!21 = distinct !DIAssignID()91!22 = distinct !DIAssignID()92!23 = distinct !DIAssignID()93!28 = distinct !DIAssignID()94!29 = !DILocation(line: 6, column: 3, scope: !12)95!30 = !DILocation(line: 8, column: 7, scope: !31)96!31 = distinct !DILexicalBlock(scope: !12, file: !3, line: 6, column: 6)97!32 = distinct !DIAssignID()98!33 = !DILocation(line: 10, column: 5, scope: !31)99!34 = !DILocation(line: 11, column: 12, scope: !12)100!35 = !DILocation(line: 11, column: 3, scope: !31)101!36 = distinct !{!36, !29, !37, !38}102!37 = !DILocation(line: 11, column: 15, scope: !12)103!38 = !{!"llvm.loop.mustprogress"}104!39 = !DILocation(line: 12, column: 3, scope: !12)105!40 = !DILocation(line: 13, column: 10, scope: !12)106!41 = !DILocation(line: 13, column: 12, scope: !12)107!42 = !DILocation(line: 13, column: 3, scope: !12)108!43 = !DISubprogram(name: "e", linkageName: "_Z1ev", scope: !3, file: !3, line: 2, type: !44, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !46)109!44 = !DISubroutineType(types: !45)110!45 = !{null}111!46 = !{}112!47 = !DISubprogram(name: "d", linkageName: "_Z1dv", scope: !3, file: !3, line: 1, type: !48, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !46)113!48 = !DISubroutineType(types: !49)114!49 = !{!6}115!50 = !DISubprogram(name: "es", linkageName: "_Z2esPi", scope: !3, file: !3, line: 3, type: !51, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !46)116!51 = !DISubroutineType(types: !52)117!52 = !{null, !5}118!1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}119