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