1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt < %s -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s 3; RUN: opt < %s -S -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 --try-experimental-debuginfo-iterators | FileCheck %s 4 5; This test case was generated from speculate-dbgvalue.c: 6; 7; int test1(int getdirt, int dirt) { 8; int result = 100; 9; if (getdirt != 0) 10; result = dirt; 11; return result; 12; } 13; 14; using 15; clang speculate-dbgvalue.c -S -emit-llvm -g -O3 -mllvm -disable-llvm-optzns -o - | opt -passes=mem2reg -S 16 17 18; Function Attrs: nounwind uwtable 19define i32 @test1(i32 %getdirt, i32 %dirt) #0 !dbg !7 { 20; CHECK-LABEL: @test1( 21; CHECK-NEXT: entry: 22; CHECK-NEXT: #dbg_value(i32 [[GETDIRT:%.*]], [[META12:![0-9]+]], !DIExpression(), [[META15:![0-9]+]]) 23; CHECK-NEXT: #dbg_value(i32 [[DIRT:%.*]], [[META13:![0-9]+]], !DIExpression(), [[META16:![0-9]+]]) 24; CHECK-NEXT: #dbg_value(i32 100, [[META14:![0-9]+]], !DIExpression(), [[META17:![0-9]+]]) 25; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[GETDIRT]], 0, !dbg [[DBG18:![0-9]+]] 26; CHECK-NEXT: [[SPEC_SELECT:%.*]] = select i1 [[CMP]], i32 [[DIRT]], i32 100, !dbg [[DBG20:![0-9]+]] 27; CHECK-NEXT: #dbg_value(i32 [[SPEC_SELECT]], [[META14]], !DIExpression(), [[META17]]) 28; CHECK-NEXT: ret i32 [[SPEC_SELECT]], !dbg [[DBG21:![0-9]+]] 29; 30; *** We used to get an incorrect "call void @llvm.dbg.value(metadata i32 [[DIRT]], metadata !14, metadata !DIExpression()), !dbg !17" here, before the select. *** 31entry: 32 call void @llvm.dbg.value(metadata i32 %getdirt, metadata !12, metadata !DIExpression()), !dbg !15 33 call void @llvm.dbg.value(metadata i32 %dirt, metadata !13, metadata !DIExpression()), !dbg !16 34 call void @llvm.dbg.value(metadata i32 100, metadata !14, metadata !DIExpression()), !dbg !17 35 %cmp = icmp ne i32 %getdirt, 0, !dbg !18 36 br i1 %cmp, label %if.then, label %if.end, !dbg !20 37 38if.then: ; preds = %entry 39 call void @llvm.dbg.value(metadata i32 %dirt, metadata !14, metadata !DIExpression()), !dbg !17 40 br label %if.end, !dbg !21 41 42if.end: ; preds = %if.then, %entry 43 %result.0 = phi i32 [ %dirt, %if.then ], [ 100, %entry ] 44 call void @llvm.dbg.value(metadata i32 %result.0, metadata !14, metadata !DIExpression()), !dbg !17 45 ret i32 %result.0, !dbg !22 46} 47 48; Function Attrs: nounwind readnone speculatable 49declare void @llvm.dbg.value(metadata, metadata, metadata) #1 50 51attributes #0 = { nounwind uwtable } 52attributes #1 = { nounwind readnone speculatable } 53 54!llvm.dbg.cu = !{!0} 55!llvm.module.flags = !{!3, !4, !5} 56!llvm.ident = !{!6} 57 58!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) 59!1 = !DIFile(filename: "speculate-dbgvalue.c", directory: "/foo") 60!2 = !{} 61!3 = !{i32 2, !"Dwarf Version", i32 4} 62!4 = !{i32 2, !"Debug Info Version", i32 3} 63!5 = !{i32 1, !"wchar_size", i32 4} 64!6 = !{!"clang version 6.0.0"} 65!7 = distinct !DISubprogram(name: "test1", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !11) 66!8 = !DISubroutineType(types: !9) 67!9 = !{!10, !10, !10} 68!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 69!11 = !{!12, !13, !14} 70!12 = !DILocalVariable(name: "getdirt", arg: 1, scope: !7, file: !1, line: 1, type: !10) 71!13 = !DILocalVariable(name: "dirt", arg: 2, scope: !7, file: !1, line: 1, type: !10) 72!14 = !DILocalVariable(name: "result", scope: !7, file: !1, line: 2, type: !10) 73!15 = !DILocation(line: 1, column: 15, scope: !7) 74!16 = !DILocation(line: 1, column: 28, scope: !7) 75!17 = !DILocation(line: 2, column: 7, scope: !7) 76!18 = !DILocation(line: 3, column: 15, scope: !19) 77!19 = distinct !DILexicalBlock(scope: !7, file: !1, line: 3, column: 7) 78!20 = !DILocation(line: 3, column: 7, scope: !7) 79!21 = !DILocation(line: 4, column: 5, scope: !19) 80!22 = !DILocation(line: 5, column: 3, scope: !7) 81