Home | History | Annotate | Download | only in AArch64
      1 ; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=1 -dce -instcombine -S | FileCheck %s
      2 ; RUN: opt < %s -loop-vectorize -force-vector-width=4 -force-vector-interleave=2 -dce -instcombine -S | FileCheck %s --check-prefix=UNROLL
      3 
      4 target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
      5 
      6 ; CHECK-LABEL: @recurrence_1
      7 ;
      8 ; void recurrence_1(int *a, int *b, int n) {
      9 ;   for(int i = 0; i < n; i++)
     10 ;     b[i] =  a[i] + a[i - 1]
     11 ; }
     12 ;
     13 ; CHECK:  vector.ph:
     14 ; CHECK:    %vector.recur.init = insertelement <4 x i32> undef, i32 %pre_load, i32 3
     15 ;
     16 ; CHECK:  vector.body:
     17 ; CHECK:    %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ [[L1:%[a-zA-Z0-9.]+]], %vector.body ]
     18 ; CHECK:    [[L1]] = load <4 x i32>
     19 ; CHECK:    {{.*}} = shufflevector <4 x i32> %vector.recur, <4 x i32> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
     20 ;
     21 ; CHECK:  middle.block:
     22 ; CHECK:    %vector.recur.extract = extractelement <4 x i32> [[L1]], i32 3
     23 ;
     24 ; CHECK:  scalar.ph:
     25 ; CHECK:    %scalar.recur.init = phi i32 [ %vector.recur.extract, %middle.block ], [ %pre_load, %vector.memcheck ], [ %pre_load, %min.iters.checked ], [ %pre_load, %for.preheader ]
     26 ;
     27 ; CHECK:  scalar.body:
     28 ; CHECK:    %scalar.recur = phi i32 [ %scalar.recur.init, %scalar.ph ], [ {{.*}}, %scalar.body ]
     29 ;
     30 ; UNROLL: vector.body:
     31 ; UNROLL:   %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ [[L2:%[a-zA-Z0-9.]+]], %vector.body ]
     32 ; UNROLL:   [[L1:%[a-zA-Z0-9.]+]] = load <4 x i32>
     33 ; UNROLL:   [[L2]] = load <4 x i32>
     34 ; UNROLL:   {{.*}} = shufflevector <4 x i32> %vector.recur, <4 x i32> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
     35 ; UNROLL:   {{.*}} = shufflevector <4 x i32> [[L1]], <4 x i32> [[L2]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
     36 ;
     37 ; UNROLL: middle.block:
     38 ; UNROLL:   %vector.recur.extract = extractelement <4 x i32> [[L2]], i32 3
     39 ;
     40 define void @recurrence_1(i32* nocapture readonly %a, i32* nocapture %b, i32 %n) {
     41 entry:
     42   br label %for.preheader
     43 
     44 for.preheader:
     45   %arrayidx.phi.trans.insert = getelementptr inbounds i32, i32* %a, i64 0
     46   %pre_load = load i32, i32* %arrayidx.phi.trans.insert
     47   br label %scalar.body
     48 
     49 scalar.body:
     50   %0 = phi i32 [ %pre_load, %for.preheader ], [ %1, %scalar.body ]
     51   %indvars.iv = phi i64 [ 0, %for.preheader ], [ %indvars.iv.next, %scalar.body ]
     52   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
     53   %arrayidx32 = getelementptr inbounds i32, i32* %a, i64 %indvars.iv.next
     54   %1 = load i32, i32* %arrayidx32
     55   %arrayidx34 = getelementptr inbounds i32, i32* %b, i64 %indvars.iv
     56   %add35 = add i32 %1, %0
     57   store i32 %add35, i32* %arrayidx34
     58   %lftr.wideiv = trunc i64 %indvars.iv.next to i32
     59   %exitcond = icmp eq i32 %lftr.wideiv, %n
     60   br i1 %exitcond, label %for.exit, label %scalar.body
     61 
     62 for.exit:
     63   ret void
     64 }
     65 
     66 ; CHECK-LABEL: @recurrence_2
     67 ;
     68 ; int recurrence_2(int *a, int n) {
     69 ;   int minmax;
     70 ;   for (int i = 0; i < n; ++i)
     71 ;     minmax = min(minmax, max(a[i] - a[i-1], 0));
     72 ;   return minmax;
     73 ; }
     74 ;
     75 ; CHECK:  vector.ph:
     76 ; CHECK:    %vector.recur.init = insertelement <4 x i32> undef, i32 %.pre, i32 3
     77 ;
     78 ; CHECK:  vector.body:
     79 ; CHECK:    %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ [[L1:%[a-zA-Z0-9.]+]], %vector.body ]
     80 ; CHECK:    [[L1]] = load <4 x i32>
     81 ; CHECK:    {{.*}} = shufflevector <4 x i32> %vector.recur, <4 x i32> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
     82 ;
     83 ; CHECK:  middle.block:
     84 ; CHECK:    %vector.recur.extract = extractelement <4 x i32> [[L1]], i32 3
     85 ;
     86 ; CHECK:  scalar.ph:
     87 ; CHECK:    %scalar.recur.init = phi i32 [ %vector.recur.extract, %middle.block ], [ %.pre, %min.iters.checked ], [ %.pre, %for.preheader ]
     88 ;
     89 ; CHECK:  scalar.body:
     90 ; CHECK:    %scalar.recur = phi i32 [ %scalar.recur.init, %scalar.ph ], [ {{.*}}, %scalar.body ]
     91 ;
     92 ; UNROLL: vector.body:
     93 ; UNROLL:   %vector.recur = phi <4 x i32> [ %vector.recur.init, %vector.ph ], [ [[L2:%[a-zA-Z0-9.]+]], %vector.body ]
     94 ; UNROLL:   [[L1:%[a-zA-Z0-9.]+]] = load <4 x i32>
     95 ; UNROLL:   [[L2]] = load <4 x i32>
     96 ; UNROLL:   {{.*}} = shufflevector <4 x i32> %vector.recur, <4 x i32> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
     97 ; UNROLL:   {{.*}} = shufflevector <4 x i32> [[L1]], <4 x i32> [[L2]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
     98 ;
     99 ; UNROLL: middle.block:
    100 ; UNROLL:   %vector.recur.extract = extractelement <4 x i32> [[L2]], i32 3
    101 ;
    102 define i32 @recurrence_2(i32* nocapture readonly %a, i32 %n) {
    103 entry:
    104   %cmp27 = icmp sgt i32 %n, 0
    105   br i1 %cmp27, label %for.preheader, label %for.cond.cleanup
    106 
    107 for.preheader:
    108   %arrayidx2.phi.trans.insert = getelementptr inbounds i32, i32* %a, i64 -1
    109   %.pre = load i32, i32* %arrayidx2.phi.trans.insert, align 4
    110   br label %scalar.body
    111 
    112 for.cond.cleanup.loopexit:
    113   %minmax.0.cond.lcssa = phi i32 [ %minmax.0.cond, %scalar.body ]
    114   br label %for.cond.cleanup
    115 
    116 for.cond.cleanup:
    117   %minmax.0.lcssa = phi i32 [ undef, %entry ], [ %minmax.0.cond.lcssa, %for.cond.cleanup.loopexit ]
    118   ret i32 %minmax.0.lcssa
    119 
    120 scalar.body:
    121   %0 = phi i32 [ %.pre, %for.preheader ], [ %1, %scalar.body ]
    122   %indvars.iv = phi i64 [ 0, %for.preheader ], [ %indvars.iv.next, %scalar.body ]
    123   %minmax.028 = phi i32 [ undef, %for.preheader ], [ %minmax.0.cond, %scalar.body ]
    124   %arrayidx = getelementptr inbounds i32, i32* %a, i64 %indvars.iv
    125   %1 = load i32, i32* %arrayidx, align 4
    126   %sub3 = sub nsw i32 %1, %0
    127   %cmp4 = icmp sgt i32 %sub3, 0
    128   %cond = select i1 %cmp4, i32 %sub3, i32 0
    129   %cmp5 = icmp slt i32 %minmax.028, %cond
    130   %minmax.0.cond = select i1 %cmp5, i32 %minmax.028, i32 %cond
    131   %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
    132   %lftr.wideiv = trunc i64 %indvars.iv.next to i32
    133   %exitcond = icmp eq i32 %lftr.wideiv, %n
    134   br i1 %exitcond, label %for.cond.cleanup.loopexit, label %scalar.body
    135 }
    136 
    137 ; CHECK-LABEL: @recurrence_3
    138 ;
    139 ; void recurrence_3(short *a, double *b, int n, float f, short p) {
    140 ;   b[0] = (double)a[0] - f * (double)p;
    141 ;   for (int i = 1; i < n; i++)
    142 ;     b[i] = (double)a[i] - f * (double)a[i - 1];
    143 ; }
    144 ;
    145 ;
    146 ; CHECK:  vector.ph:
    147 ; CHECK:    %vector.recur.init = insertelement <4 x i16> undef, i16 %0, i32 3
    148 ;
    149 ; CHECK:  vector.body:
    150 ; CHECK:    %vector.recur = phi <4 x i16> [ %vector.recur.init, %vector.ph ], [ [[L1:%[a-zA-Z0-9.]+]], %vector.body ]
    151 ; CHECK:    [[L1]] = load <4 x i16>
    152 ; CHECK:    {{.*}} = shufflevector <4 x i16> %vector.recur, <4 x i16> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
    153 ;
    154 ; CHECK:  middle.block:
    155 ; CHECK:    %vector.recur.extract = extractelement <4 x i16> [[L1]], i32 3
    156 ;
    157 ; CHECK:  scalar.ph:
    158 ; CHECK:    %scalar.recur.init = phi i16 [ %vector.recur.extract, %middle.block ], [ %0, %vector.memcheck ], [ %0, %min.iters.checked ], [ %0, %for.preheader ]
    159 ;
    160 ; CHECK:  scalar.body:
    161 ; CHECK:    %scalar.recur = phi i16 [ %scalar.recur.init, %scalar.ph ], [ {{.*}}, %scalar.body ]
    162 ;
    163 ; UNROLL: vector.body:
    164 ; UNROLL:   %vector.recur = phi <4 x i16> [ %vector.recur.init, %vector.ph ], [ [[L2:%[a-zA-Z0-9.]+]], %vector.body ]
    165 ; UNROLL:   [[L1:%[a-zA-Z0-9.]+]] = load <4 x i16>
    166 ; UNROLL:   [[L2]] = load <4 x i16>
    167 ; UNROLL:   {{.*}} = shufflevector <4 x i16> %vector.recur, <4 x i16> [[L1]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
    168 ; UNROLL:   {{.*}} = shufflevector <4 x i16> [[L1]], <4 x i16> [[L2]], <4 x i32> <i32 3, i32 4, i32 5, i32 6>
    169 ;
    170 ; UNROLL: middle.block:
    171 ; UNROLL:   %vector.recur.extract = extractelement <4 x i16> [[L2]], i32 3
    172 ;
    173 define void @recurrence_3(i16* nocapture readonly %a, double* nocapture %b, i32 %n, float %f, i16 %p) {
    174 entry:
    175   %0 = load i16, i16* %a, align 2
    176   %conv = sitofp i16 %0 to double
    177   %conv1 = fpext float %f to double
    178   %conv2 = sitofp i16 %p to double
    179   %mul = fmul fast double %conv2, %conv1
    180   %sub = fsub fast double %conv, %mul
    181   store double %sub, double* %b, align 8
    182   %cmp25 = icmp sgt i32 %n, 1
    183   br i1 %cmp25, label %for.preheader, label %for.end
    184 
    185 for.preheader:
    186   br label %scalar.body
    187 
    188 scalar.body:
    189   %1 = phi i16 [ %0, %for.preheader ], [ %2, %scalar.body ]
    190   %advars.iv = phi i64 [ %advars.iv.next, %scalar.body ], [ 1, %for.preheader ]
    191   %arrayidx5 = getelementptr inbounds i16, i16* %a, i64 %advars.iv
    192   %2 = load i16, i16* %arrayidx5, align 2
    193   %conv6 = sitofp i16 %2 to double
    194   %conv11 = sitofp i16 %1 to double
    195   %mul12 = fmul fast double %conv11, %conv1
    196   %sub13 = fsub fast double %conv6, %mul12
    197   %arrayidx15 = getelementptr inbounds double, double* %b, i64 %advars.iv
    198   store double %sub13, double* %arrayidx15, align 8
    199   %advars.iv.next = add nuw nsw i64 %advars.iv, 1
    200   %lftr.wideiv = trunc i64 %advars.iv.next to i32
    201   %exitcond = icmp eq i32 %lftr.wideiv, %n
    202   br i1 %exitcond, label %for.end.loopexit, label %scalar.body
    203 
    204 for.end.loopexit:
    205   br label %for.end
    206 
    207 for.end:
    208   ret void
    209 }
    210 
    211 ; CHECK-LABEL: @PR26734
    212 ;
    213 ; void PR26734(short *a, int *b, int *c, int d, short *e) {
    214 ;   for (; d != 21; d++) {
    215 ;     *b &= *c;
    216 ;     *e = *a - 6;
    217 ;     *c = *e;
    218 ;   }
    219 ; }
    220 ;
    221 ; CHECK-NOT: vector.ph:
    222 ;
    223 define void @PR26734(i16* %a, i32* %b, i32* %c, i32 %d, i16* %e) {
    224 entry:
    225   %cmp4 = icmp eq i32 %d, 21
    226   br i1 %cmp4, label %entry.for.end_crit_edge, label %for.body.lr.ph
    227 
    228 entry.for.end_crit_edge:
    229   %.pre = load i32, i32* %b, align 4
    230   br label %for.end
    231 
    232 for.body.lr.ph:
    233   %0 = load i16, i16* %a, align 2
    234   %sub = add i16 %0, -6
    235   %conv2 = sext i16 %sub to i32
    236   %c.promoted = load i32, i32* %c, align 4
    237   %b.promoted = load i32, i32* %b, align 4
    238   br label %for.body
    239 
    240 for.body:
    241   %inc7 = phi i32 [ %d, %for.body.lr.ph ], [ %inc, %for.body ]
    242   %and6 = phi i32 [ %b.promoted, %for.body.lr.ph ], [ %and, %for.body ]
    243   %conv25 = phi i32 [ %c.promoted, %for.body.lr.ph ], [ %conv2, %for.body ]
    244   %and = and i32 %and6, %conv25
    245   %inc = add nsw i32 %inc7, 1
    246   %cmp = icmp eq i32 %inc, 21
    247   br i1 %cmp, label %for.cond.for.end_crit_edge, label %for.body
    248 
    249 for.cond.for.end_crit_edge:
    250   %and.lcssa = phi i32 [ %and, %for.body ]
    251   store i32 %conv2, i32* %c, align 4
    252   store i32 %and.lcssa, i32* %b, align 4
    253   store i16 %sub, i16* %e, align 2
    254   br label %for.end
    255 
    256 for.end:
    257   ret void
    258 }
    259 
    260 ; CHECK-LABEL: @PR27246
    261 ;
    262 ; int PR27246() {
    263 ;   unsigned int e, n;
    264 ;   for (int i = 1; i < 49; ++i) {
    265 ;     for (int k = i; k > 1; --k)
    266 ;       e = k;
    267 ;     n = e;
    268 ;   }
    269 ;   return n;
    270 ; }
    271 ;
    272 ; CHECK-NOT: vector.ph:
    273 ;
    274 define i32 @PR27246() {
    275 entry:
    276   br label %for.cond1.preheader
    277 
    278 for.cond1.preheader:
    279   %i.016 = phi i32 [ 1, %entry ], [ %inc, %for.cond.cleanup3 ]
    280   %e.015 = phi i32 [ undef, %entry ], [ %e.1.lcssa, %for.cond.cleanup3 ]
    281   br label %for.cond1
    282 
    283 for.cond.cleanup:
    284   %e.1.lcssa.lcssa = phi i32 [ %e.1.lcssa, %for.cond.cleanup3 ]
    285   ret i32 %e.1.lcssa.lcssa
    286 
    287 for.cond1:
    288   %e.1 = phi i32 [ %k.0, %for.cond1 ], [ %e.015, %for.cond1.preheader ]
    289   %k.0 = phi i32 [ %dec, %for.cond1 ], [ %i.016, %for.cond1.preheader ]
    290   %cmp2 = icmp sgt i32 %k.0, 1
    291   %dec = add nsw i32 %k.0, -1
    292   br i1 %cmp2, label %for.cond1, label %for.cond.cleanup3
    293 
    294 for.cond.cleanup3:
    295   %e.1.lcssa = phi i32 [ %e.1, %for.cond1 ]
    296   %inc = add nuw nsw i32 %i.016, 1
    297   %exitcond = icmp eq i32 %inc, 49
    298   br i1 %exitcond, label %for.cond.cleanup, label %for.cond1.preheader
    299 }
    300