xref: /llvm-project/llvm/test/DebugInfo/COFF/fpo-shrink-wrap.ll (revision 5a288fa32e0c91b211e39f3e370255916902f898)
1; RUN: llc -enable-shrink-wrap=true < %s -experimental-debug-variable-locations=true | FileCheck %s --check-prefix=ASM
2; RUN: llc -enable-shrink-wrap=true -filetype=obj < %s -experimental-debug-variable-locations=true | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
3
4; C source:
5; int doSomething(int*);
6; int __fastcall shrink_wrap_basic(int a, int b, int c, int d) {
7;   if (a < b)
8;     return a;
9;   for (int i = c; i < d; ++i)
10;     doSomething(&c);
11;   return doSomething(&c);
12; }
13
14; ASM: @shrink_wrap_basic@16:                  # @"\01@shrink_wrap_basic@16"
15; ASM:         .cv_fpo_proc    @shrink_wrap_basic@16 8
16; ASM:         .cv_loc 0 1 3 9                 # t.c:3:9
17; ASM:         movl    %ecx, %eax
18; ASM:         cmpl    %edx, %ecx
19; ASM:         jl      [[EPILOGUE:LBB0_[0-9]+]]
20
21; ASM:         pushl   %ebx
22; ASM:         .cv_fpo_pushreg %ebx
23; ASM:         pushl   %edi
24; ASM:         .cv_fpo_pushreg %edi
25; ASM:         pushl   %esi
26; ASM:         .cv_fpo_pushreg %esi
27; ASM:         .cv_fpo_endprologue
28
29; ASM:         calll   _doSomething
30
31; ASM:         popl    %esi
32; ASM:         popl    %edi
33; ASM:         popl    %ebx
34; ASM: [[EPILOGUE]]:                                 # %return
35; ASM:         retl    $8
36; ASM: Ltmp12:
37; ASM:         .cv_fpo_endproc
38
39; Note how RvaStart advances 7 bytes to skip the shrink-wrapped portion.
40; OBJ: SubSectionType: FrameData (0xF5)
41; OBJ:    FrameData {
42; OBJ:      RvaStart: 0x0
43; OBJ:      CodeSize: 0x34
44; OBJ:      PrologSize: 0x9
45; OBJ:      FrameFunc [
46; OBJ-NEXT:   $T0 .raSearch =
47; OBJ-NEXT:   $eip $T0 ^ =
48; OBJ-NEXT:   $esp $T0 4 + =
49; OBJ-NEXT: ]
50; OBJ:    }
51; OBJ:    FrameData {
52; OBJ:      RvaStart: 0x7
53; OBJ:      CodeSize: 0x2D
54; OBJ:      PrologSize: 0x2
55; OBJ:      FrameFunc [
56; OBJ-NEXT:   $T0 .raSearch =
57; OBJ-NEXT:   $eip $T0 ^ =
58; OBJ-NEXT:   $esp $T0 4 + =
59; OBJ-NEXT:   $ebx $T0 4 - ^ =
60; OBJ-NEXT: ]
61; OBJ:    }
62; OBJ:    FrameData {
63; OBJ:      RvaStart: 0x8
64; OBJ:      CodeSize: 0x2C
65; OBJ:      PrologSize: 0x1
66; OBJ:      FrameFunc [
67; OBJ-NEXT:   $T0 .raSearch =
68; OBJ-NEXT:   $eip $T0 ^ =
69; OBJ-NEXT:   $esp $T0 4 + =
70; OBJ-NEXT:   $ebx $T0 4 - ^ =
71; OBJ-NEXT:   $edi $T0 8 - ^ =
72; OBJ-NEXT: ]
73; OBJ:    }
74; OBJ:    FrameData {
75; OBJ:      RvaStart: 0x9
76; OBJ:      CodeSize: 0x2B
77; OBJ:      PrologSize: 0x0
78; OBJ:      FrameFunc [
79; OBJ-NEXT:   $T0 .raSearch =
80; OBJ-NEXT:   $eip $T0 ^ =
81; OBJ-NEXT:   $esp $T0 4 + =
82; OBJ-NEXT:   $ebx $T0 4 - ^ =
83; OBJ-NEXT:   $edi $T0 8 - ^ =
84; OBJ-NEXT:   $esi $T0 12 - ^ =
85; OBJ-NEXT: ]
86; OBJ:    }
87; OBJ-NOT: FrameData
88
89; ModuleID = 't.c'
90source_filename = "t.c"
91target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
92target triple = "i386-pc-windows-msvc19.11.25508"
93
94; Function Attrs: nounwind
95define x86_fastcallcc i32 @"\01@shrink_wrap_basic@16"(i32 inreg %a, i32 inreg %b, i32 %c, i32 %d) local_unnamed_addr #0 !dbg !8 {
96entry:
97  %c.addr = alloca i32, align 4
98  tail call void @llvm.dbg.value(metadata i32 %d, metadata !13, metadata !DIExpression()), !dbg !19
99  tail call void @llvm.dbg.value(metadata i32 %c, metadata !14, metadata !DIExpression()), !dbg !20
100  store i32 %c, ptr %c.addr, align 4, !tbaa !21
101  tail call void @llvm.dbg.value(metadata i32 %b, metadata !15, metadata !DIExpression()), !dbg !25
102  tail call void @llvm.dbg.value(metadata i32 %a, metadata !16, metadata !DIExpression()), !dbg !26
103  %cmp = icmp slt i32 %a, %b, !dbg !27
104  br i1 %cmp, label %return, label %for.cond.preheader, !dbg !29
105
106for.cond.preheader:                               ; preds = %entry
107  br label %for.cond, !dbg !30
108
109for.cond:                                         ; preds = %for.cond.preheader, %for.cond
110  %i.0 = phi i32 [ %inc, %for.cond ], [ %c, %for.cond.preheader ]
111  call void @llvm.dbg.value(metadata i32 %i.0, metadata !17, metadata !DIExpression()), !dbg !32
112  %cmp1 = icmp slt i32 %i.0, %d, !dbg !30
113  call void @llvm.dbg.value(metadata ptr %c.addr, metadata !14, metadata !DIExpression()), !dbg !20
114  %call = call i32 @doSomething(ptr nonnull %c.addr) #3, !dbg !33
115  %inc = add nsw i32 %i.0, 1, !dbg !34
116  call void @llvm.dbg.value(metadata i32 %inc, metadata !17, metadata !DIExpression()), !dbg !32
117  br i1 %cmp1, label %for.cond, label %return, !dbg !35, !llvm.loop !36
118
119return:                                           ; preds = %for.cond, %entry
120  %retval.0 = phi i32 [ %a, %entry ], [ %call, %for.cond ]
121  ret i32 %retval.0, !dbg !38
122}
123
124declare i32 @doSomething(ptr) local_unnamed_addr #1
125
126; Function Attrs: nounwind readnone speculatable
127declare void @llvm.dbg.value(metadata, metadata, metadata) #2
128
129attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
130attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="pentium4" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
131attributes #2 = { nounwind readnone speculatable }
132attributes #3 = { nounwind }
133
134!llvm.dbg.cu = !{!0}
135!llvm.module.flags = !{!3, !4, !5, !6}
136!llvm.ident = !{!7}
137
138!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
139!1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "32f118fd5dd7e65ff7733c49b2f804ef")
140!2 = !{}
141!3 = !{i32 1, !"NumRegisterParameters", i32 0}
142!4 = !{i32 2, !"CodeView", i32 1}
143!5 = !{i32 2, !"Debug Info Version", i32 3}
144!6 = !{i32 1, !"wchar_size", i32 2}
145!7 = !{!"clang version 6.0.0 "}
146!8 = distinct !DISubprogram(name: "shrink_wrap_basic", linkageName: "\01@shrink_wrap_basic@16", scope: !1, file: !1, line: 2, type: !9, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
147!9 = !DISubroutineType(cc: DW_CC_BORLAND_msfastcall, types: !10)
148!10 = !{!11, !11, !11, !11, !11}
149!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
150!12 = !{!13, !14, !15, !16, !17}
151!13 = !DILocalVariable(name: "d", arg: 4, scope: !8, file: !1, line: 2, type: !11)
152!14 = !DILocalVariable(name: "c", arg: 3, scope: !8, file: !1, line: 2, type: !11)
153!15 = !DILocalVariable(name: "b", arg: 2, scope: !8, file: !1, line: 2, type: !11)
154!16 = !DILocalVariable(name: "a", arg: 1, scope: !8, file: !1, line: 2, type: !11)
155!17 = !DILocalVariable(name: "i", scope: !18, file: !1, line: 5, type: !11)
156!18 = distinct !DILexicalBlock(scope: !8, file: !1, line: 5, column: 3)
157!19 = !DILocation(line: 2, column: 59, scope: !8)
158!20 = !DILocation(line: 2, column: 52, scope: !8)
159!21 = !{!22, !22, i64 0}
160!22 = !{!"int", !23, i64 0}
161!23 = !{!"omnipotent char", !24, i64 0}
162!24 = !{!"Simple C/C++ TBAA"}
163!25 = !DILocation(line: 2, column: 45, scope: !8)
164!26 = !DILocation(line: 2, column: 38, scope: !8)
165!27 = !DILocation(line: 3, column: 9, scope: !28)
166!28 = distinct !DILexicalBlock(scope: !8, file: !1, line: 3, column: 7)
167!29 = !DILocation(line: 3, column: 7, scope: !8)
168!30 = !DILocation(line: 5, column: 21, scope: !31)
169!31 = distinct !DILexicalBlock(scope: !18, file: !1, line: 5, column: 3)
170!32 = !DILocation(line: 5, column: 12, scope: !18)
171!33 = !DILocation(line: 0, scope: !8)
172!34 = !DILocation(line: 5, column: 26, scope: !31)
173!35 = !DILocation(line: 5, column: 3, scope: !18)
174!36 = distinct !{!36, !35, !37}
175!37 = !DILocation(line: 6, column: 19, scope: !18)
176!38 = !DILocation(line: 8, column: 1, scope: !8)
177