1; RUN: opt -passes=licm %s -S | FileCheck %s
2
3; CHECK: %arrayidx4.promoted = load i32, i32* %arrayidx4, align 4, !tbaa !{{[0-9]+$}}
4
5target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
6
7@a = dso_local local_unnamed_addr global i16 0, align 2, !dbg !0
8@b = dso_local local_unnamed_addr global i16 0, align 2, !dbg !6
9
10; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
11declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
12
13declare i16 @e(i32)
14
15define i16 @g() !dbg !13 {
16entry:
17  %l_284 = alloca [2 x [3 x [6 x i32]]], align 16
18  %0 = bitcast [2 x [3 x [6 x i32]]]* %l_284 to i8*, !dbg !24
19  call void @llvm.lifetime.start.p0i8(i64 144, i8* nonnull %0), !dbg !24
20  call void @llvm.dbg.declare(metadata [2 x [3 x [6 x i32]]]* %l_284, metadata !17, metadata !DIExpression()), !dbg !25
21  %1 = load i16, i16* @a, align 2, !dbg !26, !tbaa !29
22  %cmp11 = icmp sgt i16 %1, -1, !dbg !33
23  br i1 %cmp11, label %for.body.lr.ph, label %cleanup, !dbg !34
24
25for.body.lr.ph:                                   ; preds = %entry
26  br label %for.body, !dbg !34
27
28for.body:                                         ; preds = %for.cond2, %for.body.lr.ph
29  %call = call signext i16 @e(i32 1), !dbg !35
30  %tobool = icmp eq i16 %call, 0, !dbg !35
31  br i1 %tobool, label %for.cond2, label %for.body.cleanup_crit_edge, !dbg !38
32
33for.cond2:                                        ; preds = %for.body
34  %arrayidx4 = getelementptr inbounds [2 x [3 x [6 x i32]]], [2 x [3 x [6 x i32]]]* %l_284, i64 0, i64 1, i64 2, i64 5, !dbg !39
35  %l = load i32, i32* %arrayidx4, !dbg !43, !tbaa !44
36  %add = add i32 %l, 1, !dbg !43
37  store i32 %add, i32* %arrayidx4, align 4, !dbg !43, !tbaa !44
38  %arrayidx8 = getelementptr inbounds [2 x [3 x [6 x i32]]], [2 x [3 x [6 x i32]]]* %l_284, i64 0, i64 1, i64 1, i64 4, !dbg !46
39  %2 = load i32, i32* %arrayidx8, align 8, !dbg !46, !tbaa !44
40  %conv9 = trunc i32 %2 to i16, !dbg !46
41  store i16 %conv9, i16* @b, align 2, !dbg !47, !tbaa !29
42  %3 = load i16, i16* @a, align 2, !dbg !26, !tbaa !29
43  %cmp = icmp sgt i16 %3, -1, !dbg !33
44  br i1 %cmp, label %for.body, label %for.cond.cleanup_crit_edge, !dbg !34, !llvm.loop !48
45
46for.cond.cleanup_crit_edge:                       ; preds = %for.cond2
47  br label %cleanup, !dbg !34
48
49for.body.cleanup_crit_edge:                       ; preds = %for.body
50  br label %cleanup, !dbg !38
51
52cleanup:                                          ; preds = %for.body.cleanup_crit_edge, %for.cond.cleanup_crit_edge, %entry
53  call void @llvm.lifetime.end.p0i8(i64 144, i8* nonnull %0), !dbg !51
54  ret i16 1, !dbg !51
55}
56
57; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
58declare void @llvm.lifetime.start.p0i8(i64 immarg, i8* nocapture) #1
59
60; Function Attrs: argmemonly nocallback nofree nosync nounwind willreturn
61declare void @llvm.lifetime.end.p0i8(i64 immarg, i8* nocapture) #1
62
63; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn
64declare void @llvm.dbg.value(metadata, metadata, metadata) #0
65
66attributes #0 = { nocallback nofree nosync nounwind readnone speculatable willreturn }
67attributes #1 = { argmemonly nocallback nofree nosync nounwind willreturn }
68
69!llvm.dbg.cu = !{!2}
70!llvm.module.flags = !{!9, !10, !11}
71!llvm.ident = !{!12}
72
73!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
74!1 = distinct !DIGlobalVariable(name: "a", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
75!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 11.0.0 (https://github.com/llvm/llvm-project.git 237d0e3c0416abf9919406bcc92874cfd15f5e0c)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
76!3 = !DIFile(filename: "a.c", directory: "/home/davide/lldb-build/bin")
77!4 = !{}
78!5 = !{!0, !6}
79!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
80!7 = distinct !DIGlobalVariable(name: "b", scope: !2, file: !3, line: 1, type: !8, isLocal: false, isDefinition: true)
81!8 = !DIBasicType(name: "short", size: 16, encoding: DW_ATE_signed)
82!9 = !{i32 7, !"Dwarf Version", i32 4}
83!10 = !{i32 2, !"Debug Info Version", i32 3}
84!11 = !{i32 1, !"wchar_size", i32 4}
85!12 = !{!"clang version 11.0.0 (https://github.com/llvm/llvm-project.git 237d0e3c0416abf9919406bcc92874cfd15f5e0c)"}
86!13 = distinct !DISubprogram(name: "g", scope: !3, file: !3, line: 5, type: !14, scopeLine: 5, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !16)
87!14 = !DISubroutineType(types: !15)
88!15 = !{!8}
89!16 = !{!17}
90!17 = !DILocalVariable(name: "l_284", scope: !13, file: !3, line: 6, type: !18)
91!18 = !DICompositeType(tag: DW_TAG_array_type, baseType: !19, size: 1152, elements: !20)
92!19 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
93!20 = !{!21, !22, !23}
94!21 = !DISubrange(count: 2)
95!22 = !DISubrange(count: 3)
96!23 = !DISubrange(count: 6)
97!24 = !DILocation(line: 6, column: 3, scope: !13)
98!25 = !DILocation(line: 6, column: 7, scope: !13)
99!26 = !DILocation(line: 7, column: 10, scope: !27)
100!27 = distinct !DILexicalBlock(scope: !28, file: !3, line: 7, column: 3)
101!28 = distinct !DILexicalBlock(scope: !13, file: !3, line: 7, column: 3)
102!29 = !{!30, !30, i64 0}
103!30 = !{!"short", !31, i64 0}
104!31 = !{!"omnipotent char", !32, i64 0}
105!32 = !{!"Simple C/C++ TBAA"}
106!33 = !DILocation(line: 7, column: 12, scope: !27)
107!34 = !DILocation(line: 7, column: 3, scope: !28)
108!35 = !DILocation(line: 8, column: 9, scope: !36)
109!36 = distinct !DILexicalBlock(scope: !37, file: !3, line: 8, column: 9)
110!37 = distinct !DILexicalBlock(scope: !27, file: !3, line: 7, column: 19)
111!38 = !DILocation(line: 8, column: 9, scope: !37)
112!39 = !DILocation(line: 11, column: 7, scope: !40)
113!40 = distinct !DILexicalBlock(scope: !41, file: !3, line: 10, column: 14)
114!41 = distinct !DILexicalBlock(scope: !42, file: !3, line: 10, column: 5)
115!42 = distinct !DILexicalBlock(scope: !37, file: !3, line: 10, column: 5)
116!43 = !DILocation(line: 11, column: 22, scope: !40)
117!44 = !{!45, !45, i64 0}
118!45 = !{!"int", !31, i64 0}
119!46 = !DILocation(line: 16, column: 9, scope: !37)
120!47 = !DILocation(line: 16, column: 7, scope: !37)
121!48 = distinct !{!48, !34, !49, !50}
122!49 = !DILocation(line: 17, column: 3, scope: !28)
123!50 = !{!"llvm.loop.unroll.disable"}
124!51 = !DILocation(line: 18, column: 1, scope: !13)
125