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