1; RUN: llc < %s | FileCheck %s --check-prefix=ASM
2; RUN: llc -filetype=obj < %s | llvm-readobj --codeview | FileCheck %s --check-prefix=OBJ
3
4; PR38857
5
6; This test case is identical to the fpo-realign-vframe.ll test, except it uses
7; two callee-saved registers.
8
9; Match the prologue for the .cv_fpo* directives.
10; ASM-LABEL: _realign_with_csrs:
11; ASM:         .cv_fpo_proc    _realign_with_csrs 0
12; ASM: # %bb.0:                                # %entry
13; ASM:         pushl   %ebp
14; ASM:         .cv_fpo_pushreg %ebp
15; ASM:         movl    %esp, %ebp
16; ASM:         .cv_fpo_setframe        %ebp
17; ASM:         andl    $-8, %esp
18; ASM:         .cv_fpo_stackalign      8
19; FIXME: Why 24 bytes? We only need 12 bytes of data.
20; ASM:         subl    $24, %esp
21; ASM:         .cv_fpo_stackalloc      24
22; ASM:         .cv_fpo_endprologue
23
24; 'x' should be EBP-relative, 'a' and 'force_alignment' ESP relative.
25; ASM:         calll   _getval
26; ASM-DAG:     leal    8(%esp), %[[LEA_DBL:[^ ]*]]
27; ASM-DAG:     leal    4(%esp), %[[LEA_A:[^ ]*]]
28; ASM:         pushl   %[[LEA_DBL]]
29; ASM:         pushl   %[[LEA_A]]
30; ASM:         pushl   %[[LEA_A]]
31; ASM:         calll   _usevals
32; ASM:         addl    $12, %esp
33
34; OBJ: Subsection [
35; OBJ:   SubSectionType: Symbols (0xF1)
36; OBJ: ]
37; OBJ: Subsection [
38; OBJ:   SubSectionType: FrameData (0xF5)
39;   	Really, the only important FrameFunc is the last one.
40; OBJ:   FrameData {
41; OBJ:   }
42; OBJ:   FrameData {
43; OBJ:   }
44; OBJ:   FrameData {
45; OBJ:   }
46; OBJ:   FrameData {
47; OBJ:   }
48; OBJ:   FrameData {
49; OBJ:     FrameFunc [
50; OBJ-NEXT:   $T1 $ebp 4 + =
51; OBJ-NEXT:   $T0 $T1 8 - 8 @ =
52; OBJ-NEXT:   $eip $T1 ^ =
53; OBJ-NEXT:   $esp $T1 4 + =
54; OBJ-NEXT:   $ebp $T1 4 - ^ =
55; OBJ-NEXT:   $esi $T1 8 - ^ =
56; OBJ-NEXT: ]
57; OBJ:   }
58; OBJ: ]
59; OBJ: Subsection [
60; OBJ:   SubSectionType: Symbols (0xF1)
61; OBJ:   GlobalProcIdSym {
62; OBJ:     Kind: S_GPROC32_ID (0x1147)
63; OBJ:     DisplayName: realign_with_csrs
64; OBJ:     LinkageName: _realign_with_csrs
65; OBJ:   }
66; 	The frame register for locals should be VFRAME, and EBP for parameters.
67; OBJ:   FrameProcSym {
68; OBJ:     Kind: S_FRAMEPROC (0x1012)
69; OBJ:     TotalFrameBytes: 0x18
70; OBJ:     LocalFramePtrReg: VFRAME (0x7536)
71; OBJ:     ParamFramePtrReg: EBP (0x16)
72; OBJ:   }
73; 	ESP is VFRAME - 24, ESP offset of 'a' is 4, so -20.
74; OBJ:   LocalSym {
75; OBJ:     Kind: S_LOCAL (0x113E)
76; OBJ:     Type: int (0x74)
77; OBJ:     Flags [ (0x0)
78; OBJ:     ]
79; OBJ:     VarName: a
80; OBJ:   }
81; OBJ:   DefRangeFramePointerRelSym {
82; OBJ:     Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
83; OBJ:     Offset: -20
84; OBJ:   }
85; 	ESP is VFRAME - 16, ESP offset of 'force_alignment' is 8, so -8.
86; OBJ:   LocalSym {
87; OBJ:     Kind: S_LOCAL (0x113E)
88; OBJ:     Type: double (0x41)
89; OBJ:     Flags [ (0x0)
90; OBJ:     ]
91; OBJ:     VarName: force_alignment
92; OBJ:   }
93; OBJ:   DefRangeFramePointerRelSym {
94; OBJ:     Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
95; OBJ:     Offset: -16
96; OBJ:   }
97; OBJ:   ProcEnd {
98; OBJ:     Kind: S_PROC_ID_END (0x114F)
99; OBJ:   }
100; OBJ: ]
101
102; ModuleID = 't.c'
103source_filename = "t.c"
104target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
105target triple = "i386-pc-windows-msvc19.14.26433"
106
107; Function Attrs: nounwind
108define dso_local i32 @realign_with_csrs() local_unnamed_addr #0 !dbg !8 {
109entry:
110  %a = alloca i32, align 4
111  %force_alignment = alloca double, align 8
112  %0 = bitcast i32* %a to i8*, !dbg !22
113  call void @llvm.dbg.declare(metadata i32* %a, metadata !14, metadata !DIExpression()), !dbg !22
114  %csr1 = tail call i32 @getval() #4
115  %call = tail call i32 @getval() #4, !dbg !22
116  store i32 %call, i32* %a, align 4, !dbg !22, !tbaa !17
117  %1 = bitcast double* %force_alignment to i8*, !dbg !23
118  call void @llvm.lifetime.start.p0i8(i64 8, i8* nonnull %1) #4, !dbg !23
119  call void @llvm.dbg.declare(metadata double* %force_alignment, metadata !15, metadata !DIExpression()), !dbg !23
120  store double 4.200000e-01, double* %force_alignment, align 8, !dbg !23, !tbaa !24
121  call void @usevals(i32* nonnull %a, i32* nonnull %a, double* nonnull %force_alignment) #4, !dbg !26
122  call void @usecsrs(i32 %csr1, i32 %csr1)
123  ret i32 0
124}
125
126; Function Attrs: nounwind readnone speculatable
127declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
128
129; Function Attrs: argmemonly nounwind
130declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #2
131
132declare dso_local i32 @getval() local_unnamed_addr #3
133
134declare dso_local void @usevals(i32*, i32*, double*) local_unnamed_addr #3
135
136declare dso_local void @usecsrs(i32, i32) local_unnamed_addr #3
137
138; Function Attrs: argmemonly nounwind
139declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #2
140
141attributes #0 = { nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "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" }
142attributes #1 = { nounwind readnone speculatable }
143attributes #2 = { argmemonly nounwind }
144attributes #3 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "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" }
145attributes #4 = { nounwind }
146
147!llvm.dbg.cu = !{!0}
148!llvm.module.flags = !{!3, !4, !5, !6}
149!llvm.ident = !{!7}
150
151!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 8.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, nameTableKind: None)
152!1 = !DIFile(filename: "t.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild", checksumkind: CSK_MD5, checksum: "a646950309d5d01d8087fc10fea33941")
153!2 = !{}
154!3 = !{i32 1, !"NumRegisterParameters", i32 0}
155!4 = !{i32 2, !"CodeView", i32 1}
156!5 = !{i32 2, !"Debug Info Version", i32 3}
157!6 = !{i32 1, !"wchar_size", i32 2}
158!7 = !{!"clang version 8.0.0 "}
159!8 = distinct !DISubprogram(name: "realign_with_csrs", scope: !1, file: !1, line: 3, type: !9, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !12)
160!9 = !DISubroutineType(types: !10)
161!10 = !{!11, !11}
162!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
163!12 = !{!13, !14, !15}
164!13 = !DILocalVariable(name: "x", arg: 1, scope: !8, file: !1, line: 3, type: !11)
165!14 = !DILocalVariable(name: "a", scope: !8, file: !1, line: 4, type: !11)
166!15 = !DILocalVariable(name: "force_alignment", scope: !8, file: !1, line: 5, type: !16, align: 64)
167!16 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float)
168!17 = !{!18, !18, i64 0}
169!18 = !{!"int", !19, i64 0}
170!19 = !{!"omnipotent char", !20, i64 0}
171!20 = !{!"Simple C/C++ TBAA"}
172!21 = !DILocation(line: 3, scope: !8)
173!22 = !DILocation(line: 4, scope: !8)
174!23 = !DILocation(line: 5, scope: !8)
175!24 = !{!25, !25, i64 0}
176!25 = !{!"double", !19, i64 0}
177!26 = !DILocation(line: 6, scope: !8)
178!27 = !DILocation(line: 7, scope: !8)
179!28 = !DILocation(line: 8, scope: !8)
180