SLP Vectorization Regression in 23.x
A profitable SLP vectorization present in 22.x is missing in 23.x, causing a performance regression in downstream benchmarks. The missing vectorization is SLP vectorized with cost ** and with tree size 9 on a common gradient-accumulation pattern involving abs().|
Reduced test case
typedef unsigned char uint8_t;
struct LUT { unsigned char weight, bin; };
extern const LUT lut[];
void func(const uint8_t* __restrict src, int* __restrict descriptor, int N) {
const LUT *p = lut;
for (int i = 0; i < N; i++) {
int gradX = src[1] - src[-1];
int gradY = src[17] - src[-17];
src++;
int weight = p->weight;
int binOffset = (*p++).bin;
int *binPtr = descriptor + binOffset;
int rx = gradX * weight;
int ry = gradY * weight;
binPtr[0] += rx;
binPtr[1] += ry;
binPtr[2] += __builtin_abs(rx);
binPtr[3] += __builtin_abs(ry);
}
}
Compilation command
clang++ --target=aarch64-linux-gnu -c -mcpu=cortex-a57 -O3 -std=gnu++98 -Rpass=slp-vectorize reduced.cc
I found out couple of patches are attributing to regression
- https://github.com/llvm/llvm-project/pull/190414
- https://github.com/llvm/llvm-project/pull/199129
When I suppressed 1 using " -mllvm -slp-inst-count-check=0" and second by reverting, I am able to retrieve the vectorization.
22.x output :
reduced.cc:17:19: remark: Stores SLP vectorized with cost -1 and with tree size 4 [-Rpass=slp-vectorizer]
reduced.cc:17:19: remark: SLP vectorized with cost -6 and with tree size 9 [-Rpass=slp-vectorizer]
23.x output (regression):
reduced.cc:17:19: remark: Stores SLP vectorized with cost -2 and with tree size 4 [-Rpass=slp-vectorizer]
23.x output with revert of #199129 + -mllvm -slp-inst-count-check=0 :
reduced.cc:17:19: remark: Stores SLP vectorized with cost -2 and with tree size 4 [-Rpass=slp-vectorizer]
reduced.cc:17:19: remark: SLP vectorized with cost -8 and with tree size 9 [-Rpass=slp-vectorizer]