1 ; RUN: opt < %s -loop-vectorize -transform-warning -S -pass-remarks-missed='loop-vectorize' -pass-remarks-analysis='loop-vectorize' 2>&1 | FileCheck %s
2 ; RUN: opt < %s -loop-vectorize -transform-warning -o /dev/null -pass-remarks-output=%t.yaml
3 ; RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s
5 ; RUN: opt < %s -passes=loop-vectorize,transform-warning -S -pass-remarks-missed='loop-vectorize' -pass-remarks-analysis='loop-vectorize' 2>&1 | FileCheck %s
6 ; RUN: opt < %s -passes=loop-vectorize,transform-warning -o /dev/null -pass-remarks-output=%t.yaml
7 ; RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s
10 ; void test(int *A, int Length) {
11 ; #pragma clang loop vectorize(enable) interleave(enable)
12 ; for (int i = 0; i < Length; i++) {
18 ; File, line, and column should match those specified in the metadata
19 ; CHECK: remark: source.cpp:5:9: loop not vectorized: could not determine number of loop iterations
20 ; CHECK: remark: source.cpp:5:9: loop not vectorized
22 ; void test_disabled(int *A, int Length) {
23 ; #pragma clang loop vectorize(disable) interleave(disable)
24 ; for (int i = 0; i < Length; i++)
27 ; CHECK: remark: source.cpp:12:8: loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized
29 ; void test_array_bounds(int *A, int *B, int Length) {
30 ; #pragma clang loop vectorize(enable)
31 ; for (int i = 0; i < Length; i++)
34 ; CHECK: remark: source.cpp:19:5: loop not vectorized: cannot identify array bounds
35 ; CHECK: remark: source.cpp:19:5: loop not vectorized
36 ; CHECK: warning: source.cpp:19:5: loop not vectorized: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering
39 ; void test_multiple_failures(int *A) {
41 ; #pragma clang loop vectorize(enable) interleave(enable)
42 ; for (int i = 0; i < 1000; i+=A[i]) {
48 ; CHECK: remark: source.cpp:29:7: loop not vectorized: control flow cannot be substituted for a select
49 ; CHECK: remark: source.cpp:27:3: loop not vectorized
52 ; YAML-NEXT: Pass: loop-vectorize
53 ; YAML-NEXT: Name: CantComputeNumberOfIterations
54 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 }
55 ; YAML-NEXT: Function: _Z4testPii
57 ; YAML-NEXT: - String: 'loop not vectorized: '
58 ; YAML-NEXT: - String: could not determine number of loop iterations
60 ; YAML-NEXT: --- !Missed
61 ; YAML-NEXT: Pass: loop-vectorize
62 ; YAML-NEXT: Name: MissedDetails
63 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 }
64 ; YAML-NEXT: Function: _Z4testPii
66 ; YAML-NEXT: - String: loop not vectorized
68 ; YAML-NEXT: --- !Analysis
69 ; YAML-NEXT: Pass: loop-vectorize
70 ; YAML-NEXT: Name: AllDisabled
71 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 12, Column: 8 }
72 ; YAML-NEXT: Function: _Z13test_disabledPii
74 ; YAML-NEXT: - String: 'loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized
76 ; YAML-NEXT: --- !Analysis
78 ; YAML-NEXT: Name: CantIdentifyArrayBounds
79 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 }
80 ; YAML-NEXT: Function: _Z17test_array_boundsPiS_i
82 ; YAML-NEXT: - String: 'loop not vectorized: '
83 ; YAML-NEXT: - String: cannot identify array bounds
85 ; YAML-NEXT: --- !Missed
86 ; YAML-NEXT: Pass: loop-vectorize
87 ; YAML-NEXT: Name: MissedDetails
88 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 }
89 ; YAML-NEXT: Function: _Z17test_array_boundsPiS_i
91 ; YAML-NEXT: - String: loop not vectorized
92 ; YAML-NEXT: - String: ' (Force='
93 ; YAML-NEXT: - Force: 'true'
94 ; YAML-NEXT: - String: ')'
96 ; YAML-NEXT: --- !Failure
97 ; YAML-NEXT: Pass: transform-warning
98 ; YAML-NEXT: Name: FailedRequestedVectorization
99 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 }
100 ; YAML-NEXT: Function: _Z17test_array_boundsPiS_i
102 ; YAML-NEXT: - String: 'loop not vectorized: the optimizer was unable to perform the requested transformation; the transformation might be disabled or specified as part of an unsupported transformation ordering'
104 ; YAML-NEXT: --- !Analysis
105 ; YAML-NEXT: Pass: loop-vectorize
106 ; YAML-NEXT: Name: NoCFGForSelect
107 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 29, Column: 7 }
108 ; YAML-NEXT: Function: test_multiple_failures
110 ; YAML-NEXT: - String: 'loop not vectorized: '
111 ; YAML-NEXT: - String: control flow cannot be substituted for a select
113 ; YAML-NEXT: --- !Analysis
114 ; YAML-NEXT: Pass: loop-vectorize
115 ; YAML-NEXT: Name: NonReductionValueUsedOutsideLoop
116 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }
117 ; YAML-NEXT: Function: test_multiple_failures
119 ; YAML-NEXT: - String: 'loop not vectorized: '
120 ; YAML-NEXT: - String: value that could not be identified as reduction is used outside the loop
122 ; YAML-NEXT: --- !Analysis
123 ; YAML-NEXT: Pass: loop-vectorize
124 ; YAML-NEXT: Name: CantComputeNumberOfIterations
125 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }
126 ; YAML-NEXT: Function: test_multiple_failures
128 ; YAML-NEXT: - String: 'loop not vectorized: '
129 ; YAML-NEXT: - String: could not determine number of loop iterations
131 ; YAML-NEXT: --- !Missed
132 ; YAML-NEXT: Pass: loop-vectorize
133 ; YAML-NEXT: Name: MissedDetails
134 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }
135 ; YAML-NEXT: Function: test_multiple_failures
137 ; YAML-NEXT: - String: loop not vectorized
140 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
142 ; Function Attrs: nounwind optsize ssp uwtable
143 define void @_Z4testPii(i32* nocapture %A, i32 %Length) #0 !dbg !4 {
145 %cmp10 = icmp sgt i32 %Length, 0, !dbg !12
146 br i1 %cmp10, label %for.body, label %for.end, !dbg !12, !llvm.loop !14
148 for.body: ; preds = %entry, %for.body
149 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
150 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv, !dbg !16
151 %0 = trunc i64 %indvars.iv to i32, !dbg !16
152 %ld = load i32, i32* %arrayidx, align 4
153 store i32 %0, i32* %arrayidx, align 4, !dbg !16, !tbaa !18
154 %cmp3 = icmp sle i32 %ld, %Length, !dbg !22
155 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !12
156 %1 = trunc i64 %indvars.iv.next to i32
157 %cmp = icmp slt i32 %1, %Length, !dbg !12
158 %or.cond = and i1 %cmp3, %cmp, !dbg !22
159 br i1 %or.cond, label %for.body, label %for.end, !dbg !22
161 for.end: ; preds = %for.body, %entry
169 ; Function Attrs: nounwind optsize ssp uwtable
170 define void @_Z13test_disabledPii(i32* nocapture %A, i32 %Length) #0 !dbg !7 {
172 %cmp4 = icmp sgt i32 %Length, 0, !dbg !25
173 br i1 %cmp4, label %for.body, label %for.end, !dbg !25, !llvm.loop !27
175 for.body: ; preds = %entry, %for.body
176 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
177 %arrayidx = getelementptr inbounds i32, i32* %A, i64 %indvars.iv, !dbg !30
178 %0 = trunc i64 %indvars.iv to i32, !dbg !30
179 store i32 %0, i32* %arrayidx, align 4, !dbg !30, !tbaa !18
180 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !25
181 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !25
182 %exitcond = icmp eq i32 %lftr.wideiv, %Length, !dbg !25
183 br i1 %exitcond, label %for.end, label %for.body, !dbg !25, !llvm.loop !27
185 for.end: ; preds = %for.body, %entry
189 ; CHECK: _Z13test_disabledPii
193 ; Function Attrs: nounwind optsize ssp uwtable
194 define void @_Z17test_array_boundsPiS_i(i32* nocapture %A, i32* nocapture readonly %B, i32 %Length) #0 !dbg !8 {
196 %cmp9 = icmp sgt i32 %Length, 0, !dbg !32
197 br i1 %cmp9, label %for.body.preheader, label %for.end, !dbg !32, !llvm.loop !34
199 for.body.preheader: ; preds = %entry
200 br label %for.body, !dbg !35
202 for.body: ; preds = %for.body.preheader, %for.body
203 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
204 %arrayidx = getelementptr inbounds i32, i32* %B, i64 %indvars.iv, !dbg !35
205 %0 = load i32, i32* %arrayidx, align 4, !dbg !35, !tbaa !18
206 %idxprom1 = sext i32 %0 to i64, !dbg !35
207 %arrayidx2 = getelementptr inbounds i32, i32* %A, i64 %idxprom1, !dbg !35
208 %1 = load i32, i32* %arrayidx2, align 4, !dbg !35, !tbaa !18
209 %arrayidx4 = getelementptr inbounds i32, i32* %A, i64 %indvars.iv, !dbg !35
210 store i32 %1, i32* %arrayidx4, align 4, !dbg !35, !tbaa !18
211 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !32
212 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !32
213 %exitcond = icmp eq i32 %lftr.wideiv, %Length, !dbg !32
214 br i1 %exitcond, label %for.end.loopexit, label %for.body, !dbg !32, !llvm.loop !34
216 for.end.loopexit: ; preds = %for.body
219 for.end: ; preds = %for.end.loopexit, %entry
223 ; CHECK: _Z17test_array_boundsPiS_i
227 ; Function Attrs: nounwind uwtable
228 define i32 @test_multiple_failures(i32* nocapture readonly %A) #0 !dbg !46 {
230 br label %for.body, !dbg !38
232 for.body: ; preds = %entry, %for.inc
233 %i.09 = phi i32 [ 0, %entry ], [ %add, %for.inc ]
234 %k.09 = phi i32 [ 0, %entry ], [ %k.1, %for.inc ]
235 %arrayidx = getelementptr inbounds i32, i32* %A, i32 %i.09, !dbg !40
236 %0 = load i32, i32* %arrayidx, align 4, !dbg !40
237 %tobool = icmp eq i32 %0, 0, !dbg !40
238 br i1 %tobool, label %for.inc, label %if.then, !dbg !40
240 if.then: ; preds = %for.body
241 %call = tail call i32 (...) @foo(), !dbg !41
242 %.pre = load i32, i32* %arrayidx, align 4
243 br label %for.inc, !dbg !42
245 for.inc: ; preds = %for.body, %if.then
246 %1 = phi i32 [ %.pre, %if.then ], [ 0, %for.body ], !dbg !43
247 %k.1 = phi i32 [ %call, %if.then ], [ %k.09, %for.body ]
248 %add = add nsw i32 %1, %i.09, !dbg !44
249 %cmp = icmp slt i32 %add, 1000, !dbg !45
250 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !38
252 for.cond.cleanup: ; preds = %for.inc
253 ret i32 %k.1, !dbg !39
256 declare i32 @foo(...)
258 ; CHECK: test_multiple_failure
262 attributes #0 = { nounwind }
265 !llvm.module.flags = !{!9, !10}
268 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0", isOptimized: true, runtimeVersion: 6, emissionKind: LineTablesOnly, file: !1, enums: !2, retainedTypes: !2, globals: !2, imports: !2)
269 !1 = !DIFile(filename: "source.cpp", directory: ".")
271 !4 = distinct !DISubprogram(name: "test", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 1, file: !1, scope: !5, type: !6, retainedNodes: !2)
272 !5 = !DIFile(filename: "source.cpp", directory: ".")
273 !6 = !DISubroutineType(types: !2)
274 !7 = distinct !DISubprogram(name: "test_disabled", line: 10, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 10, file: !1, scope: !5, type: !6, retainedNodes: !2)
275 !8 = distinct !DISubprogram(name: "test_array_bounds", line: 16, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 16, file: !1, scope: !5, type: !6, retainedNodes: !2)
276 !9 = !{i32 2, !"Dwarf Version", i32 2}
277 !10 = !{i32 2, !"Debug Info Version", i32 3}
278 !11 = !{!"clang version 3.5.0"}
279 !12 = !DILocation(line: 3, column: 8, scope: !13)
280 !13 = distinct !DILexicalBlock(line: 3, column: 3, file: !1, scope: !4)
281 !14 = !{!14, !15, !15}
282 !15 = !{!"llvm.loop.vectorize.enable", i1 true}
283 !16 = !DILocation(line: 4, column: 5, scope: !17)
284 !17 = distinct !DILexicalBlock(line: 3, column: 36, file: !1, scope: !13)
285 !18 = !{!19, !19, i64 0}
286 !19 = !{!"int", !20, i64 0}
287 !20 = !{!"omnipotent char", !21, i64 0}
288 !21 = !{!"Simple C/C++ TBAA"}
289 !22 = !DILocation(line: 5, column: 9, scope: !23)
290 !23 = distinct !DILexicalBlock(line: 5, column: 9, file: !1, scope: !17)
291 !24 = !DILocation(line: 8, column: 1, scope: !4)
292 !25 = !DILocation(line: 12, column: 8, scope: !26)
293 !26 = distinct !DILexicalBlock(line: 12, column: 3, file: !1, scope: !7)
294 !27 = !{!27, !28, !29}
295 !28 = !{!"llvm.loop.interleave.count", i32 1}
296 !29 = !{!"llvm.loop.vectorize.width", i32 1}
297 !30 = !DILocation(line: 13, column: 5, scope: !26)
298 !31 = !DILocation(line: 14, column: 1, scope: !7)
299 !32 = !DILocation(line: 18, column: 8, scope: !33)
300 !33 = distinct !DILexicalBlock(line: 18, column: 3, file: !1, scope: !8)
302 !35 = !DILocation(line: 19, column: 5, scope: !33)
303 !36 = !DILocation(line: 20, column: 1, scope: !8)
304 !37 = distinct !DILexicalBlock(line: 24, column: 3, file: !1, scope: !46)
305 !38 = !DILocation(line: 27, column: 3, scope: !37)
306 !39 = !DILocation(line: 31, column: 3, scope: !37)
307 !40 = !DILocation(line: 28, column: 9, scope: !37)
308 !41 = !DILocation(line: 29, column: 11, scope: !37)
309 !42 = !DILocation(line: 29, column: 7, scope: !37)
310 !43 = !DILocation(line: 27, column: 32, scope: !37)
311 !44 = !DILocation(line: 27, column: 30, scope: !37)
312 !45 = !DILocation(line: 27, column: 21, scope: !37)
313 !46 = distinct !DISubprogram(name: "test_multiple_failures", line: 26, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, unit: !0, scopeLine: 26, file: !1, scope: !5, type: !6, retainedNodes: !2)