[llvm-shlib] Fix the version naming style of libLLVM for Windows (#85710)
[llvm-project.git] / llvm / test / DebugInfo / assignment-tracking / X86 / remove-redundant-defs-to-prevent-reordering.ll
blob5d52cc342cf2899f3714fbfbceb0d7283931e493
1 ; RUN: llc %s -stop-before finalize-isel -o - \
2 ; RUN:    -experimental-debug-variable-locations=false \
3 ; RUN: | FileCheck %s --check-prefixes=CHECK,DBGVALUE --implicit-check-not="DBG_VALUE \$noreg"
5 ; RUN: llc --try-experimental-debuginfo-iterators %s -stop-before finalize-isel -o - \
6 ; RUN:    -experimental-debug-variable-locations=false \
7 ; RUN: | FileCheck %s --check-prefixes=CHECK,DBGVALUE --implicit-check-not="DBG_VALUE \$noreg"
8 ; RUN: llc %s -stop-before finalize-isel -o - \
9 ; RUN:    -experimental-debug-variable-locations=true \
10 ; RUN: | FileCheck %s --check-prefixes=CHECK,INSTRREF --implicit-check-not="DBG_VALUE \$noreg"
13 ; RUN: llc --try-experimental-debuginfo-iterators %s -stop-before finalize-isel -o - \
14 ; RUN:    -experimental-debug-variable-locations=true \
15 ; RUN: | FileCheck %s --check-prefixes=CHECK,INSTRREF --implicit-check-not="DBG_VALUE \$noreg"
17 ;; Found in the wild, but this test involves modifications from:
18 ;; int b;
19 ;; void ext();
20 ;; int fun(int a) {
21 ;;   if (b == 0)
22 ;;     ext();
24 ;;   a += b;
25 ;;   return a;
26 ;; }
27 ;; A `dbg.assign(undef, ...)` has been added by hand in if.end.
29 ;; For some variable we generate:
30 ;;     %inc = add nuw nsw i32 %i.0128, 1
31 ;;     call void @llvm.dbg.value(metadata i32 undef, ...
32 ;;     call void @llvm.dbg.value(metadata i32 %inc, ...
34 ;; SelectionDAG swaps the dbg.value positions:
35 ;;     %31:gr32 = nuw nsw ADD32ri8 %30:gr32(tied-def 0), 1
36 ;;     DBG_VALUE %31:gr32, ...
37 ;;     DBG_VALUE $noreg, ...
39 ;; Make sure to avoid this by removing redundant dbg.values after lowering
40 ;; dbg.assigns.
42 ;; Check that there's a debug instruction (--implicit-check-not checks no
43 ;; `DBG_VALUE $noreg, ...` has been added).
44 ; CHECK: bb.2.if.end:
45 ; DBGVALUE: DBG_VALUE
46 ; INSTRREF: INSTR_REF
48 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
49 target triple = "x86_64-unknown-linux-gnu"
51 @b = dso_local local_unnamed_addr global i32 0, align 4, !dbg !0
53 ; Function Attrs: uwtable mustprogress
54 define dso_local i32 @_Z3funi(i32 %a) local_unnamed_addr #0 !dbg !11 {
55 entry:
56   call void @llvm.dbg.assign(metadata i1 undef, metadata !15, metadata !DIExpression(), metadata !16, metadata ptr undef, metadata !DIExpression()), !dbg !17
57   call void @llvm.dbg.assign(metadata i32 %a, metadata !15, metadata !DIExpression(), metadata !18, metadata ptr undef, metadata !DIExpression()), !dbg !17
58   %0 = load i32, ptr @b, align 4, !dbg !19
59   %cmp = icmp eq i32 %0, 0, !dbg !25
60   br i1 %cmp, label %if.then, label %if.end, !dbg !26
62 if.then:                                          ; preds = %entry
63   tail call void @_Z3extv(), !dbg !27
64   %.pre = load i32, ptr @b, align 4, !dbg !28
65   br label %if.end, !dbg !27
67 if.end:                                           ; preds = %if.then, %entry
68   %1 = phi i32 [ %.pre, %if.then ], [ %0, %entry ], !dbg !28
69   %add = add nsw i32 %1, %a, !dbg !29
70   ;; Added by hand:
71   call void @llvm.dbg.assign(metadata i32 undef, metadata !15, metadata !DIExpression(), metadata !30, metadata ptr undef, metadata !DIExpression()), !dbg !17
72 call void @llvm.dbg.assign(metadata i32 %add, metadata !15, metadata !DIExpression(), metadata !30, metadata ptr undef, metadata !DIExpression()), !dbg !17
73   ret i32 %add, !dbg !31
76 declare !dbg !32 dso_local void @_Z3extv() local_unnamed_addr #1
78 ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
79 declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #2
81 !llvm.dbg.cu = !{!2}
82 !llvm.module.flags = !{!7, !8, !9, !1000}
83 !llvm.ident = !{!10}
85 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
86 !1 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
87 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !3, producer: "clang version 12.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
88 !3 = !DIFile(filename: "test.cpp", directory: "/")
89 !4 = !{}
90 !5 = !{!0}
91 !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
92 !7 = !{i32 7, !"Dwarf Version", i32 4}
93 !8 = !{i32 2, !"Debug Info Version", i32 3}
94 !9 = !{i32 1, !"wchar_size", i32 4}
95 !10 = !{!"clang version 12.0.0"}
96 !11 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funi", scope: !3, file: !3, line: 3, type: !12, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !14)
97 !12 = !DISubroutineType(types: !13)
98 !13 = !{!6, !6}
99 !14 = !{!15}
100 !15 = !DILocalVariable(name: "a", arg: 1, scope: !11, file: !3, line: 3, type: !6)
101 !16 = distinct !DIAssignID()
102 !17 = !DILocation(line: 0, scope: !11)
103 !18 = distinct !DIAssignID()
104 !19 = !DILocation(line: 4, column: 7, scope: !20)
105 !20 = distinct !DILexicalBlock(scope: !11, file: !3, line: 4, column: 7)
106 !25 = !DILocation(line: 4, column: 9, scope: !20)
107 !26 = !DILocation(line: 4, column: 7, scope: !11)
108 !27 = !DILocation(line: 5, column: 5, scope: !20)
109 !28 = !DILocation(line: 7, column: 8, scope: !11)
110 !29 = !DILocation(line: 7, column: 5, scope: !11)
111 !30 = distinct !DIAssignID()
112 !31 = !DILocation(line: 8, column: 3, scope: !11)
113 !32 = !DISubprogram(name: "ext", linkageName: "_Z3extv", scope: !3, file: !3, line: 2, type: !33, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !4)
114 !33 = !DISubroutineType(types: !34)
115 !34 = !{null}
116 !1000 = !{i32 7, !"debug-info-assignment-tracking", i1 true}