1; RUN: opt -codegenprepare -S %s -o - | FileCheck %s
2; typedef struct info {
3;   unsigned long long size;
4; } info_t;
5; extern unsigned p;
6; extern unsigned n;
7; void f() {
8;   unsigned int i;
9;   if (p) {
10;     info_t *info = (info_t *)p;
11;     for (i = 0; i < n; i++)
12;       use(info[i].size);
13;   }
14; }
15source_filename = "debug.i"
16target datalayout = "e-m:o-p:32:32-i64:64-a:0:32-n32-S128"
17target triple = "thumbv7k-apple-ios10.0.0"
18
19%struct.info = type { i64 }
20
21@p = external local_unnamed_addr global i32, align 4
22@n = external local_unnamed_addr global i32, align 4
23
24; Function Attrs: nounwind ssp uwtable
25define void @f() local_unnamed_addr #0 !dbg !16 {
26entry:
27  %0 = load i32, i32* @p, align 4, !dbg !25
28  %tobool = icmp eq i32 %0, 0, !dbg !25
29  br i1 %tobool, label %if.end, label %if.then, !dbg !26
30
31if.then:                                          ; preds = %entry
32  %1 = inttoptr i32 %0 to %struct.info*, !dbg !27
33  tail call void @llvm.dbg.value(metadata %struct.info* %1, metadata !22, metadata !DIExpression()), !dbg !28
34  ; CHECK: call void @llvm.dbg.value(metadata i32 %0, metadata !22, metadata !DIExpression())
35  tail call void @llvm.dbg.value(metadata i32 0, metadata !20, metadata !DIExpression()), !dbg !29
36  %2 = load i32, i32* @n, align 4, !dbg !30
37  %cmp5 = icmp eq i32 %2, 0, !dbg !33
38  br i1 %cmp5, label %if.end, label %for.body.preheader, !dbg !34
39
40for.body.preheader:                               ; preds = %if.then
41  ; CHECK: for.body.preheader:
42  ; CHECK:   %2 = inttoptr i32 %0 to %struct.info*
43  br label %for.body, !dbg !35
44
45for.body:                                         ; preds = %for.body.preheader, %for.body
46  %lsr.iv = phi %struct.info* [ %1, %for.body.preheader ], [ %scevgep, %for.body ]
47  %i.06 = phi i32 [ %inc, %for.body ], [ 0, %for.body.preheader ]
48  %lsr.iv7 = bitcast %struct.info* %lsr.iv to i64*
49  tail call void @llvm.dbg.value(metadata i32 %i.06, metadata !20, metadata !DIExpression()), !dbg !29
50  %3 = load i64, i64* %lsr.iv7, align 8, !dbg !35
51  %call = tail call i32 bitcast (i32 (...)* @use to i32 (i64)*)(i64 %3) #3, !dbg !36
52  %inc = add nuw i32 %i.06, 1, !dbg !37
53  tail call void @llvm.dbg.value(metadata i32 %inc, metadata !20, metadata !DIExpression()), !dbg !29
54  %4 = load i32, i32* @n, align 4, !dbg !30
55  %scevgep = getelementptr %struct.info, %struct.info* %lsr.iv, i32 1, !dbg !33
56  %cmp = icmp ult i32 %inc, %4, !dbg !33
57  br i1 %cmp, label %for.body, label %if.end.loopexit, !dbg !34, !llvm.loop !38
58
59if.end.loopexit:                                  ; preds = %for.body
60  br label %if.end, !dbg !40
61
62if.end:                                           ; preds = %if.end.loopexit, %if.then, %entry
63  ret void, !dbg !40
64}
65declare i32 @use(...) local_unnamed_addr #1
66
67; Function Attrs: nounwind readnone speculatable
68declare void @llvm.dbg.value(metadata, metadata, metadata) #2
69
70attributes #0 = { nounwind ssp uwtable }
71attributes #2 = { nounwind readnone speculatable }
72attributes #3 = { nobuiltin nounwind }
73
74!llvm.dbg.cu = !{!0}
75!llvm.module.flags = !{!10, !11, !12, !13, !14}
76!llvm.ident = !{!15}
77
78!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 (trunk 317231) (llvm/trunk 317262)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3)
79!1 = !DIFile(filename: "debug.i", directory: "/Data/radar/35321562")
80!2 = !{}
81!3 = !{!4}
82!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 32)
83!5 = !DIDerivedType(tag: DW_TAG_typedef, name: "info_t", file: !1, line: 3, baseType: !6)
84!6 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "info", file: !1, line: 1, size: 64, elements: !7)
85!7 = !{!8}
86!8 = !DIDerivedType(tag: DW_TAG_member, name: "size", scope: !6, file: !1, line: 2, baseType: !9, size: 64)
87!9 = !DIBasicType(name: "long long unsigned int", size: 64, encoding: DW_ATE_unsigned)
88!10 = !{i32 2, !"Dwarf Version", i32 4}
89!11 = !{i32 2, !"Debug Info Version", i32 3}
90!12 = !{i32 1, !"wchar_size", i32 4}
91!13 = !{i32 1, !"min_enum_size", i32 4}
92!14 = !{i32 7, !"PIC Level", i32 2}
93!15 = !{!"clang version 6.0.0 (trunk 317231) (llvm/trunk 317262)"}
94!16 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 6, type: !17, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: true, unit: !0, retainedNodes: !19)
95!17 = !DISubroutineType(types: !18)
96!18 = !{null}
97!19 = !{!20, !22}
98!20 = !DILocalVariable(name: "i", scope: !16, file: !1, line: 7, type: !21)
99!21 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
100!22 = !DILocalVariable(name: "info", scope: !23, file: !1, line: 9, type: !4)
101!23 = distinct !DILexicalBlock(scope: !24, file: !1, line: 8, column: 10)
102!24 = distinct !DILexicalBlock(scope: !16, file: !1, line: 8, column: 7)
103!25 = !DILocation(line: 8, column: 7, scope: !24)
104!26 = !DILocation(line: 8, column: 7, scope: !16)
105!27 = !DILocation(line: 9, column: 20, scope: !23)
106!28 = !DILocation(line: 9, column: 13, scope: !23)
107!29 = !DILocation(line: 7, column: 16, scope: !16)
108!30 = !DILocation(line: 10, column: 21, scope: !31)
109!31 = distinct !DILexicalBlock(scope: !32, file: !1, line: 10, column: 5)
110!32 = distinct !DILexicalBlock(scope: !23, file: !1, line: 10, column: 5)
111!33 = !DILocation(line: 10, column: 19, scope: !31)
112!34 = !DILocation(line: 10, column: 5, scope: !32)
113!35 = !DILocation(line: 11, column: 19, scope: !31)
114!36 = !DILocation(line: 11, column: 7, scope: !31)
115!37 = !DILocation(line: 10, column: 25, scope: !31)
116!38 = distinct !{!38, !34, !39}
117!39 = !DILocation(line: 11, column: 23, scope: !32)
118!40 = !DILocation(line: 13, column: 1, scope: !16)
119