1*5cce4affSRoman Lebedev; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine -S -simplifycfg -simplifycfg-require-and-preserve-domtree=1 | FileCheck %s 2cee313d2SEric Christopher 3cee313d2SEric Christophertarget datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128" 4cee313d2SEric Christopher 5cee313d2SEric Christopher; 6cee313d2SEric Christopher; We want to make sure that we are vectorizeing the scalar loop only once 7cee313d2SEric Christopher; even if the pass manager runs the vectorizer multiple times due to inlining. 8cee313d2SEric Christopher 9cee313d2SEric Christopher 10cee313d2SEric Christopher; This test checks that we add metadata to vectorized loops 11cee313d2SEric Christopher; CHECK-LABEL: @_Z4foo1Pii( 12cee313d2SEric Christopher; CHECK: <4 x i32> 13cee313d2SEric Christopher; CHECK: llvm.loop 14cee313d2SEric Christopher; CHECK: ret 15cee313d2SEric Christopher 16cee313d2SEric Christopher; This test comes from the loop: 17cee313d2SEric Christopher; 18cee313d2SEric Christopher;int foo (int *A, int n) { 19cee313d2SEric Christopher; return std::accumulate(A, A + n, 0); 20cee313d2SEric Christopher;} 21cee313d2SEric Christopherdefine i32 @_Z4foo1Pii(i32* %A, i32 %n) #0 { 22cee313d2SEric Christopherentry: 23cee313d2SEric Christopher %idx.ext = sext i32 %n to i64 24cee313d2SEric Christopher %add.ptr = getelementptr inbounds i32, i32* %A, i64 %idx.ext 25cee313d2SEric Christopher %cmp3.i = icmp eq i32 %n, 0 26cee313d2SEric Christopher br i1 %cmp3.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i 27cee313d2SEric Christopher 28cee313d2SEric Christopherfor.body.i: ; preds = %entry, %for.body.i 29cee313d2SEric Christopher %__init.addr.05.i = phi i32 [ %add.i, %for.body.i ], [ 0, %entry ] 30cee313d2SEric Christopher %__first.addr.04.i = phi i32* [ %incdec.ptr.i, %for.body.i ], [ %A, %entry ] 31cee313d2SEric Christopher %0 = load i32, i32* %__first.addr.04.i, align 4 32cee313d2SEric Christopher %add.i = add nsw i32 %0, %__init.addr.05.i 33cee313d2SEric Christopher %incdec.ptr.i = getelementptr inbounds i32, i32* %__first.addr.04.i, i64 1 34cee313d2SEric Christopher %cmp.i = icmp eq i32* %incdec.ptr.i, %add.ptr 35cee313d2SEric Christopher br i1 %cmp.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i 36cee313d2SEric Christopher 37cee313d2SEric Christopher_ZSt10accumulateIPiiET0_T_S2_S1_.exit: ; preds = %for.body.i, %entry 38cee313d2SEric Christopher %__init.addr.0.lcssa.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ] 39cee313d2SEric Christopher ret i32 %__init.addr.0.lcssa.i 40cee313d2SEric Christopher} 41cee313d2SEric Christopher 42cee313d2SEric Christopher; This test checks that we don't vectorize loops that are marked with the "width" == 1 metadata. 43cee313d2SEric Christopher; CHECK-LABEL: @_Z4foo2Pii( 44cee313d2SEric Christopher; CHECK-NOT: <4 x i32> 45cee313d2SEric Christopher; CHECK: llvm.loop 46cee313d2SEric Christopher; CHECK: ret 47cee313d2SEric Christopherdefine i32 @_Z4foo2Pii(i32* %A, i32 %n) #0 { 48cee313d2SEric Christopherentry: 49cee313d2SEric Christopher %idx.ext = sext i32 %n to i64 50cee313d2SEric Christopher %add.ptr = getelementptr inbounds i32, i32* %A, i64 %idx.ext 51cee313d2SEric Christopher %cmp3.i = icmp eq i32 %n, 0 52cee313d2SEric Christopher br i1 %cmp3.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i 53cee313d2SEric Christopher 54cee313d2SEric Christopherfor.body.i: ; preds = %entry, %for.body.i 55cee313d2SEric Christopher %__init.addr.05.i = phi i32 [ %add.i, %for.body.i ], [ 0, %entry ] 56cee313d2SEric Christopher %__first.addr.04.i = phi i32* [ %incdec.ptr.i, %for.body.i ], [ %A, %entry ] 57cee313d2SEric Christopher %0 = load i32, i32* %__first.addr.04.i, align 4 58cee313d2SEric Christopher %add.i = add nsw i32 %0, %__init.addr.05.i 59cee313d2SEric Christopher %incdec.ptr.i = getelementptr inbounds i32, i32* %__first.addr.04.i, i64 1 60cee313d2SEric Christopher %cmp.i = icmp eq i32* %incdec.ptr.i, %add.ptr 61cee313d2SEric Christopher br i1 %cmp.i, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %for.body.i, !llvm.loop !0 62cee313d2SEric Christopher 63cee313d2SEric Christopher_ZSt10accumulateIPiiET0_T_S2_S1_.exit: ; preds = %for.body.i, %entry 64cee313d2SEric Christopher %__init.addr.0.lcssa.i = phi i32 [ 0, %entry ], [ %add.i, %for.body.i ] 65cee313d2SEric Christopher ret i32 %__init.addr.0.lcssa.i 66cee313d2SEric Christopher} 67cee313d2SEric Christopher 68a36ddf0aSFangrui Songattributes #0 = { nounwind readonly ssp uwtable "fp-contract-model"="standard" "frame-pointer"="non-leaf" "realign-stack" "relocation-model"="pic" "ssp-buffers-size"="8" } 69cee313d2SEric Christopher 70cee313d2SEric Christopher; CHECK: !0 = distinct !{!0, !1} 71cee313d2SEric Christopher; CHECK: !1 = !{!"llvm.loop.isvectorized", i32 1} 72cee313d2SEric Christopher; CHECK: !2 = distinct !{!2, !3, !1} 73cee313d2SEric Christopher; CHECK: !3 = !{!"llvm.loop.unroll.runtime.disable"} 74cee313d2SEric Christopher 75cee313d2SEric Christopher!0 = !{!0, !1} 76cee313d2SEric Christopher!1 = !{!"llvm.loop.vectorize.width", i32 1} 77