1 ; RUN: opt < %s -passes=loop-vectorize,transform-warning -S -pass-remarks-missed='loop-vectorize' -pass-remarks-analysis='loop-vectorize' 2>&1 | FileCheck %s
2 ; RUN: opt < %s -passes=loop-vectorize,transform-warning -o /dev/null -pass-remarks-output=%t.yaml
3 ; RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s
6 ; void test(int *A, int Length) {
7 ; #pragma clang loop vectorize(enable) interleave(enable)
8 ; for (int i = 0; i < Length; i++) {
14 ; File, line, and column should match those specified in the metadata
15 ; CHECK: remark: source.cpp:5:9: loop not vectorized: Cannot vectorize early exit loop
16 ; CHECK: remark: source.cpp:5:9: loop not vectorized
18 ; void test_disabled(int *A, int Length) {
19 ; #pragma clang loop vectorize(disable) interleave(disable)
20 ; for (int i = 0; i < Length; i++)
23 ; CHECK: remark: source.cpp:12:8: loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized
25 ; void test_array_bounds(int *A, int *B, int Length) {
26 ; #pragma clang loop vectorize(enable)
27 ; for (int i = 0; i < Length; i++)
30 ; CHECK: remark: source.cpp:19:5: loop not vectorized: cannot identify array bounds
31 ; CHECK: remark: source.cpp:18:8: loop not vectorized (Force=true)
32 ; CHECK: warning: source.cpp:18:8: 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
35 ; void test_multiple_failures(int *A) {
37 ; #pragma clang loop vectorize(enable) interleave(enable)
38 ; for (int i = 0; i < 1000; i+=A[i]) {
44 ; CHECK: remark: source.cpp:29:7: loop not vectorized: control flow cannot be substituted for a select
45 ; CHECK: remark: source.cpp:27:3: loop not vectorized
48 ; YAML-NEXT: Pass: loop-vectorize
49 ; YAML-NEXT: Name: EarlyExitNotLatchPredecessor
50 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 }
51 ; YAML-NEXT: Function: _Z4testPii
53 ; YAML-NEXT: - String: 'loop not vectorized: '
54 ; YAML-NEXT: - String: Cannot vectorize early exit loop
56 ; YAML-NEXT: --- !Missed
57 ; YAML-NEXT: Pass: loop-vectorize
58 ; YAML-NEXT: Name: MissedDetails
59 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 }
60 ; YAML-NEXT: Function: _Z4testPii
62 ; YAML-NEXT: - String: loop not vectorized
64 ; YAML-NEXT: --- !Analysis
65 ; YAML-NEXT: Pass: loop-vectorize
66 ; YAML-NEXT: Name: AllDisabled
67 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 12, Column: 8 }
68 ; YAML-NEXT: Function: _Z13test_disabledPii
70 ; YAML-NEXT: - String: 'loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized
72 ; YAML-NEXT: --- !Analysis
74 ; YAML-NEXT: Name: CantIdentifyArrayBounds
75 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 }
76 ; YAML-NEXT: Function: _Z17test_array_boundsPiS_i
78 ; YAML-NEXT: - String: 'loop not vectorized: '
79 ; YAML-NEXT: - String: cannot identify array bounds
81 ; YAML-NEXT: --- !Missed
82 ; YAML-NEXT: Pass: loop-vectorize
83 ; YAML-NEXT: Name: MissedDetails
84 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 18, Column: 8 }
85 ; YAML-NEXT: Function: _Z17test_array_boundsPiS_i
87 ; YAML-NEXT: - String: loop not vectorized
88 ; YAML-NEXT: - String: ' (Force='
89 ; YAML-NEXT: - Force: 'true'
90 ; YAML-NEXT: - String: ')'
92 ; YAML-NEXT: --- !Failure
93 ; YAML-NEXT: Pass: transform-warning
94 ; YAML-NEXT: Name: FailedRequestedVectorization
95 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 18, Column: 8 }
96 ; YAML-NEXT: Function: _Z17test_array_boundsPiS_i
98 ; 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'
100 ; YAML-NEXT: --- !Analysis
101 ; YAML-NEXT: Pass: loop-vectorize
102 ; YAML-NEXT: Name: NoCFGForSelect
103 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 29, Column: 7 }
104 ; YAML-NEXT: Function: test_multiple_failures
106 ; YAML-NEXT: - String: 'loop not vectorized: '
107 ; YAML-NEXT: - String: control flow cannot be substituted for a select
109 ; YAML-NEXT: --- !Analysis
110 ; YAML-NEXT: Pass: loop-vectorize
111 ; YAML-NEXT: Name: NonReductionValueUsedOutsideLoop
112 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }
113 ; YAML-NEXT: Function: test_multiple_failures
115 ; YAML-NEXT: - String: 'loop not vectorized: '
116 ; YAML-NEXT: - String: value that could not be identified as reduction is used outside the loop
118 ; YAML-NEXT: --- !Analysis
119 ; YAML-NEXT: Pass: loop-vectorize
120 ; YAML-NEXT: Name: EarlyExitNotLatchPredecessor
121 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }
122 ; YAML-NEXT: Function: test_multiple_failures
124 ; YAML-NEXT: - String: 'loop not vectorized: '
125 ; YAML-NEXT: - String: Cannot vectorize early exit loop
128 ; YAML-NEXT: Pass: loop-vectorize
129 ; YAML-NEXT: Name: MissedDetails
130 ; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }
131 ; YAML-NEXT: Function: test_multiple_failures
133 ; YAML-NEXT: - String: loop not vectorized
136 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
138 ; Function Attrs: nounwind optsize ssp uwtable
139 define void @_Z4testPii(ptr nocapture %A, i32 %Length) #0 !dbg !4 {
141 %cmp10 = icmp sgt i32 %Length, 0, !dbg !12
142 br i1 %cmp10, label %for.body, label %for.end, !dbg !12, !llvm.loop !14
144 for.body: ; preds = %entry, %for.body
145 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
146 %arrayidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv, !dbg !16
147 %0 = trunc i64 %indvars.iv to i32, !dbg !16
148 %ld = load i32, ptr %arrayidx, align 4
149 store i32 %0, ptr %arrayidx, align 4, !dbg !16, !tbaa !18
150 %cmp3 = icmp sle i32 %ld, %Length, !dbg !22
151 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !12
152 %1 = trunc i64 %indvars.iv.next to i32
153 %cmp = icmp slt i32 %1, %Length, !dbg !12
154 %or.cond = and i1 %cmp3, %cmp, !dbg !22
155 br i1 %or.cond, label %for.body, label %for.end, !dbg !22
157 for.end: ; preds = %for.body, %entry
165 ; Function Attrs: nounwind optsize ssp uwtable
166 define void @_Z13test_disabledPii(ptr nocapture %A, i32 %Length) #0 !dbg !7 {
168 %cmp4 = icmp sgt i32 %Length, 0, !dbg !25
169 br i1 %cmp4, label %for.body, label %for.end, !dbg !25, !llvm.loop !27
171 for.body: ; preds = %entry, %for.body
172 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]
173 %arrayidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv, !dbg !30
174 %0 = trunc i64 %indvars.iv to i32, !dbg !30
175 store i32 %0, ptr %arrayidx, align 4, !dbg !30, !tbaa !18
176 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !25
177 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !25
178 %exitcond = icmp eq i32 %lftr.wideiv, %Length, !dbg !25
179 br i1 %exitcond, label %for.end, label %for.body, !dbg !25, !llvm.loop !27
181 for.end: ; preds = %for.body, %entry
185 ; CHECK: _Z13test_disabledPii
189 ; Function Attrs: nounwind optsize ssp uwtable
190 define void @_Z17test_array_boundsPiS_i(ptr nocapture %A, ptr nocapture readonly %B, i32 %Length) #0 !dbg !8 {
192 %cmp9 = icmp sgt i32 %Length, 0, !dbg !32
193 br i1 %cmp9, label %for.body.preheader, label %for.end, !dbg !32, !llvm.loop !34
195 for.body.preheader: ; preds = %entry
196 br label %for.body, !dbg !32
198 for.body: ; preds = %for.body.preheader, %for.body
199 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]
200 %arrayidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv, !dbg !35
201 %0 = load i32, ptr %arrayidx, align 4, !dbg !35, !tbaa !18
202 %idxprom1 = sext i32 %0 to i64, !dbg !35
203 %arrayidx2 = getelementptr inbounds i32, ptr %A, i64 %idxprom1, !dbg !35
204 %1 = load i32, ptr %arrayidx2, align 4, !dbg !35, !tbaa !18
205 %arrayidx4 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv, !dbg !35
206 store i32 %1, ptr %arrayidx4, align 4, !dbg !35, !tbaa !18
207 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !32
208 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !32
209 %exitcond = icmp eq i32 %lftr.wideiv, %Length, !dbg !32
210 br i1 %exitcond, label %for.end.loopexit, label %for.body, !dbg !32, !llvm.loop !34
212 for.end.loopexit: ; preds = %for.body
215 for.end: ; preds = %for.end.loopexit, %entry
219 ; CHECK: _Z17test_array_boundsPiS_i
223 ; Function Attrs: nounwind uwtable
224 define i32 @test_multiple_failures(ptr nocapture readonly %A) #0 !dbg !46 {
226 br label %for.body, !dbg !38
228 for.body: ; preds = %entry, %for.inc
229 %i.09 = phi i32 [ 0, %entry ], [ %add, %for.inc ]
230 %k.09 = phi i32 [ 0, %entry ], [ %k.1, %for.inc ]
231 %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.09, !dbg !40
232 %0 = load i32, ptr %arrayidx, align 4, !dbg !40
233 %tobool = icmp eq i32 %0, 0, !dbg !40
234 br i1 %tobool, label %for.inc, label %if.then, !dbg !40
236 if.then: ; preds = %for.body
237 %call = tail call i32 (...) @foo(), !dbg !41
238 %.pre = load i32, ptr %arrayidx, align 4
239 br label %for.inc, !dbg !42
241 for.inc: ; preds = %for.body, %if.then
242 %1 = phi i32 [ %.pre, %if.then ], [ 0, %for.body ], !dbg !43
243 %k.1 = phi i32 [ %call, %if.then ], [ %k.09, %for.body ]
244 %add = add nsw i32 %1, %i.09, !dbg !44
245 %cmp = icmp slt i32 %add, 1000, !dbg !45
246 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !38
248 for.cond.cleanup: ; preds = %for.inc
249 ret i32 %k.1, !dbg !39
252 declare i32 @foo(...)
254 ; CHECK: test_multiple_failure
258 attributes #0 = { nounwind }
261 !llvm.module.flags = !{!9, !10}
264 !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)
265 !1 = !DIFile(filename: "source.cpp", directory: ".")
267 !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)
268 !5 = !DIFile(filename: "source.cpp", directory: ".")
269 !6 = !DISubroutineType(types: !2)
270 !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)
271 !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)
272 !9 = !{i32 2, !"Dwarf Version", i32 2}
273 !10 = !{i32 2, !"Debug Info Version", i32 3}
274 !11 = !{!"clang version 3.5.0"}
275 !12 = !DILocation(line: 3, column: 8, scope: !13)
276 !13 = distinct !DILexicalBlock(line: 3, column: 3, file: !1, scope: !4)
277 !14 = !{!14, !15, !15}
278 !15 = !{!"llvm.loop.vectorize.enable", i1 true}
279 !16 = !DILocation(line: 4, column: 5, scope: !17)
280 !17 = distinct !DILexicalBlock(line: 3, column: 36, file: !1, scope: !13)
281 !18 = !{!19, !19, i64 0}
282 !19 = !{!"int", !20, i64 0}
283 !20 = !{!"omnipotent char", !21, i64 0}
284 !21 = !{!"Simple C/C++ TBAA"}
285 !22 = !DILocation(line: 5, column: 9, scope: !23)
286 !23 = distinct !DILexicalBlock(line: 5, column: 9, file: !1, scope: !17)
287 !24 = !DILocation(line: 8, column: 1, scope: !4)
288 !25 = !DILocation(line: 12, column: 8, scope: !26)
289 !26 = distinct !DILexicalBlock(line: 12, column: 3, file: !1, scope: !7)
290 !27 = !{!27, !28, !29}
291 !28 = !{!"llvm.loop.interleave.count", i32 1}
292 !29 = !{!"llvm.loop.vectorize.width", i32 1}
293 !30 = !DILocation(line: 13, column: 5, scope: !26)
294 !31 = !DILocation(line: 14, column: 1, scope: !7)
295 !32 = !DILocation(line: 18, column: 8, scope: !33)
296 !33 = distinct !DILexicalBlock(line: 18, column: 3, file: !1, scope: !8)
298 !35 = !DILocation(line: 19, column: 5, scope: !33)
299 !36 = !DILocation(line: 20, column: 1, scope: !8)
300 !37 = distinct !DILexicalBlock(line: 24, column: 3, file: !1, scope: !46)
301 !38 = !DILocation(line: 27, column: 3, scope: !37)
302 !39 = !DILocation(line: 31, column: 3, scope: !37)
303 !40 = !DILocation(line: 28, column: 9, scope: !37)
304 !41 = !DILocation(line: 29, column: 11, scope: !37)
305 !42 = !DILocation(line: 29, column: 7, scope: !37)
306 !43 = !DILocation(line: 27, column: 32, scope: !37)
307 !44 = !DILocation(line: 27, column: 30, scope: !37)
308 !45 = !DILocation(line: 27, column: 21, scope: !37)
309 !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)