Issue 238823
Summary [LV][AArch64] Trip-count-4 loop vectorized after #197391, ~1.7x slower
Labels new issue
Assignees
Reporter eastig
    After #197391 ([LV] Allow runtime checks for low trip count loops without scalar epilogues), the loop vectorizer vectorizes the `qy` loop in the reproducer below with VF=2. Before #197391 it was not vectorized. The vectorized loop is ~1.7x slower than the scalar loop on Neoverse V2.

The reproducer is reduced from RAJAPerf `Apps_DIFFUSION3DPA` (`DIFFUSION3DPA_5`) which is is ~18% slower after #197391 with almost all of the extra time is in the loop nest:

```cpp
typedef double (*A3)[4][4];

extern "C" void kern(double *out, double *in, double *D, double *coef) {
  A3 DQQ0 = (A3)(in + 0), DQQ1 = (A3)(in + 64), DQQ2 = (A3)(in + 128);
  A3 QQQ0 = (A3)(out + 0), QQQ1 = (A3)(out + 64), QQQ2 = (A3)(out + 128);
  A3 O11 = (A3)(D + 0), O12 = (A3)(D + 64), O13 = (A3)(D + 128),
     O22 = (A3)(D + 192), O23 = (A3)(D + 256), O33 = (A3)(D + 320);
  for (int qz = 0; qz < 4; ++qz)
    for (int qy = 0; qy < 4; ++qy)
      for (int qx = 0; qx < 4; ++qx) {
        double u = 0.0, v = 0.0, w = 0.0;
        for (int dz = 0; dz < 3; ++dz) {
          u += DQQ0[dz][qy][qx] * coef[0 + dz];
          v += DQQ1[dz][qy][qx] * coef[3 + dz];
          w += DQQ2[dz][qy][qx] * coef[6 + dz];
        }
 const double o11 = O11[qz][qy][qx], o12 = O12[qz][qy][qx],
 o13 = O13[qz][qy][qx], o22 = O22[qz][qy][qx],
                     o23 = O23[qz][qy][qx], o33 = O33[qz][qy][qx];
        QQQ0[qz][qy][qx] = o11 * u + o12 * v + o13 * w;
        QQQ1[qz][qy][qx] = o12 * u + o22 * v + o23 * w;
 QQQ2[qz][qy][qx] = o13 * u + o23 * v + o33 * w;
      }
}
```

LV remarks before and after #197391:
```
$ ./good/bin/clang++ -O3 -mcpu=neoverse-v2 -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize -c reproducer.cpp
reproducer.cpp:10:5: remark: loop not vectorized: runtime pointer checks needed. Enable vectorization of this loop with '#pragma clang loop vectorize(enable)' when compiling with -Os/-Oz [-Rpass-analysis=loop-vectorize]
   10 |     for (int qy = 0; qy < 4; ++qy)
      |     ^
reproducer.cpp:10:5: remark: vectorization is not possible [-Rpass-missed=loop-vectorize]
reproducer.cpp:10:5: remark: interleaving is not possible [-Rpass-missed=loop-vectorize]

$ ./bad/bin/clang++ -O3 -mcpu=neoverse-v2 -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize -c reproducer.cpp
reproducer.cpp:10:5: remark: the cost-model indicates that interleaving is not beneficial [-Rpass-analysis=loop-vectorize]
   10 |     for (int qy = 0; qy < 4; ++qy)
      |     ^
reproducer.cpp:10:5: remark: vectorized loop (vectorization width: 2, interleaved count: 1) [-Rpass=loop-vectorize]
```

This might be the similar costing problem as #237151.

@fhahn @david-arm @Mel-Chen 
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to