1 ; RUN: opt -S -passes=globalopt < %s | FileCheck %s
2 source_filename = "array.c"
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
6 %struct.mystruct = type { i32, i64 }
10 ; static long double array[2];
11 ; void __attribute__((nodebug)) foo(int in) { array[0] = in; }
12 ; void __attribute__((nodebug)) bar(int in) { array[1] = in; }
13 ; int main(int argc, char **argv)
17 ; return (array[0] + array[1]) > 0;
20 ; using clang -O0 -g2 -S -emit-llvm
22 @array = internal global [2 x x86_fp80] zeroinitializer, align 16, !dbg !0
24 ; CHECK: @array.0 = internal unnamed_addr global x86_fp80 0xK00000000000000000000, align 16, !dbg ![[EL0:.*]]
25 ; CHECK: @array.1 = internal unnamed_addr global x86_fp80 0xK00000000000000000000, align 16, !dbg ![[EL1:.*]]
27 ; CHECK: ![[EL0]] = !DIGlobalVariableExpression(var: ![[VAR:.*]], expr: !DIExpression(DW_OP_LLVM_fragment, 0, 128))
28 ; CHECK: ![[VAR]] = distinct !DIGlobalVariable(name: "array"
29 ; CHECK: ![[EL1]] = !DIGlobalVariableExpression(var: ![[VAR]], expr: !DIExpression(DW_OP_LLVM_fragment, 128, 128))
31 ; Function Attrs: noinline nounwind optnone uwtable
32 define void @foo(i32 %in) #0 {
34 %in.addr = alloca i32, align 4
35 store i32 %in, ptr %in.addr, align 4
36 %0 = load i32, ptr %in.addr, align 4
37 %conv = sitofp i32 %0 to x86_fp80
38 store x86_fp80 %conv, ptr @array, align 16
42 ; Function Attrs: noinline nounwind optnone uwtable
43 define void @bar(i32 %in) #0 {
45 %in.addr = alloca i32, align 4
46 store i32 %in, ptr %in.addr, align 4
47 %0 = load i32, ptr %in.addr, align 4
48 %conv = sitofp i32 %0 to x86_fp80
49 store x86_fp80 %conv, ptr getelementptr inbounds ([2 x x86_fp80], ptr @array, i64 0, i64 1), align 16
53 ; Function Attrs: noinline nounwind optnone uwtable
54 define i32 @main(i32 %argc, ptr %argv) #0 !dbg !14 {
56 %retval = alloca i32, align 4
57 %argc.addr = alloca i32, align 4
58 %argv.addr = alloca ptr, align 8
59 store i32 0, ptr %retval, align 4
60 store i32 %argc, ptr %argc.addr, align 4
61 call void @llvm.dbg.declare(metadata ptr %argc.addr, metadata !21, metadata !DIExpression()), !dbg !22
62 store ptr %argv, ptr %argv.addr, align 8
63 call void @llvm.dbg.declare(metadata ptr %argv.addr, metadata !23, metadata !DIExpression()), !dbg !24
64 %0 = load ptr, ptr %argv.addr, align 8, !dbg !25
65 %1 = load ptr, ptr %0, align 8, !dbg !25
66 %arrayidx1 = getelementptr inbounds i8, ptr %1, i64 1, !dbg !25
67 %2 = load i8, ptr %arrayidx1, align 1, !dbg !25
68 %conv = sext i8 %2 to i32, !dbg !25
69 call void @foo(i32 %conv), !dbg !26
70 %3 = load ptr, ptr %argv.addr, align 8, !dbg !27
71 %4 = load ptr, ptr %3, align 8, !dbg !27
72 %arrayidx3 = getelementptr inbounds i8, ptr %4, i64 1, !dbg !27
73 %5 = load i8, ptr %arrayidx3, align 1, !dbg !27
74 %conv4 = sext i8 %5 to i32, !dbg !27
75 call void @bar(i32 %conv4), !dbg !28
76 %6 = load x86_fp80, ptr @array, align 16, !dbg !29
77 %7 = load x86_fp80, ptr getelementptr inbounds ([2 x x86_fp80], ptr @array, i64 0, i64 1), align 16, !dbg !30
78 %add = fadd x86_fp80 %6, %7, !dbg !31
79 %cmp = fcmp ogt x86_fp80 %add, 0xK00000000000000000000, !dbg !32
80 %conv5 = zext i1 %cmp to i32, !dbg !32
81 ret i32 %conv5, !dbg !33
84 ; Function Attrs: nounwind readnone speculatable
85 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
87 attributes #0 = { noinline nounwind optnone uwtable }
88 attributes #1 = { nounwind readnone speculatable }
91 !llvm.module.flags = !{!10, !11, !12}
94 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
95 !1 = distinct !DIGlobalVariable(name: "array", scope: !2, file: !3, line: 1, type: !6, isLocal: true, isDefinition: true)
96 !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
97 !3 = !DIFile(filename: "array.c", directory: "/")
100 !6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 256, elements: !8)
101 !7 = !DIBasicType(name: "long double", size: 128, encoding: DW_ATE_float)
103 !9 = !DISubrange(count: 2)
104 !10 = !{i32 2, !"Dwarf Version", i32 4}
105 !11 = !{i32 2, !"Debug Info Version", i32 3}
106 !12 = !{i32 1, !"wchar_size", i32 4}
107 !13 = !{!"clang version 7.0.0"}
108 !14 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 4, type: !15, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4)
109 !15 = !DISubroutineType(types: !16)
110 !16 = !{!17, !17, !18}
111 !17 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
112 !18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
113 !19 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !20, size: 64)
114 !20 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
115 !21 = !DILocalVariable(name: "argc", arg: 1, scope: !14, file: !3, line: 4, type: !17)
116 !22 = !DILocation(line: 4, column: 14, scope: !14)
117 !23 = !DILocalVariable(name: "argv", arg: 2, scope: !14, file: !3, line: 4, type: !18)
118 !24 = !DILocation(line: 4, column: 27, scope: !14)
119 !25 = !DILocation(line: 6, column: 7, scope: !14)
120 !26 = !DILocation(line: 6, column: 3, scope: !14)
121 !27 = !DILocation(line: 7, column: 7, scope: !14)
122 !28 = !DILocation(line: 7, column: 3, scope: !14)
123 !29 = !DILocation(line: 8, column: 11, scope: !14)
124 !30 = !DILocation(line: 8, column: 22, scope: !14)
125 !31 = !DILocation(line: 8, column: 20, scope: !14)
126 !32 = !DILocation(line: 8, column: 32, scope: !14)
127 !33 = !DILocation(line: 8, column: 3, scope: !14)