[llvm] r184684 - LoopVectorize: Add utility class for checking dependency among accesses

Arnold Schwaighofer aschwaighofer at apple.com
Thu Oct 31 08:38:59 PDT 2013


On Oct 31, 2013, at 9:40 AM, Hal Finkel <hfinkel at anl.gov> wrote:

> ----- Original Message -----
>> 
>> +  // Negative distances are not plausible dependencies.
>> +  const APInt &Val = C->getValue()->getValue();
>> +  if (Val.isNegative()) {
>> +    bool IsTrueDataDependence = (AIsWrite && !BIsWrite);
>> +    if (IsTrueDataDependence &&
>> +        (couldPreventStoreLoadForward(Val.abs().getZExtValue(),
>> TypeByteSize) ||
>> +         ATy != BTy))
> 
> I don't understand why we're checking for store-load forwarding in this case. If I understand correctly, this handles cases where we have things like:
>  for (int i = 0; i < n; ++i) {
>    a[i] = a[i+3] // + b[i];
>  }
> 

No. This check catches the case:


ASCEV:  a[i] = …
BSCEV:       = a[i-1]

AIsWrite
BIsRead

BSCEV-ASCEV = negative, so this is a “safe dependence in program order to vectorize”:

 Iteration 1:
  a[1] =
       = a[0]

 Iteration 2:
  a[2] =
       = a[1]

 Iteration 3:
  a[3] =
       = a[2]

 Vectorized:
  a[1:2:3] =
           = a[0:1:2]
  a[4:5:6] =
           = a[3:4:5]

But you miss out on store load forwarding ("a[1] =“ -> “ = a[1]”, etc) making this slower.

We can add a target hook if you have an architecture where store load forwarding still happens in such cases.

Best,
Arnold



More information about the llvm-commits mailing list