1 ; FIXME: use -stop-after when MIR serialization output includes needed debug info.
2 ; RUN: llc < %s -print-after=wasm-reg-stackify 2>&1 | FileCheck %s
4 ; CHECK: {{.*}}After WebAssembly Register Stackify
5 ; CHECK: bb.3.for.body.for.body_crit_edge:
6 ; CHECK: [[REG:%[0-9]+]]:i32 = nsw ADD_I32 {{.*}} fib.c:7:7
7 ; CHECK-NEXT: DBG_VALUE [[REG]]:i32, $noreg, !"a", {{.*}} fib.c:5:13
10 ; The test generated via: clang --target=wasm32-unknown-unknown-wasm fib.c -g -O2
11 ; All lifetime markers and attributes were removed.
12 source_filename = "fib.c"
13 ; void swap(int* a, int* b);
15 ; __attribute__ ((visibility ("default")))
17 ; int i, t, a = 0, b = 1;
18 ; for (i = 0; i < n; i++) {
24 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
25 target triple = "wasm32-unknown-unknown-wasm"
27 ; Function Attrs: nounwind
28 define i32 @fib(i32 %n) local_unnamed_addr #0 !dbg !7 {
30 %a = alloca i32, align 4
31 %b = alloca i32, align 4
32 call void @llvm.dbg.value(metadata i32 %n, metadata !12, metadata !DIExpression()), !dbg !17
33 call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !DIExpression()), !dbg !19
34 store i32 0, ptr %a, align 4, !dbg !19, !tbaa !20
35 call void @llvm.dbg.value(metadata i32 1, metadata !16, metadata !DIExpression()), !dbg !24
36 store i32 1, ptr %b, align 4, !dbg !24, !tbaa !20
37 call void @llvm.dbg.value(metadata i32 0, metadata !13, metadata !DIExpression()), !dbg !25
38 %cmp4 = icmp sgt i32 %n, 0, !dbg !26
39 call void @llvm.dbg.value(metadata i32 1, metadata !16, metadata !DIExpression()), !dbg !24
40 br i1 %cmp4, label %for.body.preheader, label %for.end, !dbg !29
42 for.body.preheader: ; preds = %entry
43 call void @llvm.dbg.value(metadata i32 0, metadata !13, metadata !DIExpression()), !dbg !25
44 call void @llvm.dbg.value(metadata i32 0, metadata !15, metadata !DIExpression()), !dbg !19
45 call void @llvm.dbg.value(metadata i32 1, metadata !15, metadata !DIExpression()), !dbg !19
46 store i32 1, ptr %a, align 4, !dbg !30, !tbaa !20
47 call void @llvm.dbg.value(metadata ptr %a, metadata !15, metadata !DIExpression()), !dbg !19
48 call void @llvm.dbg.value(metadata ptr %b, metadata !16, metadata !DIExpression()), !dbg !24
49 call void @swap(ptr nonnull %a, ptr nonnull %b) #5, !dbg !32
50 call void @llvm.dbg.value(metadata i32 1, metadata !13, metadata !DIExpression()), !dbg !25
51 %0 = load i32, ptr %b, align 4, !dbg !33, !tbaa !20
52 call void @llvm.dbg.value(metadata i32 %0, metadata !16, metadata !DIExpression()), !dbg !24
53 %exitcond9 = icmp eq i32 %n, 1, !dbg !26
54 br i1 %exitcond9, label %for.end, label %for.body.for.body_crit_edge, !dbg !29, !llvm.loop !34
56 for.body.for.body_crit_edge: ; preds = %for.body.preheader, %for.body.for.body_crit_edge
57 %1 = phi i32 [ %2, %for.body.for.body_crit_edge ], [ %0, %for.body.preheader ]
58 %inc10 = phi i32 [ %inc, %for.body.for.body_crit_edge ], [ 1, %for.body.preheader ]
59 %.pre = load i32, ptr %a, align 4, !dbg !30, !tbaa !20
60 call void @llvm.dbg.value(metadata i32 %inc10, metadata !13, metadata !DIExpression()), !dbg !25
61 call void @llvm.dbg.value(metadata i32 %.pre, metadata !15, metadata !DIExpression()), !dbg !19
62 %add = add nsw i32 %.pre, %1, !dbg !30
63 call void @llvm.dbg.value(metadata i32 %add, metadata !15, metadata !DIExpression()), !dbg !19
64 store i32 %add, ptr %a, align 4, !dbg !30, !tbaa !20
65 call void @llvm.dbg.value(metadata ptr %a, metadata !15, metadata !DIExpression()), !dbg !19
66 call void @llvm.dbg.value(metadata ptr %b, metadata !16, metadata !DIExpression()), !dbg !24
67 call void @swap(ptr nonnull %a, ptr nonnull %b) #5, !dbg !32
68 %inc = add nuw nsw i32 %inc10, 1, !dbg !36
69 call void @llvm.dbg.value(metadata i32 %inc, metadata !13, metadata !DIExpression()), !dbg !25
70 %2 = load i32, ptr %b, align 4, !dbg !33, !tbaa !20
71 call void @llvm.dbg.value(metadata i32 %2, metadata !16, metadata !DIExpression()), !dbg !24
72 %exitcond = icmp eq i32 %inc, %n, !dbg !26
73 br i1 %exitcond, label %for.end, label %for.body.for.body_crit_edge, !dbg !29, !llvm.loop !34
75 for.end: ; preds = %for.body.for.body_crit_edge, %for.body.preheader, %entry
76 %.lcssa = phi i32 [ 1, %entry ], [ %0, %for.body.preheader ], [ %2, %for.body.for.body_crit_edge ]
77 ret i32 %.lcssa, !dbg !38
80 declare void @swap(ptr, ptr) local_unnamed_addr #2
82 ; Function Attrs: nounwind readnone speculatable
83 declare void @llvm.dbg.value(metadata, metadata, metadata) #4
86 !llvm.module.flags = !{!3, !4, !5}
89 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (trunk 334610)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
90 !1 = !DIFile(filename: "fib.c", directory: "/d/y/llvmwasm")
92 !3 = !{i32 2, !"Dwarf Version", i32 4}
93 !4 = !{i32 2, !"Debug Info Version", i32 3}
94 !5 = !{i32 1, !"wchar_size", i32 4}
95 !6 = !{!"clang version 7.0.0 (trunk 334610)"}
96 !7 = distinct !DISubprogram(name: "fib", scope: !1, file: !1, line: 4, type: !8, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !11)
97 !8 = !DISubroutineType(types: !9)
99 !10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
100 !11 = !{!12, !13, !14, !15, !16}
101 !12 = !DILocalVariable(name: "n", arg: 1, scope: !7, file: !1, line: 4, type: !10)
102 !13 = !DILocalVariable(name: "i", scope: !7, file: !1, line: 5, type: !10)
103 !14 = !DILocalVariable(name: "t", scope: !7, file: !1, line: 5, type: !10)
104 !15 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 5, type: !10)
105 !16 = !DILocalVariable(name: "b", scope: !7, file: !1, line: 5, type: !10)
106 !17 = !DILocation(line: 4, column: 13, scope: !7)
107 !18 = !DILocation(line: 5, column: 3, scope: !7)
108 !19 = !DILocation(line: 5, column: 13, scope: !7)
109 !20 = !{!21, !21, i64 0}
110 !21 = !{!"int", !22, i64 0}
111 !22 = !{!"omnipotent char", !23, i64 0}
112 !23 = !{!"Simple C/C++ TBAA"}
113 !24 = !DILocation(line: 5, column: 20, scope: !7)
114 !25 = !DILocation(line: 5, column: 7, scope: !7)
115 !26 = !DILocation(line: 6, column: 17, scope: !27)
116 !27 = distinct !DILexicalBlock(scope: !28, file: !1, line: 6, column: 3)
117 !28 = distinct !DILexicalBlock(scope: !7, file: !1, line: 6, column: 3)
118 !29 = !DILocation(line: 6, column: 3, scope: !28)
119 !30 = !DILocation(line: 7, column: 7, scope: !31)
120 !31 = distinct !DILexicalBlock(scope: !27, file: !1, line: 6, column: 27)
121 !32 = !DILocation(line: 8, column: 5, scope: !31)
122 !33 = !DILocation(line: 0, scope: !7)
123 !34 = distinct !{!34, !29, !35}
124 !35 = !DILocation(line: 9, column: 3, scope: !28)
125 !36 = !DILocation(line: 6, column: 23, scope: !27)
126 !37 = !DILocation(line: 11, column: 1, scope: !7)
127 !38 = !DILocation(line: 10, column: 3, scope: !7)
128 !39 = distinct !DISubprogram(name: "_start", scope: !1, file: !1, line: 13, type: !40, isLocal: false, isDefinition: true, scopeLine: 13, isOptimized: true, unit: !0, retainedNodes: !2)
129 !40 = !DISubroutineType(types: !41)
131 !42 = !DILocation(line: 13, column: 16, scope: !39)