1; RUN: opt -licm %s -S | FileCheck %s 2 3; CHECK: for.body: 4; CHECK-NEXT: llvm.dbg.value(metadata i8 undef 5 6; The load is loop invariant. Check that we leave an undef dbg.value behind 7; when licm sinks the instruction. 8 9; clang reduce.cpp -g -O2 -Xclang -disable-llvm-passes -emit-llvm -o reduce.ll 10; opt -simplifycfg -sroa -loop-rotate -o - -S reduce.ll 11; cat reduce.cpp 12; extern char a; 13; extern char b; 14; void use(char); 15; void fun() { 16; char local = 0; 17; for (;b;) 18; local = a; 19; use(local); 20; } 21 22@b = external dso_local global i8, align 1 23@a = external dso_local global i8, align 1 24 25define dso_local void @_Z3funv() !dbg !12 { 26entry: 27 call void @llvm.dbg.value(metadata i8 0, metadata !16, metadata !DIExpression()), !dbg !17 28 %0 = load i8, i8* @b, align 1, !dbg !18 29 %tobool1 = icmp ne i8 %0, 0, !dbg !18 30 br i1 %tobool1, label %for.body.lr.ph, label %for.end, !dbg !24 31 32for.body.lr.ph: ; preds = %entry 33 br label %for.body, !dbg !24 34 35for.body: ; preds = %for.body.lr.ph, %for.body 36 %1 = load i8, i8* @a, align 1, !dbg !25 37 call void @llvm.dbg.value(metadata i8 %1, metadata !16, metadata !DIExpression()), !dbg !17 38 %2 = load i8, i8* @b, align 1, !dbg !18 39 %tobool = icmp ne i8 %2, 0, !dbg !18 40 br i1 %tobool, label %for.body, label %for.cond.for.end_crit_edge, !dbg !24, !llvm.loop !26 41 42for.cond.for.end_crit_edge: ; preds = %for.body 43 %split = phi i8 [ %1, %for.body ] 44 br label %for.end, !dbg !24 45 46for.end: ; preds = %for.cond.for.end_crit_edge, %entry 47 %local.0.lcssa = phi i8 [ %split, %for.cond.for.end_crit_edge ], [ 0, %entry ], !dbg !17 48 call void @llvm.dbg.value(metadata i8 %local.0.lcssa, metadata !16, metadata !DIExpression()), !dbg !17 49 call void @_Z3usec(i8 signext %local.0.lcssa), !dbg !28 50 ret void, !dbg !29 51} 52 53declare !dbg !4 dso_local void @_Z3usec(i8 signext) 54declare void @llvm.dbg.value(metadata, metadata, metadata) 55 56!llvm.dbg.cu = !{!0} 57!llvm.module.flags = !{!8, !9, !10} 58!llvm.ident = !{!11} 59 60!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 11.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3, splitDebugInlining: false, nameTableKind: None) 61!1 = !DIFile(filename: "reduce.cpp", directory: "/") 62!2 = !{} 63!3 = !{!4} 64!4 = !DISubprogram(name: "use", linkageName: "_Z3usec", scope: !1, file: !1, line: 3, type: !5, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2) 65!5 = !DISubroutineType(types: !6) 66!6 = !{null, !7} 67!7 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char) 68!8 = !{i32 7, !"Dwarf Version", i32 4} 69!9 = !{i32 2, !"Debug Info Version", i32 3} 70!10 = !{i32 1, !"wchar_size", i32 4} 71!11 = !{!"clang version 11.0.0"} 72!12 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 4, type: !13, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15) 73!13 = !DISubroutineType(types: !14) 74!14 = !{null} 75!15 = !{!16} 76!16 = !DILocalVariable(name: "local", scope: !12, file: !1, line: 5, type: !7) 77!17 = !DILocation(line: 0, scope: !12) 78!18 = !DILocation(line: 6, column: 9, scope: !19) 79!19 = distinct !DILexicalBlock(scope: !20, file: !1, line: 6, column: 3) 80!20 = distinct !DILexicalBlock(scope: !12, file: !1, line: 6, column: 3) 81!24 = !DILocation(line: 6, column: 3, scope: !20) 82!25 = !DILocation(line: 7, column: 13, scope: !19) 83!26 = distinct !{!26, !24, !27} 84!27 = !DILocation(line: 7, column: 13, scope: !20) 85!28 = !DILocation(line: 8, column: 3, scope: !12) 86!29 = !DILocation(line: 9, column: 1, scope: !12) 87