1 ; RUN: opt < %s -loop-vectorize -force-vector-interleave=1 -force-vector-width=4 -dce -instcombine -S | FileCheck %s 2 3 ; int __attribute__((noinline)) sum_array(int *A, int n) { 4 ; return std::accumulate(A, A + n, 0); 5 ; } 6 7 target datalayout = "e-p:64:64:64-p1:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-n8:16:32:64-S128" 8 9 ;CHECK-LABEL: @sum_array( 10 ;CHECK: phi i64 11 ;CHECK: phi <4 x i32> 12 ;CHECK: load <4 x i32> 13 ;CHECK: add nsw <4 x i32> 14 ;CHECK: ret i32 15 define i32 @sum_array(i32* %A, i32 %n) nounwind uwtable readonly noinline ssp { 16 %1 = sext i32 %n to i64 17 %2 = getelementptr inbounds i32, i32* %A, i64 %1 18 %3 = icmp eq i32 %n, 0 19 br i1 %3, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %.lr.ph.i 20 21 .lr.ph.i: ; preds = %0, %.lr.ph.i 22 %.03.i = phi i32* [ %6, %.lr.ph.i ], [ %A, %0 ] 23 %.012.i = phi i32 [ %5, %.lr.ph.i ], [ 0, %0 ] 24 %4 = load i32, i32* %.03.i, align 4 25 %5 = add nsw i32 %4, %.012.i 26 %6 = getelementptr inbounds i32, i32* %.03.i, i64 1 27 %7 = icmp eq i32* %6, %2 28 br i1 %7, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %.lr.ph.i 29 30 _ZSt10accumulateIPiiET0_T_S2_S1_.exit: ; preds = %.lr.ph.i, %0 31 %.01.lcssa.i = phi i32 [ 0, %0 ], [ %5, %.lr.ph.i ] 32 ret i32 %.01.lcssa.i 33 } 34 35 ; Same, but use a pointer with a different size. 36 ;CHECK-LABEL: @sum_array_as1( 37 ;CHECK: phi i16 38 ;CHECK: phi <4 x i32> 39 ;CHECK: load <4 x i32> 40 ;CHECK: add nsw <4 x i32> 41 ;CHECK: ret i32 42 define i32 @sum_array_as1(i32 addrspace(1)* %A, i32 %n) nounwind uwtable readonly noinline ssp { 43 %1 = sext i32 %n to i64 44 %2 = getelementptr inbounds i32, i32 addrspace(1)* %A, i64 %1 45 %3 = icmp eq i32 %n, 0 46 br i1 %3, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %.lr.ph.i 47 48 .lr.ph.i: ; preds = %0, %.lr.ph.i 49 %.03.i = phi i32 addrspace(1)* [ %6, %.lr.ph.i ], [ %A, %0 ] 50 %.012.i = phi i32 [ %5, %.lr.ph.i ], [ 0, %0 ] 51 %4 = load i32, i32 addrspace(1)* %.03.i, align 4 52 %5 = add nsw i32 %4, %.012.i 53 %6 = getelementptr inbounds i32, i32 addrspace(1)* %.03.i, i64 1 54 %7 = icmp eq i32 addrspace(1)* %6, %2 55 br i1 %7, label %_ZSt10accumulateIPiiET0_T_S2_S1_.exit, label %.lr.ph.i 56 57 _ZSt10accumulateIPiiET0_T_S2_S1_.exit: ; preds = %.lr.ph.i, %0 58 %.01.lcssa.i = phi i32 [ 0, %0 ], [ %5, %.lr.ph.i ] 59 ret i32 %.01.lcssa.i 60 } 61