llvm / llvm/llvm-project

Missed AVX2 Vectorization

Open
#176,016 4 comments 0 reactions 0 assignees View on GitHub
backend:X86 llvm:SLPVectorizer missed-optimization
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

GCC vectorized the update_correction_history function here whereas clang simply unrolled it to scalar code.

https://godbolt.org/z/r7MT5z7n4

```c++
void update_correction_history(const Position& pos,
Search::Worker& workerThread,
const int bonus) {
const Color us = pos.side_to_move();

constexpr int nonPawnWeight = 178;
auto& shared = workerThread.sharedHistory;

alignas(16) std::int32_t v[4] = {
shared.pawn_correction_entry(pos)[us].pawn,
shared.minor_piece_correction_entry(pos)[us].minor,
shared.nonpawn_correction_entry(pos)[us].nonPawnWhite,
shared.nonpawn_correction_entry(pos)[us].nonPawnBlack,
};

std::int32_t b[4] = { bonus,
bonus * 156 / 128,
bonus * nonPawnWeight / 128,
bonus * nonPawnWeight / 128 };

auto D = CORRECTION_HISTORY_LIMIT;
for (int i = 0; i < 4; ++i) {
int clamped = std::clamp(b[i], -D, D);
v[i] += clamped - v[i] * std::abs(clamped) / D;
}

shared.pawn_correction_entry(pos).at(us).pawn.from_raw(v[0]);
shared.minor_piece_correction_entry(pos).at(us).minor.from_raw(v[1]);
shared.nonpawn_correction_entry(pos).at(us).nonPawnWhite.from_raw(v[2]);
shared.nonpawn_correction_entry(pos).at(us).nonPawnBlack.from_raw(v[3]);
}
```

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.