1; RUN: opt < %s -loop-reduce -S | FileCheck %s
2
3; Test that LSR does not produce invalid debug info when a debug value is
4; salvaged during LSR by adding additional location operands, then becomes
5; undef, and finally recovered by SCEV salvaging.
6
7target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
8
9define i32 @_Z3fooiii(i32 %Result, i32 %Step, i32 %Last) local_unnamed_addr !dbg !7 {
10; CHECK-LABEL: @_Z3fooiii(
11entry:
12  call void @llvm.dbg.value(metadata i32 %Result, metadata !12, metadata !DIExpression()), !dbg !17
13  call void @llvm.dbg.value(metadata i32 %Step, metadata !13, metadata !DIExpression()), !dbg !17
14  call void @llvm.dbg.value(metadata i32 %Last, metadata !14, metadata !DIExpression()), !dbg !17
15  call void @llvm.dbg.value(metadata i32 0, metadata !16, metadata !DIExpression()), !dbg !17
16  br label %do.body, !dbg !18
17
18do.body:                                          ; preds = %do.body, %entry
19; CHECK-LABEL: do.body:
20  %Result.addr.0 = phi i32 [ %Result, %entry ], [ %or, %do.body ]
21  %Itr.0 = phi i32 [ 0, %entry ], [ %add, %do.body ], !dbg !17
22; CHECK-NOT: call void @llvm.dbg.value(metadata !DIArgList
23; CHECK: call void @llvm.dbg.value(metadata !DIArgList(i32 %lsr.iv, i32 %Step), metadata ![[VAR_ITR:[0-9]+]], metadata !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_minus, DW_OP_LLVM_arg, 1, DW_OP_div, DW_OP_LLVM_arg, 1, DW_OP_mul, DW_OP_stack_value))
24  call void @llvm.dbg.value(metadata i32 %Itr.0, metadata !16, metadata !DIExpression()), !dbg !17
25  call void @llvm.dbg.value(metadata i32 %Result.addr.0, metadata !12, metadata !DIExpression()), !dbg !17
26  %add = add nsw i32 %Itr.0, %Step, !dbg !19
27  call void @llvm.dbg.value(metadata i32 %add, metadata !16, metadata !DIExpression()), !dbg !17
28  %call = tail call i32 @_Z3barv(), !dbg !21
29  call void @llvm.dbg.value(metadata i32 %call, metadata !15, metadata !DIExpression()), !dbg !17
30  %shl = shl i32 %call, %add, !dbg !22
31  %or = or i32 %shl, %Result.addr.0, !dbg !23
32  call void @llvm.dbg.value(metadata i32 %or, metadata !12, metadata !DIExpression()), !dbg !17
33  %and = and i32 %call, %Last, !dbg !24
34  %tobool.not = icmp eq i32 %and, 0, !dbg !25
35  br i1 %tobool.not, label %do.end, label %do.body, !dbg !26, !llvm.loop !27
36
37do.end:                                           ; preds = %do.body
38  ret i32 %or, !dbg !30
39}
40
41declare !dbg !31 dso_local i32 @_Z3barv() local_unnamed_addr
42
43declare void @llvm.dbg.value(metadata, metadata, metadata)
44
45; CHECK: ![[VAR_ITR]] = !DILocalVariable(name: "Itr"
46
47!llvm.dbg.cu = !{!0}
48!llvm.module.flags = !{!3, !4, !5}
49!llvm.ident = !{!6}
50
51!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 13.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
52!1 = !DIFile(filename: "test.cpp", directory: "/")
53!2 = !{}
54!3 = !{i32 7, !"Dwarf Version", i32 4}
55!4 = !{i32 2, !"Debug Info Version", i32 3}
56!5 = !{i32 1, !"wchar_size", i32 4}
57!6 = !{!"clang version 13.0.0"}
58!7 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooiii", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !11)
59!8 = !DISubroutineType(types: !9)
60!9 = !{!10, !10, !10, !10}
61!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
62!11 = !{!12, !13, !14, !15, !16}
63!12 = !DILocalVariable(name: "Result", arg: 1, scope: !7, file: !1, line: 3, type: !10)
64!13 = !DILocalVariable(name: "Step", arg: 2, scope: !7, file: !1, line: 3, type: !10)
65!14 = !DILocalVariable(name: "Last", arg: 3, scope: !7, file: !1, line: 3, type: !10)
66!15 = !DILocalVariable(name: "Bar", scope: !7, file: !1, line: 4, type: !10)
67!16 = !DILocalVariable(name: "Itr", scope: !7, file: !1, line: 5, type: !10)
68!17 = !DILocation(line: 0, scope: !7)
69!18 = !DILocation(line: 6, column: 3, scope: !7)
70!19 = !DILocation(line: 7, column: 9, scope: !20)
71!20 = distinct !DILexicalBlock(scope: !7, file: !1, line: 6, column: 6)
72!21 = !DILocation(line: 8, column: 11, scope: !20)
73!22 = !DILocation(line: 9, column: 20, scope: !20)
74!23 = !DILocation(line: 9, column: 12, scope: !20)
75!24 = !DILocation(line: 10, column: 16, scope: !7)
76!25 = !DILocation(line: 10, column: 12, scope: !7)
77!26 = !DILocation(line: 10, column: 3, scope: !20)
78!27 = distinct !{!27, !18, !28, !29}
79!28 = !DILocation(line: 10, column: 22, scope: !7)
80!29 = !{!"llvm.loop.mustprogress"}
81!30 = !DILocation(line: 11, column: 3, scope: !7)
82!31 = !DISubprogram(name: "bar", linkageName: "_Z3barv", scope: !1, file: !1, line: 1, type: !32, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !2)
83!32 = !DISubroutineType(types: !33)
84!33 = !{!10}
85