Home | History | Annotate | Download | only in LoopVectorize
      1 ; RUN: opt < %s  -loop-vectorize -force-vector-unroll=1 -force-vector-width=4 -dce -instcombine -S -enable-if-conversion | FileCheck %s
      2 
      3 target 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"
      4 target triple = "x86_64-apple-macosx10.9.0"
      5 
      6 ; This is kernel11 from "LivermoreLoops". We can't vectorize it because we
      7 ; access both x[k] and x[k-1].
      8 ;
      9 ; void kernel11(double *x, double *y, int n) {
     10 ;   for ( int k=1 ; k<n ; k++ )
     11 ;     x[k] = x[k-1] + y[k];
     12 ; }
     13 
     14 ; CHECK-LABEL: @kernel11(
     15 ; CHECK-NOT: <4 x double>
     16 ; CHECK: ret
     17 define i32 @kernel11(double* %x, double* %y, i32 %n) nounwind uwtable ssp {
     18   %1 = alloca double*, align 8
     19   %2 = alloca double*, align 8
     20   %3 = alloca i32, align 4
     21   %k = alloca i32, align 4
     22   store double* %x, double** %1, align 8
     23   store double* %y, double** %2, align 8
     24   store i32 %n, i32* %3, align 4
     25   store i32 1, i32* %k, align 4
     26   br label %4
     27 
     28 ; <label>:4                                       ; preds = %25, %0
     29   %5 = load i32* %k, align 4
     30   %6 = load i32* %3, align 4
     31   %7 = icmp slt i32 %5, %6
     32   br i1 %7, label %8, label %28
     33 
     34 ; <label>:8                                       ; preds = %4
     35   %9 = load i32* %k, align 4
     36   %10 = sub nsw i32 %9, 1
     37   %11 = sext i32 %10 to i64
     38   %12 = load double** %1, align 8
     39   %13 = getelementptr inbounds double* %12, i64 %11
     40   %14 = load double* %13, align 8
     41   %15 = load i32* %k, align 4
     42   %16 = sext i32 %15 to i64
     43   %17 = load double** %2, align 8
     44   %18 = getelementptr inbounds double* %17, i64 %16
     45   %19 = load double* %18, align 8
     46   %20 = fadd double %14, %19
     47   %21 = load i32* %k, align 4
     48   %22 = sext i32 %21 to i64
     49   %23 = load double** %1, align 8
     50   %24 = getelementptr inbounds double* %23, i64 %22
     51   store double %20, double* %24, align 8
     52   br label %25
     53 
     54 ; <label>:25                                      ; preds = %8
     55   %26 = load i32* %k, align 4
     56   %27 = add nsw i32 %26, 1
     57   store i32 %27, i32* %k, align 4
     58   br label %4
     59 
     60 ; <label>:28                                      ; preds = %4
     61   ret i32 0
     62 }
     63 
     64 
     65 
     66 ; We don't vectorize this function because A[i*7] is scalarized, and the
     67 ; different scalars can in theory wrap around and overwrite other scalar
     68 ; elements. At the moment we only allow read/write access to arrays
     69 ; that are consecutive.
     70 ; 
     71 ; void foo(int *a) {
     72 ;   for (int i=0; i<256; ++i) {
     73 ;     int x = a[i*7];
     74 ;     if (x>3)
     75 ;       x = x*x+x*4;
     76 ;     a[i*7] = x+3;
     77 ;   }
     78 ; }
     79 
     80 ; CHECK-LABEL: @func2(
     81 ; CHECK-NOT: <4 x i32>
     82 ; CHECK: ret
     83 define i32 @func2(i32* nocapture %a) nounwind uwtable ssp {
     84   br label %1
     85 
     86 ; <label>:1                                       ; preds = %7, %0
     87   %indvars.iv = phi i64 [ 0, %0 ], [ %indvars.iv.next, %7 ]
     88   %2 = mul nsw i64 %indvars.iv, 7
     89   %3 = getelementptr inbounds i32* %a, i64 %2
     90   %4 = load i32* %3, align 4
     91   %5 = icmp sgt i32 %4, 3
     92   br i1 %5, label %6, label %7
     93 
     94 ; <label>:6                                       ; preds = %1
     95   %tmp = add i32 %4, 4
     96   %tmp1 = mul i32 %tmp, %4
     97   br label %7
     98 
     99 ; <label>:7                                       ; preds = %6, %1
    100   %x.0 = phi i32 [ %tmp1, %6 ], [ %4, %1 ]
    101   %8 = add nsw i32 %x.0, 3
    102   store i32 %8, i32* %3, align 4
    103   %indvars.iv.next = add i64 %indvars.iv, 1
    104   %lftr.wideiv = trunc i64 %indvars.iv.next to i32
    105   %exitcond = icmp eq i32 %lftr.wideiv, 256
    106   br i1 %exitcond, label %9, label %1
    107 
    108 ; <label>:9                                       ; preds = %7
    109   ret i32 0
    110 }
    111