xref: /llvm-project/llvm/test/Transforms/Inline/inline-skip-use-empty-alloca.ll (revision c672ba7dde3a6ec2f6c89fcb207c9a6a8474cedc)
1; RUN: opt < %s -S -passes=inline | FileCheck %s
2; RUN: opt < %s -S -strip-debug -passes=inline | FileCheck %s
3;
4; RUN: opt < %s -S -passes=inline --try-experimental-debuginfo-iterators | FileCheck %s
5
6; https://bugs.llvm.org/show_bug.cgi?id=43291
7; The purpose of this test is to check if there is use_empty in the inner loop when scanning
8; blocks of allocas, if the alloca is use_empty, skip it when allocas inlining.
9
10declare void @use(ptr )
11
12define void @foo(i16 %k) !dbg !6 {
13  call void @llvm.dbg.value(metadata i16 %k, metadata !14, metadata !DIExpression()), !dbg !15
14  %alloca_a = alloca i32
15  call void @llvm.dbg.value(metadata i16 %k, metadata !14, metadata !DIExpression()), !dbg !15
16  %alloca_b = alloca [3 x i32]
17  call void @llvm.dbg.value(metadata i16 %k, metadata !14, metadata !DIExpression()), !dbg !15
18  %alloca_c = alloca i32
19  call void @llvm.dbg.value(metadata i16 %k, metadata !14, metadata !DIExpression()), !dbg !15
20  call void @use(ptr %alloca_a), !dbg !16
21  call void @use(ptr %alloca_c), !dbg !16
22  %_tmp23 = icmp ne i16 %k, 0
23  br i1 %_tmp23, label %bb1, label %bb2
24
25bb1:                                              ; preds = %0
26  store i32 0, ptr %alloca_b
27  br label %bb2
28
29bb2:                                              ; preds = %bb1, %0
30  ret void
31}
32
33define i16 @bar() !dbg !17 {
34  ; CHECK-LABEL: bar
35  ; CHECK: %alloca_a.i = alloca i32
36  ; CHECK-NOT: %alloca_b.i = alloca [3 x i32]
37  ; CHECK: %alloca_c.i = alloca i32
38  call void @foo(i16 0), !dbg !20
39  br label %bb1
40
41bb1:                                              ; preds = %0
42  ret i16 0
43}
44
45; Function Attrs: nounwind readnone speculatable willreturn
46declare void @llvm.dbg.value(metadata, metadata, metadata) #0
47
48attributes #0 = { nounwind readnone speculatable willreturn }
49
50!llvm.dbg.cu = !{!0}
51!llvm.module.flags = !{!3, !4}
52!llvm.ident = !{!5}
53
54!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "Foo", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !2, globals: !2)
55!1 = !DIFile(filename: "foo2.c", directory: "/tmp")
56!2 = !{}
57!3 = !{i32 2, !"Dwarf Version", i32 4}
58!4 = !{i32 2, !"Debug Info Version", i32 3}
59!5 = !{!"Foo"}
60!6 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 17, type: !7, scopeLine: 17, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
61!7 = !DISubroutineType(types: !8)
62!8 = !{!9, !13}
63!9 = !DIDerivedType(tag: DW_TAG_typedef, name: "int64_t", file: !10, line: 76, baseType: !11)
64!10 = !DIFile(filename: "stdint.h", directory: "/tmp")
65!11 = !DIDerivedType(tag: DW_TAG_typedef, name: "__i64_t", file: !1, baseType: !12)
66!12 = !DIBasicType(name: "signed long long", size: 64, encoding: DW_ATE_signed)
67!13 = !DIBasicType(name: "int", size: 16, encoding: DW_ATE_signed)
68!14 = !DILocalVariable(name: "k", arg: 1, scope: !6, file: !1, line: 17, type: !13)
69!15 = !DILocation(line: 0, scope: !6)
70!16 = !DILocation(line: 19, column: 3, scope: !6)
71!17 = distinct !DISubprogram(name: "g", scope: !1, file: !1, line: 8, type: !18, scopeLine: 8, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
72!18 = !DISubroutineType(types: !19)
73!19 = !{!13}
74!20 = !DILocation(line: 8, column: 7, scope: !17)
75