llvm / llvm/llvm-project

x86 backend pessimizes `_mm*_andnot*` usages

Open
#212,169 4 comments 0 reactions 0 assignees View on GitHub
backend:X86
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Example: https://godbolt.org/z/oa5qx864a

Reproduced here:

```c
void f(__m512i x, __m512i& a, __m512i& b) {
__m512i mask = _mm512_set1_epi8(0xf);
a = _mm512_and_si512(mask, x);
b = _mm512_andnot_si512(mask, x);
}
```

I'm trying to use `and` and `andnot` to save registers. But the compiler defeats any attempt I can think of to avoid this, it constant folds the "not" part of `andnot` and generates code that uses two different masks.

Contributor guide

Open the contributing guide

Research direction

Run the linked Godbolt example and the C++ intrinsic reproducer first; no source file or test is named in the issue. Trace how the x86 backend handles _mm512_and_si512 and _mm512_andnot_si512, then compare the generated code with the reported two-mask behavior. Done means the reproduced case no longer pessimizes register use while preserving correct results.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.