xref: /llvm-project/llvm/test/Transforms/LoopVectorize/X86/vectorization-remarks-missed.ll (revision b0697dc1de1f6fbc0f3c192e5420203c8afe3f99)
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
4
5; C/C++ code for tests
6; void test(int *A, int Length) {
7; #pragma clang loop vectorize(enable) interleave(enable)
8;   for (int i = 0; i < Length; i++) {
9;     A[i] = i;
10;     if (A[i] > Length)
11;       break;
12;   }
13; }
14; File, line, and column should match those specified in the metadata
15; CHECK: remark: source.cpp:5:9: loop not vectorized: Cannot vectorize uncountable loop
16; CHECK: remark: source.cpp:5:9: loop not vectorized
17
18; void test_disabled(int *A, int Length) {
19; #pragma clang loop vectorize(disable) interleave(disable)
20;   for (int i = 0; i < Length; i++)
21;     A[i] = i;
22; }
23; CHECK: remark: source.cpp:12:8: loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized
24
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++)
28;     A[i] = A[B[i]];
29; }
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
33
34; int foo();
35; void test_multiple_failures(int *A) {
36;   int k = 0;
37; #pragma clang loop vectorize(enable) interleave(enable)
38;   for (int i = 0; i < 1000; i+=A[i]) {
39;     if (A[i])
40;       k = foo();
41;   }
42;   return k;
43; }
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
46
47; YAML:       --- !Analysis
48; YAML-NEXT: Pass:            loop-vectorize
49; YAML-NEXT: Name:            UnsupportedUncountableLoop
50; YAML-NEXT: DebugLoc:        { File: source.cpp, Line: 5, Column: 9 }
51; YAML-NEXT: Function:        _Z4testPii
52; YAML-NEXT: Args:
53; YAML-NEXT:   - String:          'loop not vectorized: '
54; YAML-NEXT:   - String:          Cannot vectorize uncountable loop
55; YAML-NEXT: ...
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
61; YAML-NEXT: Args:
62; YAML-NEXT:   - String:          loop not vectorized
63; YAML-NEXT: ...
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
69; YAML-NEXT: Args:
70; YAML-NEXT:   - String:          'loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized
71; YAML-NEXT: ...
72; YAML-NEXT: --- !Analysis
73; YAML-NEXT: Pass:            ''
74; YAML-NEXT: Name:            CantIdentifyArrayBounds
75; YAML-NEXT: DebugLoc:        { File: source.cpp, Line: 19, Column: 5 }
76; YAML-NEXT: Function:        _Z17test_array_boundsPiS_i
77; YAML-NEXT: Args:
78; YAML-NEXT:   - String:          'loop not vectorized: '
79; YAML-NEXT:   - String:          cannot identify array bounds
80; YAML-NEXT: ...
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
86; YAML-NEXT: Args:
87; YAML-NEXT:   - String:          loop not vectorized
88; YAML-NEXT:   - String:          ' (Force='
89; YAML-NEXT:   - Force:           'true'
90; YAML-NEXT:   - String:          ')'
91; YAML-NEXT: ...
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
97; YAML-NEXT: Args:
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'
99; YAML-NEXT: ...
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
105; YAML-NEXT: Args:
106; YAML-NEXT:   - String:          'loop not vectorized: '
107; YAML-NEXT:   - String:          Control flow cannot be substituted for a select
108; YAML-NEXT: ...
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
114; YAML-NEXT: Args:
115; YAML-NEXT:   - String:          'loop not vectorized: '
116; YAML-NEXT:   - String:          value that could not be identified as reduction is used outside the loop
117; YAML-NEXT: ...
118; YAML-NEXT: --- !Analysis
119; YAML-NEXT: Pass:            loop-vectorize
120; YAML-NEXT: Name:            UnsupportedUncountableLoop
121; YAML-NEXT: DebugLoc:        { File: source.cpp, Line: 27, Column: 3 }
122; YAML-NEXT: Function:        test_multiple_failures
123; YAML-NEXT: Args:
124; YAML-NEXT:   - String:          'loop not vectorized: '
125; YAML-NEXT:   - String:          Cannot vectorize uncountable loop
126; YAML-NEXT: ...
127; YAML:      --- !Missed
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
132; YAML-NEXT: Args:
133; YAML-NEXT:   - String:          loop not vectorized
134; YAML-NEXT: ...
135
136target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
137
138; Function Attrs: nounwind optsize ssp uwtable
139define void @_Z4testPii(ptr nocapture %A, i32 %Length) #0 !dbg !4 {
140entry:
141  %cmp10 = icmp sgt i32 %Length, 0, !dbg !12
142  br i1 %cmp10, label %for.body, label %for.end, !dbg !12, !llvm.loop !14
143
144for.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
156
157for.end:                                          ; preds = %for.body, %entry
158  ret void, !dbg !24
159}
160
161; CHECK: _Z4testPii
162; CHECK-NOT: x i32>
163; CHECK: ret
164
165; Function Attrs: nounwind optsize ssp uwtable
166define void @_Z13test_disabledPii(ptr nocapture %A, i32 %Length) #0 !dbg !7 {
167entry:
168  %cmp4 = icmp sgt i32 %Length, 0, !dbg !25
169  br i1 %cmp4, label %for.body, label %for.end, !dbg !25, !llvm.loop !27
170
171for.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
180
181for.end:                                          ; preds = %for.body, %entry
182  ret void, !dbg !31
183}
184
185; CHECK: _Z13test_disabledPii
186; CHECK-NOT: x i32>
187; CHECK: ret
188
189; Function Attrs: nounwind optsize ssp uwtable
190define void @_Z17test_array_boundsPiS_i(ptr nocapture %A, ptr nocapture readonly %B, i32 %Length) #0 !dbg !8 {
191entry:
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
194
195for.body.preheader:                               ; preds = %entry
196  br label %for.body, !dbg !32
197
198for.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
211
212for.end.loopexit:                                 ; preds = %for.body
213  br label %for.end
214
215for.end:                                          ; preds = %for.end.loopexit, %entry
216  ret void, !dbg !36
217}
218
219; CHECK: _Z17test_array_boundsPiS_i
220; CHECK-NOT: x i32>
221; CHECK: ret
222
223; Function Attrs: nounwind uwtable
224define i32 @test_multiple_failures(ptr nocapture readonly %A) #0 !dbg !46 {
225entry:
226  br label %for.body, !dbg !38
227
228for.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
235
236if.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
240
241for.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
247
248for.cond.cleanup:                                 ; preds = %for.inc
249  ret i32 %k.1, !dbg !39
250}
251
252declare i32 @foo(...)
253
254; CHECK: test_multiple_failure
255; CHECK-NOT: x i32>
256; CHECK: ret
257
258attributes #0 = { nounwind }
259
260!llvm.dbg.cu = !{!0}
261!llvm.module.flags = !{!9, !10}
262!llvm.ident = !{!11}
263
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: ".")
266!2 = !{}
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)
297!34 = !{!34, !15}
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)
310