1; RUN: opt -S -passes=jump-threading < %s | FileCheck %s 2; RUN: opt -S -passes=jump-threading < %s --try-experimental-debuginfo-iterators | FileCheck %s 3 4@a = global i32 0, align 4 5; Test that the llvm.dbg.value calls in a threaded block are correctly updated to 6; target the locals in their threaded block, and not the unthreaded one. 7define void @test1(i32 %cond1, i32 %cond2) { 8; CHECK: [[globalptr:@.*]] = global i32 0, align 4 9; CHECK: bb.cond2: 10; CHECK: #dbg_value(ptr null, ![[DBG1ptr:[0-9]+]], !DIExpression(), ![[DBG2ptr:[0-9]+]] 11; CHECK-NEXT: [[TOBOOL1:%.*]] = icmp eq i32 %cond2, 0, !dbg ![[DBGLOCtobool1:[0-9]+]] 12; CHECK-NEXT: #dbg_value(!DIArgList(ptr null, i1 [[TOBOOL1]], i1 [[TOBOOL1]]), !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_LLVM_arg, 2, DW_OP_plus), !{{[0-9]+}} 13; CHECK: bb.cond2.thread: 14; CHECK-NEXT: #dbg_value(ptr [[globalptr]], ![[DBG1ptr]], !DIExpression(), ![[DBG2ptr]] 15; CHECK-NEXT: [[TOBOOL12:%.*]] = icmp eq i32 %cond2, 0, !dbg ![[DBGLOCtobool1]] 16; CHECK-NEXT: #dbg_value(!DIArgList(ptr [[globalptr]], i1 [[TOBOOL12]], i1 [[TOBOOL12]]), !{{[0-9]+}}, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_LLVM_arg, 2, DW_OP_plus), !{{[0-9]+}} 17entry: 18 %tobool = icmp eq i32 %cond1, 0, !dbg !15 19 call void @llvm.dbg.value(metadata i1 %tobool, metadata !9, metadata !DIExpression()), !dbg !15 20 br i1 %tobool, label %bb.cond2, label %bb.f1, !dbg !16 21 22bb.f1: ; preds = %entry 23 call void @f1(), !dbg !17 24 br label %bb.cond2, !dbg !18 25 26bb.cond2: ; preds = %bb.f1, %entry 27 %ptr = phi ptr [ null, %bb.f1 ], [ @a, %entry ], !dbg !19 28 call void @llvm.dbg.value(metadata ptr %ptr, metadata !11, metadata !DIExpression()), !dbg !19 29 %tobool1 = icmp eq i32 %cond2, 0, !dbg !20 30 call void @llvm.dbg.value(metadata !DIArgList(ptr %ptr, i1 %tobool1, i1 %tobool1), metadata !13, metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_LLVM_arg, 2, DW_OP_plus)), !dbg !20 31 br i1 %tobool1, label %bb.file, label %bb.f2, !dbg !21 32 33bb.f2: ; preds = %bb.cond2 34 call void @f2(), !dbg !22 35 br label %exit, !dbg !23 36 37bb.file: ; preds = %bb.cond2 38 %cmp = icmp eq ptr %ptr, null, !dbg !24 39 call void @llvm.dbg.value(metadata i1 %cmp, metadata !14, metadata !DIExpression()), !dbg !24 40 br i1 %cmp, label %bb.f4, label %bb.f3, !dbg !25 41 42bb.f3: ; preds = %bb.file 43 br label %exit, !dbg !26 44 45bb.f4: ; preds = %bb.file 46 call void @f4(), !dbg !27 47 br label %exit, !dbg !28 48 49exit: ; preds = %bb.f4, %bb.f3, %bb.f2 50 ret void, !dbg !29 51} 52 53; This is testing for debug value intrinsics outside of the threaded block pointing to a value 54; inside to correctly take any new definitions. 55define void @test2(i32 %cond1, i32 %cond2) !dbg !5 { 56; CHECK: bb.f3 57; CHECK: #dbg_value(ptr @a, !{{[0-9]+}}, !DIExpression(), !{{[0-9]+}} 58; CHECK: bb.f4 59; CHECK-NEXT: [[PTR3:%.*]] = phi ptr [ null, %bb.cond2 ] 60; CHECK-NEXT: #dbg_value(ptr [[PTR3]], !{{[0-9]+}}, !DIExpression(), !{{[0-9]+}} 61entry: 62 %tobool = icmp eq i32 %cond1, 0, !dbg !15 63 br i1 %tobool, label %bb.cond2, label %bb.f1, !dbg !16 64 65bb.f1: ; preds = %entry 66 call void @f1(), !dbg !17 67 br label %bb.cond2, !dbg !18 68 69bb.cond2: ; preds = %bb.f1, %entry 70 %ptr = phi ptr [ null, %bb.f1 ], [ @a, %entry ], !dbg !19 71 %tobool1 = icmp eq i32 %cond2, 0, !dbg !20 72 br i1 %tobool1, label %bb.file, label %bb.f2, !dbg !21 73 74bb.f2: ; preds = %bb.cond2 75 call void @f2(), !dbg !22 76 br label %exit, !dbg !23 77 78bb.file: ; preds = %bb.cond2 79 %cmp = icmp eq ptr %ptr, null, !dbg !24 80 call void @llvm.dbg.value(metadata ptr %ptr, metadata !14, metadata !DIExpression()), !dbg !21 81 br i1 %cmp, label %bb.f4, label %bb.f3, !dbg !25 82 83bb.f3: ; preds = %bb.file 84 call void @f3(), !dbg !26 85 br label %exit, !dbg !27 86 87bb.f4: ; preds = %bb.file 88 call void @f4(), !dbg !28 89 br label %exit, !dbg !29 90 91exit: ; preds = %bb.f4, %bb.f3, %bb.f2 92 ret void, !dbg !29 93} 94 95; Test for the cloning of dbg.values on elided instructions -- down one path 96; being threaded, the `and` in the function below is optimised away, but its 97; debug-info should still be preserved. 98; Similarly, the call to f1 gets cloned, its dbg.value should be cloned too. 99; Duplicated debug value in land.end.thr_comm is removed by 100; RemoveRedundantDbgInstrs pass at the end. 101define void @test16(i1 %c, i1 %c2, i1 %c3, i1 %c4) nounwind ssp !dbg !30 { 102; CHECK-LABEL: define void @test16(i1 103entry: 104 %cmp = icmp sgt i32 undef, 1, !dbg !33 105 br i1 %c, label %land.end, label %land.rhs, !dbg !33 106 107land.rhs: 108 br i1 %c2, label %lor.lhs.false.i, label %land.end, !dbg !33 109 110lor.lhs.false.i: 111 br i1 %c3, label %land.end, label %land.end, !dbg !33 112 113; CHECK-LABEL: land.end.thr_comm: 114; CHECK-NEXT: #dbg_value(i32 1, 115; CHECK-NEXT: call void @f1() 116; CHECK-NEXT: br i1 %c4, 117 118; CHECK-LABEL: land.end: 119; CHECK-NEXT: %0 = phi i1 120; CHECK-NEXT: #dbg_value(i32 0, 121land.end: 122 %0 = phi i1 [ true, %entry ], [ false, %land.rhs ], [false, %lor.lhs.false.i], [false, %lor.lhs.false.i] 123 call void @llvm.dbg.value(metadata i32 0, metadata !32, metadata !DIExpression()), !dbg !33 124 %cmp12 = and i1 %cmp, %0, !dbg !33 125 %xor1 = xor i1 %cmp12, %c4, !dbg !33 126 call void @llvm.dbg.value(metadata i32 1, metadata !32, metadata !DIExpression()), !dbg !33 127 call void @f1() 128 br i1 %xor1, label %if.then, label %if.end, !dbg !33 129 130if.then: 131 ret void, !dbg !33 132 133if.end: 134 ret void, !dbg !33 135} 136 137declare void @f1() 138 139declare void @f2() 140 141declare void @f3() 142 143declare void @f4() 144 145; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) 146declare void @llvm.dbg.value(metadata, metadata, metadata) #0 147 148attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } 149 150!llvm.dbg.cu = !{!0} 151!llvm.debugify = !{!2, !3} 152!llvm.module.flags = !{!4} 153 154!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug) 155!1 = !DIFile(filename: "/home/ben/Documents/llvm-project/llvm/test/Transforms/JumpThreading/thread-debug-info.ll", directory: "/") 156!2 = !{i32 15} 157!3 = !{i32 4} 158!4 = !{i32 2, !"Debug Info Version", i32 3} 159!5 = distinct !DISubprogram(name: "test2", linkageName: "test2", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8) 160!6 = !DISubroutineType(types: !7) 161!7 = !{} 162!8 = !{!9, !11, !13, !14} 163!9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 1, type: !10) 164!10 = !DIBasicType(name: "ty8", size: 8, encoding: DW_ATE_unsigned) 165!11 = !DILocalVariable(name: "2", scope: !5, file: !1, line: 5, type: !12) 166!12 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned) 167!13 = !DILocalVariable(name: "3", scope: !5, file: !1, line: 6, type: !10) 168!14 = !DILocalVariable(name: "4", scope: !5, file: !1, line: 10, type: !10) 169!15 = !DILocation(line: 1, column: 1, scope: !5) 170!16 = !DILocation(line: 2, column: 1, scope: !5) 171!17 = !DILocation(line: 3, column: 1, scope: !5) 172!18 = !DILocation(line: 4, column: 1, scope: !5) 173!19 = !DILocation(line: 5, column: 1, scope: !5) 174!20 = !DILocation(line: 6, column: 1, scope: !5) 175!21 = !DILocation(line: 7, column: 1, scope: !5) 176!22 = !DILocation(line: 8, column: 1, scope: !5) 177!23 = !DILocation(line: 9, column: 1, scope: !5) 178!24 = !DILocation(line: 10, column: 1, scope: !5) 179!25 = !DILocation(line: 11, column: 1, scope: !5) 180!26 = !DILocation(line: 12, column: 1, scope: !5) 181!27 = !DILocation(line: 13, column: 1, scope: !5) 182!28 = !DILocation(line: 14, column: 1, scope: !5) 183!29 = !DILocation(line: 15, column: 1, scope: !5) 184!30 = distinct !DISubprogram(name: "test13", linkageName: "test13", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !31) 185!31 = !{!32} 186!32 = !DILocalVariable(name: "1", scope: !30, file: !1, line: 1, type: !10) 187!33 = !DILocation(line: 1, column: 1, scope: !30) 188