[PATCH] D49168: [LV] Add a new reduction pattern match

Hideki Saito via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 24 18:12:52 PDT 2018


hsaito added a comment.

Takahiro,

I'm not familiar with the Recurrence Descriptor code, but I suppose the following is considered as RK_FloatAdd. If that's the case, we should be beefing up RK_FloatAdd rather than adding a new Kind. We can't keep adding new kind every time we encounter a different pattern of reduction sum/product. Downside is possibly exposing a downstream bug, but that should only help generalizing reduction handling code. From reduction analysis perspective, select (IF) and phi (IF-converted) should be the same thing. So, trying to handle this within FloatAdd/FloatMult should also help generalize recurrence analysis code. That's how I look at the issue. Hope this helps.

Thanks,

Hideki
------

float foo(float *a, int n){

  float sum=0;
  for (int i=0;i<n;i++){
    if (a[i]>1.0){
      sum+=a[i];
    }
    else if (a[i]<3.0){
      sum+=2*a[i];
    }
  }
  return sum;

}

for.body:                                         ; preds = %for.inc, %for.body.preheader

  %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.inc ]
  %sum.026 = phi float [ 0.000000e+00, %for.body.preheader ], [ %sum.1, %for.inc ]
  %arrayidx = getelementptr inbounds float, float* %a, i64 %indvars.iv
  %0 = load float, float* %arrayidx, align 4, !tbaa !2
  %cmp1 = fcmp ogt float %0, 1.000000e+00
  br i1 %cmp1, label %if.then, label %if.else
   

if.then:                                          ; preds = %for.body

  %add = fadd fast float %0, %sum.026
  br label %for.inc
   

if.else:                                          ; preds = %for.body

  %cmp8 = fcmp olt float %0, 3.000000e+00
  br i1 %cmp8, label %if.then10, label %for.inc
   

if.then10:                                        ; preds = %if.else

  %mul = fmul fast float %0, 2.000000e+00
  %add13 = fadd fast float %mul, %sum.026
  br label %for.inc
   

for.inc:                                          ; preds = %if.then, %if.then10, %if.else

  %sum.1 = phi float [ %add, %if.then ], [ %add13, %if.then10 ], [ %sum.026, %if.else ]
  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
  %exitcond = icmp eq i64 %indvars.iv.next, %wide.trip.count
  br i1 %exitcond, label %for.cond.cleanup.loopexit, label %for.body


Repository:
  rL LLVM

https://reviews.llvm.org/D49168





More information about the llvm-commits mailing list