llvm / llvm/llvm-project

bad vector codegen on loops with wide accumulators

Open
#168,775 5 comments 0 reactions 0 assignees View on GitHub
missed-optimization vectorizers
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```c
#include

uint64_t example_1(uint64_t len, const unsigned char* input) {
uint64_t total = 0;
for (uint64_t i = 0; i < len; i++) {
// example computation to be vectorized
unsigned char output = input[i] ^ 0x07;
// accumulator
total += output;
}
return total;
}
```
The loop vectorizer optimizes the above function very poorly: it chooses a vectorization width of 2, when it should be able to use a much higher vectorization width, ie 16.

If you pick a narrower accumulator (ie, change the type of total to uint8_t), the vectorizer will choose a high width as expected.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.