1; RUN: opt -loop-simplify -loop-distribute -enable-loop-distribute -S < %s 2>&1 \
2; RUN:     | FileCheck %s --check-prefix=ALWAYS --check-prefix=NO_REMARKS
3; RUN: opt -loop-simplify -loop-distribute -enable-loop-distribute -S \
4; RUN:     -pass-remarks-missed=loop-distribute < %s 2>&1 \
5; RUN:     | FileCheck %s --check-prefix=ALWAYS --check-prefix=MISSED_REMARKS
6; RUN: opt -loop-simplify -loop-distribute -enable-loop-distribute -S \
7; RUN:     -pass-remarks-analysis=loop-distribute < %s 2>&1 \
8; RUN:     | FileCheck %s --check-prefix=ALWAYS --check-prefix=ANALYSIS_REMARKS
9; RUN: opt -loop-simplify -loop-distribute -enable-loop-distribute -S \
10; RUN:     -pass-remarks=loop-distribute < %s 2>&1 \
11; RUN:     | FileCheck %s --check-prefix=ALWAYS --check-prefix=REMARKS
12
13; This is the input program:
14;
15;     1	void forced (char *A, char *B, char *C, int N) {
16;     2	#pragma clang loop distribute(enable)
17;     3	  for(int i = 0; i < N; i++) {
18;     4	    A[i] = B[i] * C[i];
19;     5	  }
20;     6	}
21;     7
22;     8	void not_forced (char *A, char *B, char *C, int N) {
23;     9	  for(int i = 0; i < N; i++) {
24;    10	    A[i] = B[i] * C[i];
25;    11	  }
26;    12	}
27;    13
28;    14 void success (char *A, char *B, char *C, char *D, char *E, int N) {
29;    15   for(int i = 0; i < N; i++) {
30;    16     A[i + 1] = A[i] + B[i];
31;    17     C[i] = D[i] * E[i];
32;    18   }
33;    19 }
34
35target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
36target triple = "x86_64-apple-macosx10.11.0"
37
38; MISSED_REMARKS: remark:  /tmp/t.c:3:3: loop not distributed: use -Rpass-analysis=loop-distribute for more info
39; ALWAYS:         remark: /tmp/t.c:3:3: loop not distributed: memory operations are safe for vectorization
40; ALWAYS:         warning: /tmp/t.c:3:3: loop not distributed: failed explicitly specified loop distribution
41
42define void @forced(i8* %A, i8* %B, i8* %C, i32 %N) !dbg !7 {
43entry:
44  %cmp12 = icmp sgt i32 %N, 0, !dbg !9
45  br i1 %cmp12, label %ph, label %for.cond.cleanup, !dbg !10
46
47ph:
48  br label %for.body
49
50for.body:
51  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %ph ]
52  %arrayidx = getelementptr inbounds i8, i8* %B, i64 %indvars.iv, !dbg !12
53  %0 = load i8, i8* %arrayidx, align 1, !dbg !12, !tbaa !13
54  %arrayidx2 = getelementptr inbounds i8, i8* %C, i64 %indvars.iv, !dbg !16
55  %1 = load i8, i8* %arrayidx2, align 1, !dbg !16, !tbaa !13
56  %mul = mul i8 %1, %0, !dbg !17
57  %arrayidx6 = getelementptr inbounds i8, i8* %A, i64 %indvars.iv, !dbg !18
58  store i8 %mul, i8* %arrayidx6, align 1, !dbg !19, !tbaa !13
59  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !10
60  %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !10
61  %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !10
62  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !10, !llvm.loop !20
63
64for.cond.cleanup:
65  ret void, !dbg !11
66}
67
68; NO_REMARKS-NOT: remark: /tmp/t.c:9:3: loop not distributed: memory operations are safe for vectorization
69; MISSED_REMARKS: remark: /tmp/t.c:9:3: loop not distributed: use -Rpass-analysis=loop-distribute for more info
70; ANALYSIS_REMARKS: remark: /tmp/t.c:9:3: loop not distributed: memory operations are safe for vectorization
71; ALWAYS-NOT: warning: /tmp/t.c:9:3: loop not distributed: failed explicitly specified loop distribution
72
73define void @not_forced(i8* %A, i8* %B, i8* %C, i32 %N) !dbg !22 {
74entry:
75  %cmp12 = icmp sgt i32 %N, 0, !dbg !23
76  br i1 %cmp12, label %ph, label %for.cond.cleanup, !dbg !24
77
78ph:
79  br label %for.body
80
81for.body:
82  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %ph ]
83  %arrayidx = getelementptr inbounds i8, i8* %B, i64 %indvars.iv, !dbg !26
84  %0 = load i8, i8* %arrayidx, align 1, !dbg !26, !tbaa !13
85  %arrayidx2 = getelementptr inbounds i8, i8* %C, i64 %indvars.iv, !dbg !27
86  %1 = load i8, i8* %arrayidx2, align 1, !dbg !27, !tbaa !13
87  %mul = mul i8 %1, %0, !dbg !28
88  %arrayidx6 = getelementptr inbounds i8, i8* %A, i64 %indvars.iv, !dbg !29
89  store i8 %mul, i8* %arrayidx6, align 1, !dbg !30, !tbaa !13
90  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !24
91  %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !24
92  %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !24
93  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !24
94
95for.cond.cleanup:
96  ret void, !dbg !25
97}
98
99; REMARKS: remark: /tmp/t.c:15:3: distributed loop
100
101define void @success(i8* %A, i8* %B, i8* %C, i8* %D, i8* %E, i32 %N) !dbg !31 {
102entry:
103  %cmp28 = icmp sgt i32 %N, 0, !dbg !32
104  br i1 %cmp28, label %ph, label %for.cond.cleanup, !dbg !33
105
106ph:
107  br label %for.body
108
109for.body:
110  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %ph ]
111  %arrayidx = getelementptr inbounds i8, i8* %A, i64 %indvars.iv, !dbg !35
112  %0 = load i8, i8* %arrayidx, align 1, !dbg !35, !tbaa !13
113  %arrayidx2 = getelementptr inbounds i8, i8* %B, i64 %indvars.iv, !dbg !36
114  %1 = load i8, i8* %arrayidx2, align 1, !dbg !36, !tbaa !13
115  %add = add i8 %1, %0, !dbg !37
116  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !33
117  %arrayidx7 = getelementptr inbounds i8, i8* %A, i64 %indvars.iv.next, !dbg !38
118  store i8 %add, i8* %arrayidx7, align 1, !dbg !39, !tbaa !13
119  %arrayidx9 = getelementptr inbounds i8, i8* %D, i64 %indvars.iv, !dbg !40
120  %2 = load i8, i8* %arrayidx9, align 1, !dbg !40, !tbaa !13
121  %arrayidx12 = getelementptr inbounds i8, i8* %E, i64 %indvars.iv, !dbg !41
122  %3 = load i8, i8* %arrayidx12, align 1, !dbg !41, !tbaa !13
123  %mul = mul i8 %3, %2, !dbg !42
124  %arrayidx16 = getelementptr inbounds i8, i8* %C, i64 %indvars.iv, !dbg !43
125  store i8 %mul, i8* %arrayidx16, align 1, !dbg !44, !tbaa !13
126  %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !33
127  %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !33
128  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !dbg !33
129
130for.cond.cleanup:
131  ret void, !dbg !34
132}
133
134; MISSED_REMARKS: /tmp/t.c:27:5: loop not distributed: use -Rpass-analysis=loop-distribute for more info
135; ANALYSIS_REMARKS: /tmp/t.c:27:5: loop not distributed: may not insert runtime check with convergent operation
136; ALWAYS: warning: /tmp/t.c:27:5: loop not distributed: failed explicitly specified loop distribution
137define void @convergent(i8* %A, i8* %B, i8* %C, i8* %D, i8* %E, i32 %N) #1 !dbg !45 {
138entry:
139  %cmp28 = icmp sgt i32 %N, 0, !dbg !46
140  br i1 %cmp28, label %ph, label %for.cond.cleanup, !dbg !47
141
142ph:
143  br label %for.body
144
145for.body:
146  %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %ph ]
147  %arrayidx = getelementptr inbounds i8, i8* %A, i64 %indvars.iv, !dbg !49
148  %0 = load i8, i8* %arrayidx, align 1, !dbg !49, !tbaa !13
149  %arrayidx2 = getelementptr inbounds i8, i8* %B, i64 %indvars.iv, !dbg !50
150  %1 = load i8, i8* %arrayidx2, align 1, !dbg !50, !tbaa !13
151  %add = add i8 %1, %0, !dbg !51
152  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !57
153  %arrayidx7 = getelementptr inbounds i8, i8* %A, i64 %indvars.iv.next, !dbg !52
154  store i8 %add, i8* %arrayidx7, align 1, !dbg !53, !tbaa !13
155  %arrayidx9 = getelementptr inbounds i8, i8* %D, i64 %indvars.iv, !dbg !54
156  %2 = load i8, i8* %arrayidx9, align 1, !dbg !54, !tbaa !13
157  %arrayidx12 = getelementptr inbounds i8, i8* %E, i64 %indvars.iv, !dbg !55
158  %3 = load i8, i8* %arrayidx12, align 1, !dbg !55, !tbaa !13
159  %mul = mul i8 %3, %2, !dbg !56
160  %arrayidx16 = getelementptr inbounds i8, i8* %C, i64 %indvars.iv, !dbg !57
161  store i8 %mul, i8* %arrayidx16, align 1, !dbg !58, !tbaa !13
162  call void @llvm.convergent()
163  %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !57
164  %exitcond = icmp eq i32 %lftr.wideiv, %N, !dbg !57
165  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !llvm.loop !20, !dbg !57
166
167for.cond.cleanup:
168  ret void, !dbg !58
169}
170
171
172declare void @llvm.convergent() #0
173
174attributes #0 = { nounwind readnone convergent }
175attributes #1 = { nounwind convergent }
176
177
178!llvm.dbg.cu = !{!0}
179!llvm.module.flags = !{!3, !4}
180
181!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 (trunk 267633) (llvm/trunk 267675)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
182!1 = !DIFile(filename: "/tmp/t.c", directory: "/tmp")
183!2 = !{}
184!3 = !{i32 2, !"Dwarf Version", i32 2}
185!4 = !{i32 2, !"Debug Info Version", i32 3}
186!7 = distinct !DISubprogram(name: "forced", scope: !1, file: !1, line: 1, type: !8, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
187!8 = !DISubroutineType(types: !2)
188!9 = !DILocation(line: 3, column: 20, scope: !7)
189!10 = !DILocation(line: 3, column: 3, scope: !7)
190!11 = !DILocation(line: 6, column: 1, scope: !7)
191!12 = !DILocation(line: 4, column: 12, scope: !7)
192!13 = !{!14, !14, i64 0}
193!14 = !{!"omnipotent char", !15, i64 0}
194!15 = !{!"Simple C/C++ TBAA"}
195!16 = !DILocation(line: 4, column: 19, scope: !7)
196!17 = !DILocation(line: 4, column: 17, scope: !7)
197!18 = !DILocation(line: 4, column: 5, scope: !7)
198!19 = !DILocation(line: 4, column: 10, scope: !7)
199!20 = distinct !{!20, !21}
200!21 = !{!"llvm.loop.distribute.enable", i1 true}
201!22 = distinct !DISubprogram(name: "not_forced", scope: !1, file: !1, line: 8, type: !8, isLocal: false, isDefinition: true, scopeLine: 8, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
202!23 = !DILocation(line: 9, column: 20, scope: !22)
203!24 = !DILocation(line: 9, column: 3, scope: !22)
204!25 = !DILocation(line: 12, column: 1, scope: !22)
205!26 = !DILocation(line: 10, column: 12, scope: !22)
206!27 = !DILocation(line: 10, column: 19, scope: !22)
207!28 = !DILocation(line: 10, column: 17, scope: !22)
208!29 = !DILocation(line: 10, column: 5, scope: !22)
209!30 = !DILocation(line: 10, column: 10, scope: !22)
210!31 = distinct !DISubprogram(name: "success", scope: !1, file: !1, line: 14, type: !8, isLocal: false, isDefinition: true, scopeLine: 14, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
211!32 = !DILocation(line: 15, column: 20, scope: !31)
212!33 = !DILocation(line: 15, column: 3, scope: !31)
213!34 = !DILocation(line: 19, column: 1, scope: !31)
214!35 = !DILocation(line: 16, column: 16, scope: !31)
215!36 = !DILocation(line: 16, column: 23, scope: !31)
216!37 = !DILocation(line: 16, column: 21, scope: !31)
217!38 = !DILocation(line: 16, column: 5, scope: !31)
218!39 = !DILocation(line: 16, column: 14, scope: !31)
219!40 = !DILocation(line: 17, column: 12, scope: !31)
220!41 = !DILocation(line: 17, column: 19, scope: !31)
221!42 = !DILocation(line: 17, column: 17, scope: !31)
222!43 = !DILocation(line: 17, column: 5, scope: !31)
223!44 = !DILocation(line: 17, column: 10, scope: !31)
224!45 = distinct !DISubprogram(name: "convergent", scope: !1, file: !1, line: 24, type: !8, isLocal: false, isDefinition: true, scopeLine: 24, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
225!46 = !DILocation(line: 25, column: 20, scope: !45)
226!47 = !DILocation(line: 25, column: 3, scope: !45)
227!48 = !DILocation(line: 29, column: 1, scope: !45)
228!49 = !DILocation(line: 26, column: 16, scope: !45)
229!50 = !DILocation(line: 26, column: 23, scope: !45)
230!51 = !DILocation(line: 26, column: 21, scope: !45)
231!52 = !DILocation(line: 26, column: 5, scope: !45)
232!53 = !DILocation(line: 26, column: 14, scope: !45)
233!54 = !DILocation(line: 27, column: 12, scope: !45)
234!55 = !DILocation(line: 27, column: 19, scope: !45)
235!56 = !DILocation(line: 27, column: 17, scope: !45)
236!57 = !DILocation(line: 27, column: 5, scope: !45)
237!58 = !DILocation(line: 27, column: 10, scope: !45)
238