Home | History | Annotate | Download | only in X86
      1 ; RUN: opt < %s -basicaa -slp-vectorizer -S | FileCheck %s
      2 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
      3 target triple = "x86_64-apple-macosx10.9.0"
      4 
      5 @A = common global [2000 x double] zeroinitializer, align 16
      6 @B = common global [2000 x double] zeroinitializer, align 16
      7 @C = common global [2000 x float] zeroinitializer, align 16
      8 @D = common global [2000 x float] zeroinitializer, align 16
      9 
     10 ; Currently SCEV isn't smart enough to figure out that accesses
     11 ; A[3*i], A[3*i+1] and A[3*i+2] are consecutive, but in future
     12 ; that would hopefully be fixed. For now, check that this isn't
     13 ; vectorized.
     14 ; CHECK-LABEL: foo_3double
     15 ; CHECK-NOT: x double>
     16 ; Function Attrs: nounwind ssp uwtable
     17 define void @foo_3double(i32 %u) #0 {
     18 entry:
     19   %u.addr = alloca i32, align 4
     20   store i32 %u, i32* %u.addr, align 4
     21   %mul = mul nsw i32 %u, 3
     22   %idxprom = sext i32 %mul to i64
     23   %arrayidx = getelementptr inbounds [2000 x double]* @A, i32 0, i64 %idxprom
     24   %0 = load double* %arrayidx, align 8
     25   %arrayidx4 = getelementptr inbounds [2000 x double]* @B, i32 0, i64 %idxprom
     26   %1 = load double* %arrayidx4, align 8
     27   %add5 = fadd double %0, %1
     28   store double %add5, double* %arrayidx, align 8
     29   %add11 = add nsw i32 %mul, 1
     30   %idxprom12 = sext i32 %add11 to i64
     31   %arrayidx13 = getelementptr inbounds [2000 x double]* @A, i32 0, i64 %idxprom12
     32   %2 = load double* %arrayidx13, align 8
     33   %arrayidx17 = getelementptr inbounds [2000 x double]* @B, i32 0, i64 %idxprom12
     34   %3 = load double* %arrayidx17, align 8
     35   %add18 = fadd double %2, %3
     36   store double %add18, double* %arrayidx13, align 8
     37   %add24 = add nsw i32 %mul, 2
     38   %idxprom25 = sext i32 %add24 to i64
     39   %arrayidx26 = getelementptr inbounds [2000 x double]* @A, i32 0, i64 %idxprom25
     40   %4 = load double* %arrayidx26, align 8
     41   %arrayidx30 = getelementptr inbounds [2000 x double]* @B, i32 0, i64 %idxprom25
     42   %5 = load double* %arrayidx30, align 8
     43   %add31 = fadd double %4, %5
     44   store double %add31, double* %arrayidx26, align 8
     45   ret void
     46 }
     47 
     48 ; SCEV should be able to tell that accesses A[C1 + C2*i], A[C1 + C2*i], ...
     49 ; A[C1 + C2*i] are consecutive, if C2 is a power of 2, and C2 > C1 > 0.
     50 ; Thus, the following code should be vectorized.
     51 ; CHECK-LABEL: foo_2double
     52 ; CHECK: x double>
     53 ; Function Attrs: nounwind ssp uwtable
     54 define void @foo_2double(i32 %u) #0 {
     55 entry:
     56   %u.addr = alloca i32, align 4
     57   store i32 %u, i32* %u.addr, align 4
     58   %mul = mul nsw i32 %u, 2
     59   %idxprom = sext i32 %mul to i64
     60   %arrayidx = getelementptr inbounds [2000 x double]* @A, i32 0, i64 %idxprom
     61   %0 = load double* %arrayidx, align 8
     62   %arrayidx4 = getelementptr inbounds [2000 x double]* @B, i32 0, i64 %idxprom
     63   %1 = load double* %arrayidx4, align 8
     64   %add5 = fadd double %0, %1
     65   store double %add5, double* %arrayidx, align 8
     66   %add11 = add nsw i32 %mul, 1
     67   %idxprom12 = sext i32 %add11 to i64
     68   %arrayidx13 = getelementptr inbounds [2000 x double]* @A, i32 0, i64 %idxprom12
     69   %2 = load double* %arrayidx13, align 8
     70   %arrayidx17 = getelementptr inbounds [2000 x double]* @B, i32 0, i64 %idxprom12
     71   %3 = load double* %arrayidx17, align 8
     72   %add18 = fadd double %2, %3
     73   store double %add18, double* %arrayidx13, align 8
     74   ret void
     75 }
     76 
     77 ; Similar to the previous test, but with different datatype.
     78 ; CHECK-LABEL: foo_4float
     79 ; CHECK: x float>
     80 ; Function Attrs: nounwind ssp uwtable
     81 define void @foo_4float(i32 %u) #0 {
     82 entry:
     83   %u.addr = alloca i32, align 4
     84   store i32 %u, i32* %u.addr, align 4
     85   %mul = mul nsw i32 %u, 4
     86   %idxprom = sext i32 %mul to i64
     87   %arrayidx = getelementptr inbounds [2000 x float]* @C, i32 0, i64 %idxprom
     88   %0 = load float* %arrayidx, align 4
     89   %arrayidx4 = getelementptr inbounds [2000 x float]* @D, i32 0, i64 %idxprom
     90   %1 = load float* %arrayidx4, align 4
     91   %add5 = fadd float %0, %1
     92   store float %add5, float* %arrayidx, align 4
     93   %add11 = add nsw i32 %mul, 1
     94   %idxprom12 = sext i32 %add11 to i64
     95   %arrayidx13 = getelementptr inbounds [2000 x float]* @C, i32 0, i64 %idxprom12
     96   %2 = load float* %arrayidx13, align 4
     97   %arrayidx17 = getelementptr inbounds [2000 x float]* @D, i32 0, i64 %idxprom12
     98   %3 = load float* %arrayidx17, align 4
     99   %add18 = fadd float %2, %3
    100   store float %add18, float* %arrayidx13, align 4
    101   %add24 = add nsw i32 %mul, 2
    102   %idxprom25 = sext i32 %add24 to i64
    103   %arrayidx26 = getelementptr inbounds [2000 x float]* @C, i32 0, i64 %idxprom25
    104   %4 = load float* %arrayidx26, align 4
    105   %arrayidx30 = getelementptr inbounds [2000 x float]* @D, i32 0, i64 %idxprom25
    106   %5 = load float* %arrayidx30, align 4
    107   %add31 = fadd float %4, %5
    108   store float %add31, float* %arrayidx26, align 4
    109   %add37 = add nsw i32 %mul, 3
    110   %idxprom38 = sext i32 %add37 to i64
    111   %arrayidx39 = getelementptr inbounds [2000 x float]* @C, i32 0, i64 %idxprom38
    112   %6 = load float* %arrayidx39, align 4
    113   %arrayidx43 = getelementptr inbounds [2000 x float]* @D, i32 0, i64 %idxprom38
    114   %7 = load float* %arrayidx43, align 4
    115   %add44 = fadd float %6, %7
    116   store float %add44, float* %arrayidx39, align 4
    117   ret void
    118 }
    119 
    120 ; Similar to the previous tests, but now we are dealing with AddRec SCEV.
    121 ; CHECK-LABEL: foo_loop
    122 ; CHECK: x double>
    123 ; Function Attrs: nounwind ssp uwtable
    124 define i32 @foo_loop(double* %A, i32 %n) #0 {
    125 entry:
    126   %A.addr = alloca double*, align 8
    127   %n.addr = alloca i32, align 4
    128   %sum = alloca double, align 8
    129   %i = alloca i32, align 4
    130   store double* %A, double** %A.addr, align 8
    131   store i32 %n, i32* %n.addr, align 4
    132   store double 0.000000e+00, double* %sum, align 8
    133   store i32 0, i32* %i, align 4
    134   %cmp1 = icmp slt i32 0, %n
    135   br i1 %cmp1, label %for.body.lr.ph, label %for.end
    136 
    137 for.body.lr.ph:                                   ; preds = %entry
    138   br label %for.body
    139 
    140 for.body:                                         ; preds = %for.body.lr.ph, %for.body
    141   %0 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
    142   %1 = phi double [ 0.000000e+00, %for.body.lr.ph ], [ %add7, %for.body ]
    143   %mul = mul nsw i32 %0, 2
    144   %idxprom = sext i32 %mul to i64
    145   %arrayidx = getelementptr inbounds double* %A, i64 %idxprom
    146   %2 = load double* %arrayidx, align 8
    147   %mul1 = fmul double 7.000000e+00, %2
    148   %add = add nsw i32 %mul, 1
    149   %idxprom3 = sext i32 %add to i64
    150   %arrayidx4 = getelementptr inbounds double* %A, i64 %idxprom3
    151   %3 = load double* %arrayidx4, align 8
    152   %mul5 = fmul double 7.000000e+00, %3
    153   %add6 = fadd double %mul1, %mul5
    154   %add7 = fadd double %1, %add6
    155   store double %add7, double* %sum, align 8
    156   %inc = add nsw i32 %0, 1
    157   store i32 %inc, i32* %i, align 4
    158   %cmp = icmp slt i32 %inc, %n
    159   br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
    160 
    161 for.cond.for.end_crit_edge:                       ; preds = %for.body
    162   %split = phi double [ %add7, %for.body ]
    163   br label %for.end
    164 
    165 for.end:                                          ; preds = %for.cond.for.end_crit_edge, %entry
    166   %.lcssa = phi double [ %split, %for.cond.for.end_crit_edge ], [ 0.000000e+00, %entry ]
    167   %conv = fptosi double %.lcssa to i32
    168   ret i32 %conv
    169 }
    170 
    171 attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
    172 
    173 !llvm.ident = !{!0}
    174 
    175 !0 = metadata !{metadata !"clang version 3.5.0 "}
    176