346 lines · plain
1; RUN: opt < %s -passes=loop-vectorize,transform-warning -S -pass-remarks-missed='loop-vectorize' -pass-remarks-analysis='loop-vectorize' 2>&1 | FileCheck %s2; RUN: opt < %s -passes=loop-vectorize,transform-warning -o /dev/null -pass-remarks-output=%t.yaml3; RUN: cat %t.yaml | FileCheck -check-prefix=YAML %s4 5; C/C++ code for tests6; 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 metadata15; CHECK: remark: source.cpp:5:9: loop not vectorized: Cannot vectorize uncountable loop16; CHECK: remark: source.cpp:5:9: loop not vectorized17 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 vectorized24 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 bounds31; 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 ordering33 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 select45; CHECK: remark: source.cpp:27:3: loop not vectorized46 47; YAML: --- !Analysis48; YAML-NEXT: Pass: loop-vectorize49; YAML-NEXT: Name: UnsupportedUncountableLoop50; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 }51; YAML-NEXT: Function: _Z4testPii52; YAML-NEXT: Args:53; YAML-NEXT: - String: 'loop not vectorized: '54; YAML-NEXT: - String: Cannot vectorize uncountable loop55; YAML-NEXT: ...56; YAML-NEXT: --- !Missed57; YAML-NEXT: Pass: loop-vectorize58; YAML-NEXT: Name: MissedDetails59; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 5, Column: 9 }60; YAML-NEXT: Function: _Z4testPii61; YAML-NEXT: Args:62; YAML-NEXT: - String: loop not vectorized63; YAML-NEXT: ...64; YAML-NEXT: --- !Analysis65; YAML-NEXT: Pass: loop-vectorize66; YAML-NEXT: Name: AllDisabled67; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 12, Column: 8 }68; YAML-NEXT: Function: _Z13test_disabledPii69; YAML-NEXT: Args:70; YAML-NEXT: - String: 'loop not vectorized: vectorization and interleaving are explicitly disabled, or the loop has already been vectorized71; YAML-NEXT: ...72; YAML-NEXT: --- !Analysis73; YAML-NEXT: Pass: ''74; YAML-NEXT: Name: CantIdentifyArrayBounds75; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 19, Column: 5 }76; YAML-NEXT: Function: _Z17test_array_boundsPiS_i77; YAML-NEXT: Args:78; YAML-NEXT: - String: 'loop not vectorized: '79; YAML-NEXT: - String: cannot identify array bounds80; YAML-NEXT: ...81; YAML-NEXT: --- !Missed82; YAML-NEXT: Pass: loop-vectorize83; YAML-NEXT: Name: MissedDetails84; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 18, Column: 8 }85; YAML-NEXT: Function: _Z17test_array_boundsPiS_i86; YAML-NEXT: Args:87; YAML-NEXT: - String: loop not vectorized88; YAML-NEXT: - String: ' (Force='89; YAML-NEXT: - Force: 'true'90; YAML-NEXT: - String: ')'91; YAML-NEXT: ...92; YAML-NEXT: --- !Failure93; YAML-NEXT: Pass: transform-warning94; YAML-NEXT: Name: FailedRequestedVectorization95; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 18, Column: 8 }96; YAML-NEXT: Function: _Z17test_array_boundsPiS_i97; 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: --- !Analysis101; YAML-NEXT: Pass: loop-vectorize102; YAML-NEXT: Name: NoCFGForSelect103; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 29, Column: 7 }104; YAML-NEXT: Function: test_multiple_failures105; YAML-NEXT: Args:106; YAML-NEXT: - String: 'loop not vectorized: '107; YAML-NEXT: - String: Control flow cannot be substituted for a select108; YAML-NEXT: ...109; YAML-NEXT: --- !Analysis110; YAML-NEXT: Pass: loop-vectorize111; YAML-NEXT: Name: NonReductionValueUsedOutsideLoop112; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }113; YAML-NEXT: Function: test_multiple_failures114; 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 loop117; YAML-NEXT: ...118; YAML-NEXT: --- !Analysis119; YAML-NEXT: Pass: loop-vectorize120; YAML-NEXT: Name: NonReductionValueUsedOutsideLoop121; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }122; YAML-NEXT: Function: test_multiple_failures123; YAML-NEXT: Args:124; YAML-NEXT: - String: 'loop not vectorized: '125; YAML-NEXT: - String: value that could not be identified as reduction is used outside the loop126; YAML-NEXT: ...127; YAML-NEXT: --- !Analysis128; YAML-NEXT: Pass: loop-vectorize129; YAML-NEXT: Name: CantVectorizeLibcall130; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 29, Column: 11 }131; YAML-NEXT: Function: test_multiple_failures132; YAML-NEXT: Args:133; YAML-NEXT: - String: 'loop not vectorized: '134; YAML-NEXT: - String: call instruction cannot be vectorized135; YAML-NEXT: ...136; YAML-NEXT: --- !Analysis137; YAML-NEXT: Pass: loop-vectorize138; YAML-NEXT: Name: NoInductionVariable139; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }140; YAML-NEXT: Function: test_multiple_failures141; YAML-NEXT: Args:142; YAML-NEXT: - String: 'loop not vectorized: '143; YAML-NEXT: - String: loop induction variable could not be identified144; YAML-NEXT: ...145; YAML-NEXT: --- !Analysis146; YAML-NEXT: Pass: loop-vectorize147; YAML-NEXT: Name: UnsupportedUncountableLoop148; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }149; YAML-NEXT: Function: test_multiple_failures150; YAML-NEXT: Args:151; YAML-NEXT: - String: 'loop not vectorized: '152; YAML-NEXT: - String: Cannot vectorize uncountable loop153; YAML-NEXT: ...154; YAML-NEXT: --- !Analysis155; YAML-NEXT: Pass: loop-vectorize156; YAML-NEXT: Name: CantComputeNumberOfIterations157; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }158; YAML-NEXT: Function: test_multiple_failures159; YAML-NEXT: Args:160; YAML-NEXT: - String: 'loop not vectorized: '161; YAML-NEXT: - String: could not determine number of loop iterations162; YAML-NEXT: ...163; YAML: --- !Missed164; YAML-NEXT: Pass: loop-vectorize165; YAML-NEXT: Name: MissedDetails166; YAML-NEXT: DebugLoc: { File: source.cpp, Line: 27, Column: 3 }167; YAML-NEXT: Function: test_multiple_failures168; YAML-NEXT: Args:169; YAML-NEXT: - String: loop not vectorized170; YAML-NEXT: ...171 172target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"173 174; Function Attrs: nounwind optsize ssp uwtable175define void @_Z4testPii(ptr nocapture %A, i32 %Length) #0 !dbg !4 {176entry:177 %cmp10 = icmp sgt i32 %Length, 0, !dbg !12178 br i1 %cmp10, label %for.body, label %for.end, !dbg !12, !llvm.loop !14179 180for.body: ; preds = %entry, %for.body181 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]182 %arrayidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv, !dbg !16183 %0 = trunc i64 %indvars.iv to i32, !dbg !16184 %ld = load i32, ptr %arrayidx, align 4185 store i32 %0, ptr %arrayidx, align 4, !dbg !16, !tbaa !18186 %cmp3 = icmp sle i32 %ld, %Length, !dbg !22187 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !12188 %1 = trunc i64 %indvars.iv.next to i32189 %cmp = icmp slt i32 %1, %Length, !dbg !12190 %or.cond = and i1 %cmp3, %cmp, !dbg !22191 br i1 %or.cond, label %for.body, label %for.end, !dbg !22192 193for.end: ; preds = %for.body, %entry194 ret void, !dbg !24195}196 197; CHECK: _Z4testPii198; CHECK-NOT: x i32>199; CHECK: ret200 201; Function Attrs: nounwind optsize ssp uwtable202define void @_Z13test_disabledPii(ptr nocapture %A, i32 %Length) #0 !dbg !7 {203entry:204 %cmp4 = icmp sgt i32 %Length, 0, !dbg !25205 br i1 %cmp4, label %for.body, label %for.end, !dbg !25, !llvm.loop !27206 207for.body: ; preds = %entry, %for.body208 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ]209 %arrayidx = getelementptr inbounds i32, ptr %A, i64 %indvars.iv, !dbg !30210 %0 = trunc i64 %indvars.iv to i32, !dbg !30211 store i32 %0, ptr %arrayidx, align 4, !dbg !30, !tbaa !18212 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !25213 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !25214 %exitcond = icmp eq i32 %lftr.wideiv, %Length, !dbg !25215 br i1 %exitcond, label %for.end, label %for.body, !dbg !25, !llvm.loop !27216 217for.end: ; preds = %for.body, %entry218 ret void, !dbg !31219}220 221; CHECK: _Z13test_disabledPii222; CHECK-NOT: x i32>223; CHECK: ret224 225; Function Attrs: nounwind optsize ssp uwtable226define void @_Z17test_array_boundsPiS_i(ptr nocapture %A, ptr nocapture readonly %B, i32 %Length) #0 !dbg !8 {227entry:228 %cmp9 = icmp sgt i32 %Length, 0, !dbg !32229 br i1 %cmp9, label %for.body.preheader, label %for.end, !dbg !32, !llvm.loop !34230 231for.body.preheader: ; preds = %entry232 br label %for.body, !dbg !32233 234for.body: ; preds = %for.body.preheader, %for.body235 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %for.body.preheader ]236 %arrayidx = getelementptr inbounds i32, ptr %B, i64 %indvars.iv, !dbg !35237 %0 = load i32, ptr %arrayidx, align 4, !dbg !35, !tbaa !18238 %idxprom1 = sext i32 %0 to i64, !dbg !35239 %arrayidx2 = getelementptr inbounds i32, ptr %A, i64 %idxprom1, !dbg !35240 %1 = load i32, ptr %arrayidx2, align 4, !dbg !35, !tbaa !18241 %arrayidx4 = getelementptr inbounds i32, ptr %A, i64 %indvars.iv, !dbg !35242 store i32 %1, ptr %arrayidx4, align 4, !dbg !35, !tbaa !18243 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1, !dbg !32244 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !32245 %exitcond = icmp eq i32 %lftr.wideiv, %Length, !dbg !32246 br i1 %exitcond, label %for.end.loopexit, label %for.body, !dbg !32, !llvm.loop !34247 248for.end.loopexit: ; preds = %for.body249 br label %for.end250 251for.end: ; preds = %for.end.loopexit, %entry252 ret void, !dbg !36253}254 255; CHECK: _Z17test_array_boundsPiS_i256; CHECK-NOT: x i32>257; CHECK: ret258 259; Function Attrs: nounwind uwtable260define i32 @test_multiple_failures(ptr nocapture readonly %A) #0 !dbg !46 {261entry:262 br label %for.body, !dbg !38263 264for.body: ; preds = %entry, %for.inc265 %i.09 = phi i32 [ 0, %entry ], [ %add, %for.inc ]266 %k.09 = phi i32 [ 0, %entry ], [ %k.1, %for.inc ]267 %arrayidx = getelementptr inbounds i32, ptr %A, i32 %i.09, !dbg !40268 %0 = load i32, ptr %arrayidx, align 4, !dbg !40269 %tobool = icmp eq i32 %0, 0, !dbg !40270 br i1 %tobool, label %for.inc, label %if.then, !dbg !40271 272if.then: ; preds = %for.body273 %call = tail call i32 (...) @foo(), !dbg !41274 %.pre = load i32, ptr %arrayidx, align 4275 br label %for.inc, !dbg !42276 277for.inc: ; preds = %for.body, %if.then278 %1 = phi i32 [ %.pre, %if.then ], [ 0, %for.body ], !dbg !43279 %k.1 = phi i32 [ %call, %if.then ], [ %k.09, %for.body ]280 %add = add nsw i32 %1, %i.09, !dbg !44281 %cmp = icmp slt i32 %add, 1000, !dbg !45282 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !38283 284for.cond.cleanup: ; preds = %for.inc285 ret i32 %k.1, !dbg !39286}287 288declare i32 @foo(...)289 290; CHECK: test_multiple_failure291; CHECK-NOT: x i32>292; CHECK: ret293 294attributes #0 = { nounwind }295 296!llvm.dbg.cu = !{!0}297!llvm.module.flags = !{!9, !10}298!llvm.ident = !{!11}299 300!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)301!1 = !DIFile(filename: "source.cpp", directory: ".")302!2 = !{}303!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)304!5 = !DIFile(filename: "source.cpp", directory: ".")305!6 = !DISubroutineType(types: !2)306!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)307!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)308!9 = !{i32 2, !"Dwarf Version", i32 2}309!10 = !{i32 2, !"Debug Info Version", i32 3}310!11 = !{!"clang version 3.5.0"}311!12 = !DILocation(line: 3, column: 8, scope: !13)312!13 = distinct !DILexicalBlock(line: 3, column: 3, file: !1, scope: !4)313!14 = !{!14, !15, !15}314!15 = !{!"llvm.loop.vectorize.enable", i1 true}315!16 = !DILocation(line: 4, column: 5, scope: !17)316!17 = distinct !DILexicalBlock(line: 3, column: 36, file: !1, scope: !13)317!18 = !{!19, !19, i64 0}318!19 = !{!"int", !20, i64 0}319!20 = !{!"omnipotent char", !21, i64 0}320!21 = !{!"Simple C/C++ TBAA"}321!22 = !DILocation(line: 5, column: 9, scope: !23)322!23 = distinct !DILexicalBlock(line: 5, column: 9, file: !1, scope: !17)323!24 = !DILocation(line: 8, column: 1, scope: !4)324!25 = !DILocation(line: 12, column: 8, scope: !26)325!26 = distinct !DILexicalBlock(line: 12, column: 3, file: !1, scope: !7)326!27 = !{!27, !28, !29}327!28 = !{!"llvm.loop.interleave.count", i32 1}328!29 = !{!"llvm.loop.vectorize.width", i32 1}329!30 = !DILocation(line: 13, column: 5, scope: !26)330!31 = !DILocation(line: 14, column: 1, scope: !7)331!32 = !DILocation(line: 18, column: 8, scope: !33)332!33 = distinct !DILexicalBlock(line: 18, column: 3, file: !1, scope: !8)333!34 = !{!34, !15}334!35 = !DILocation(line: 19, column: 5, scope: !33)335!36 = !DILocation(line: 20, column: 1, scope: !8)336!37 = distinct !DILexicalBlock(line: 24, column: 3, file: !1, scope: !46)337!38 = !DILocation(line: 27, column: 3, scope: !37)338!39 = !DILocation(line: 31, column: 3, scope: !37)339!40 = !DILocation(line: 28, column: 9, scope: !37)340!41 = !DILocation(line: 29, column: 11, scope: !37)341!42 = !DILocation(line: 29, column: 7, scope: !37)342!43 = !DILocation(line: 27, column: 32, scope: !37)343!44 = !DILocation(line: 27, column: 30, scope: !37)344!45 = !DILocation(line: 27, column: 21, scope: !37)345!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)346