1; RUN: opt -S -loop-fusion -pass-remarks-analysis=loop-fusion -disable-output < %s 2>&1 | FileCheck %s
2; REQUIRES: asserts
3
4@B = common global [1024 x i32] zeroinitializer, align 16
5
6; CHECK: remark: diagnostics_analysis.c:6:3: [test]: Loop is not a candidate for fusion: Loop contains a volatile access
7; CHECK: remark: diagnostics_analysis.c:10:3: [test]: Loop is not a candidate for fusion: Loop has unknown trip count
8define void @test(i32* %A, i32 %n) !dbg !15 {
9entry:
10  %A.addr = alloca i32*, align 8
11  %n.addr = alloca i32, align 4
12  %i = alloca i32, align 4
13  %i1 = alloca i32, align 4
14  store i32* %A, i32** %A.addr, align 8
15  store i32 %n, i32* %n.addr, align 4
16  %0 = bitcast i32* %i to i8*
17  store i32 0, i32* %i, align 4
18  br label %for.cond
19
20for.cond:                                         ; preds = %for.inc, %entry
21  %1 = load i32, i32* %i, align 4
22  %2 = load i32, i32* %n.addr, align 4
23  %cmp = icmp slt i32 %1, %2
24  br i1 %cmp, label %for.body, label %for.cond.cleanup
25
26for.cond.cleanup:                                 ; preds = %for.cond
27  %3 = bitcast i32* %i to i8*, !dbg !42
28  br label %for.end
29
30for.body:                                         ; preds = %for.cond
31  %4 = load i32, i32* %i, align 4
32  %sub = sub nsw i32 %4, 3
33  %5 = load i32, i32* %i, align 4
34  %add = add nsw i32 %5, 3
35  %mul = mul nsw i32 %sub, %add
36  %6 = load i32, i32* %i, align 4
37  %rem = srem i32 %mul, %6
38  %7 = load i32*, i32** %A.addr, align 8
39  %8 = load i32, i32* %i, align 4
40  %idxprom = sext i32 %8 to i64
41  %arrayidx = getelementptr inbounds i32, i32* %7, i64 %idxprom
42  store volatile i32 %rem, i32* %arrayidx, align 4
43  br label %for.inc
44
45for.inc:                                          ; preds = %for.body
46  %9 = load i32, i32* %i, align 4, !dbg !49
47  %inc = add nsw i32 %9, 1, !dbg !49
48  store i32 %inc, i32* %i, align 4, !dbg !49
49  br label %for.cond, !dbg !42, !llvm.loop !50
50
51for.end:                                          ; preds = %for.cond.cleanup
52  %10 = bitcast i32* %i1 to i8*
53  store i32 0, i32* %i1, align 4
54  br label %for.cond2
55
56for.cond2:                                        ; preds = %for.inc12, %for.end
57  %11 = load i32, i32* %i1, align 4
58  %12 = load i32, i32* %n.addr, align 4
59  %cmp3 = icmp slt i32 %11, %12
60  br i1 %cmp3, label %for.body5, label %for.cond.cleanup4
61
62for.cond.cleanup4:                                ; preds = %for.cond2
63  %13 = bitcast i32* %i1 to i8*
64  br label %for.end14
65
66for.body5:                                        ; preds = %for.cond2
67  %14 = load i32, i32* %i1, align 4
68  %sub6 = sub nsw i32 %14, 3
69  %15 = load i32, i32* %i1, align 4
70  %add7 = add nsw i32 %15, 3
71  %mul8 = mul nsw i32 %sub6, %add7
72  %16 = load i32, i32* %i1, align 4
73  %rem9 = srem i32 %mul8, %16
74  %17 = load i32, i32* %i1, align 4
75  %idxprom10 = sext i32 %17 to i64
76  %arrayidx11 = getelementptr inbounds [1024 x i32], [1024 x i32]* @B, i64 0, i64 %idxprom10
77  store i32 %rem9, i32* %arrayidx11, align 4
78  br label %for.inc12
79
80for.inc12:                                        ; preds = %for.body5
81  %18 = load i32, i32* %i1, align 4
82  %inc13 = add nsw i32 %18, 1
83  store i32 %inc13, i32* %i1, align 4
84  br label %for.cond2, !dbg !59, !llvm.loop !67
85
86for.end14:                                        ; preds = %for.cond.cleanup4
87  ret void
88}
89
90!llvm.module.flags = !{!10, !11, !13}
91!llvm.ident = !{!14}
92
93!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
94!1 = distinct !DIGlobalVariable(name: "B", scope: !2, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true)
95!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 9.0.0 ([email protected]:compiler/llvm-project.git c019c32c5a2b0ed4487a738337d35fd3f630ac0a)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: GNU)
96!3 = !DIFile(filename: "diagnostics_analysis.c", directory: "/tmp")
97!4 = !{}
98!5 = !{!0}
99!6 = !DICompositeType(tag: DW_TAG_array_type, baseType: !7, size: 32768, elements: !8)
100!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
101!8 = !{!9}
102!9 = !DISubrange(count: 1024)
103!10 = !{i32 2, !"Dwarf Version", i32 4}
104!11 = !{i32 2, !"Debug Info Version", i32 3}
105!13 = !{i32 7, !"PIC Level", i32 2}
106!14 = !{!"clang version 9.0.0 ([email protected]:compiler/llvm-project.git c019c32c5a2b0ed4487a738337d35fd3f630ac0a)"}
107!15 = distinct !DISubprogram(name: "test", scope: !3, file: !3, line: 5, type: !16, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !20)
108!16 = !DISubroutineType(types: !17)
109!17 = !{null, !18, !7}
110!18 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !19, size: 64)
111!19 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7)
112!20 = !{!21, !22, !23, !25}
113!21 = !DILocalVariable(name: "A", arg: 1, scope: !15, file: !3, line: 5, type: !18)
114!22 = !DILocalVariable(name: "n", arg: 2, scope: !15, file: !3, line: 5, type: !7)
115!23 = !DILocalVariable(name: "i", scope: !24, file: !3, line: 6, type: !7)
116!24 = distinct !DILexicalBlock(scope: !15, file: !3, line: 6, column: 3)
117!25 = !DILocalVariable(name: "i", scope: !26, file: !3, line: 10, type: !7)
118!26 = distinct !DILexicalBlock(scope: !15, file: !3, line: 10, column: 3)
119!38 = distinct !DILexicalBlock(scope: !24, file: !3, line: 6, column: 3)
120!41 = !DILocation(line: 6, column: 3, scope: !24)
121!42 = !DILocation(line: 6, column: 3, scope: !38)
122!44 = distinct !DILexicalBlock(scope: !38, file: !3, line: 6, column: 31)
123!49 = !DILocation(line: 6, column: 27, scope: !38)
124!50 = distinct !{!50, !41, !51}
125!51 = !DILocation(line: 8, column: 3, scope: !24)
126!55 = distinct !DILexicalBlock(scope: !26, file: !3, line: 10, column: 3)
127!58 = !DILocation(line: 10, column: 3, scope: !26)
128!59 = !DILocation(line: 10, column: 3, scope: !55)
129!67 = distinct !{!67, !58, !68}
130!68 = !DILocation(line: 12, column: 3, scope: !26)
131!69 = !DILocation(line: 13, column: 1, scope: !15)
132