xref: /aosp_15_r20/external/llvm/test/Transforms/Inline/alloca-dbgdeclare-merge.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; Test that alloca merging in the inliner places dbg.declare calls immediately
2*9880d681SAndroid Build Coastguard Worker; after the merged alloca. Not at the end of the entry BB, and definitely not
3*9880d681SAndroid Build Coastguard Worker; before the alloca.
4*9880d681SAndroid Build Coastguard Worker;
5*9880d681SAndroid Build Coastguard Worker; clang -g -S -emit-llvm -Xclang -disable-llvm-optzns
6*9880d681SAndroid Build Coastguard Worker;
7*9880d681SAndroid Build Coastguard Worker;__attribute__((always_inline)) void f() {
8*9880d681SAndroid Build Coastguard Worker;  char aaa[100];
9*9880d681SAndroid Build Coastguard Worker;  aaa[10] = 1;
10*9880d681SAndroid Build Coastguard Worker;}
11*9880d681SAndroid Build Coastguard Worker;
12*9880d681SAndroid Build Coastguard Worker;__attribute__((always_inline)) void g() {
13*9880d681SAndroid Build Coastguard Worker;  char bbb[100];
14*9880d681SAndroid Build Coastguard Worker;  bbb[20] = 1;
15*9880d681SAndroid Build Coastguard Worker;}
16*9880d681SAndroid Build Coastguard Worker;
17*9880d681SAndroid Build Coastguard Worker;void h() {
18*9880d681SAndroid Build Coastguard Worker;  f();
19*9880d681SAndroid Build Coastguard Worker;  g();
20*9880d681SAndroid Build Coastguard Worker;}
21*9880d681SAndroid Build Coastguard Worker;
22*9880d681SAndroid Build Coastguard Worker; RUN: opt -always-inline -S < %s | FileCheck %s
23*9880d681SAndroid Build Coastguard Worker;
24*9880d681SAndroid Build Coastguard Worker; CHECK:      define void @h()
25*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT: entry:
26*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   %[[AI:.*]] = alloca [100 x i8]
27*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   call void @llvm.dbg.declare(metadata [100 x i8]* %[[AI]],
28*9880d681SAndroid Build Coastguard Worker; CHECK-NEXT:   call void @llvm.dbg.declare(metadata [100 x i8]* %[[AI]],
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker
31*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
32*9880d681SAndroid Build Coastguard Workertarget triple = "x86_64-unknown-linux-gnu"
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Worker; Function Attrs: alwaysinline nounwind uwtable
35*9880d681SAndroid Build Coastguard Workerdefine void @f() #0 !dbg !4 {
36*9880d681SAndroid Build Coastguard Workerentry:
37*9880d681SAndroid Build Coastguard Worker  %aaa = alloca [100 x i8], align 16
38*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata [100 x i8]* %aaa, metadata !12, metadata !17), !dbg !18
39*9880d681SAndroid Build Coastguard Worker  %arrayidx = getelementptr inbounds [100 x i8], [100 x i8]* %aaa, i64 0, i64 10, !dbg !19
40*9880d681SAndroid Build Coastguard Worker  store i8 1, i8* %arrayidx, align 2, !dbg !20
41*9880d681SAndroid Build Coastguard Worker  ret void, !dbg !21
42*9880d681SAndroid Build Coastguard Worker}
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind readnone
45*9880d681SAndroid Build Coastguard Workerdeclare void @llvm.dbg.declare(metadata, metadata, metadata) #1
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker; Function Attrs: alwaysinline nounwind uwtable
48*9880d681SAndroid Build Coastguard Workerdefine void @g() #0 !dbg !7 {
49*9880d681SAndroid Build Coastguard Workerentry:
50*9880d681SAndroid Build Coastguard Worker  %bbb = alloca [100 x i8], align 16
51*9880d681SAndroid Build Coastguard Worker  call void @llvm.dbg.declare(metadata [100 x i8]* %bbb, metadata !22, metadata !17), !dbg !23
52*9880d681SAndroid Build Coastguard Worker  %arrayidx = getelementptr inbounds [100 x i8], [100 x i8]* %bbb, i64 0, i64 20, !dbg !24
53*9880d681SAndroid Build Coastguard Worker  store i8 1, i8* %arrayidx, align 4, !dbg !25
54*9880d681SAndroid Build Coastguard Worker  ret void, !dbg !26
55*9880d681SAndroid Build Coastguard Worker}
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Worker; Function Attrs: nounwind uwtable
58*9880d681SAndroid Build Coastguard Workerdefine void @h() #2 !dbg !8 {
59*9880d681SAndroid Build Coastguard Workerentry:
60*9880d681SAndroid Build Coastguard Worker  call void @f(), !dbg !27
61*9880d681SAndroid Build Coastguard Worker  call void @g(), !dbg !28
62*9880d681SAndroid Build Coastguard Worker  ret void, !dbg !29
63*9880d681SAndroid Build Coastguard Worker}
64*9880d681SAndroid Build Coastguard Worker
65*9880d681SAndroid Build Coastguard Workerattributes #0 = { alwaysinline nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
66*9880d681SAndroid Build Coastguard Workerattributes #1 = { nounwind readnone }
67*9880d681SAndroid Build Coastguard Workerattributes #2 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
68*9880d681SAndroid Build Coastguard Worker
69*9880d681SAndroid Build Coastguard Worker!llvm.dbg.cu = !{!0}
70*9880d681SAndroid Build Coastguard Worker!llvm.module.flags = !{!9, !10}
71*9880d681SAndroid Build Coastguard Worker!llvm.ident = !{!11}
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Worker!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 248518) (llvm/trunk 248512)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
74*9880d681SAndroid Build Coastguard Worker!1 = !DIFile(filename: "../1.c", directory: "/code/llvm-git/build")
75*9880d681SAndroid Build Coastguard Worker!2 = !{}
76*9880d681SAndroid Build Coastguard Worker!4 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 1, type: !5, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: false, unit: !0, variables: !2)
77*9880d681SAndroid Build Coastguard Worker!5 = !DISubroutineType(types: !6)
78*9880d681SAndroid Build Coastguard Worker!6 = !{null}
79*9880d681SAndroid Build Coastguard Worker!7 = distinct !DISubprogram(name: "g", scope: !1, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: false, unit: !0, variables: !2)
80*9880d681SAndroid Build Coastguard Worker!8 = distinct !DISubprogram(name: "h", scope: !1, file: !1, line: 11, type: !5, isLocal: false, isDefinition: true, scopeLine: 11, isOptimized: false, unit: !0, variables: !2)
81*9880d681SAndroid Build Coastguard Worker!9 = !{i32 2, !"Dwarf Version", i32 4}
82*9880d681SAndroid Build Coastguard Worker!10 = !{i32 2, !"Debug Info Version", i32 3}
83*9880d681SAndroid Build Coastguard Worker!11 = !{!"clang version 3.8.0 (trunk 248518) (llvm/trunk 248512)"}
84*9880d681SAndroid Build Coastguard Worker!12 = !DILocalVariable(name: "aaa", scope: !4, file: !1, line: 2, type: !13)
85*9880d681SAndroid Build Coastguard Worker!13 = !DICompositeType(tag: DW_TAG_array_type, baseType: !14, size: 800, align: 8, elements: !15)
86*9880d681SAndroid Build Coastguard Worker!14 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
87*9880d681SAndroid Build Coastguard Worker!15 = !{!16}
88*9880d681SAndroid Build Coastguard Worker!16 = !DISubrange(count: 100)
89*9880d681SAndroid Build Coastguard Worker!17 = !DIExpression()
90*9880d681SAndroid Build Coastguard Worker!18 = !DILocation(line: 2, column: 8, scope: !4)
91*9880d681SAndroid Build Coastguard Worker!19 = !DILocation(line: 3, column: 3, scope: !4)
92*9880d681SAndroid Build Coastguard Worker!20 = !DILocation(line: 3, column: 11, scope: !4)
93*9880d681SAndroid Build Coastguard Worker!21 = !DILocation(line: 4, column: 1, scope: !4)
94*9880d681SAndroid Build Coastguard Worker!22 = !DILocalVariable(name: "bbb", scope: !7, file: !1, line: 7, type: !13)
95*9880d681SAndroid Build Coastguard Worker!23 = !DILocation(line: 7, column: 8, scope: !7)
96*9880d681SAndroid Build Coastguard Worker!24 = !DILocation(line: 8, column: 3, scope: !7)
97*9880d681SAndroid Build Coastguard Worker!25 = !DILocation(line: 8, column: 11, scope: !7)
98*9880d681SAndroid Build Coastguard Worker!26 = !DILocation(line: 9, column: 1, scope: !7)
99*9880d681SAndroid Build Coastguard Worker!27 = !DILocation(line: 12, column: 3, scope: !8)
100*9880d681SAndroid Build Coastguard Worker!28 = !DILocation(line: 13, column: 3, scope: !8)
101*9880d681SAndroid Build Coastguard Worker!29 = !DILocation(line: 14, column: 1, scope: !8)
102