| Issue |
244138
|
| Summary |
[X86] SimplifyDemandedVectorEltsForTargetNode - incorrect f64 mask encoding in VPERMV to VPERMILPV narrowing
|
| Labels |
backend:X86,
regression:23
|
| Assignees |
|
| Reporter |
RKSimon
|
Described in #238829:
SimplifyDemandedVectorEltsForTargetNode narrows a 256-bit X86ISD::VPERMV whose upper elements are not demanded to a 128-bit X86ISD::VPERMILPV. It passes the VPERMV mask through unchanged. VPERMV masks hold plain element indices, but VPERMILPD selects with bit 1 of each mask element. So for f64, index 1 decodes as element 0, and the narrowed permute then folds to its input.
https://godbolt.org/z/cqdxnW7os
```cpp
#include <immintrin.h>
#include <cstdio>
__attribute__((noinline))
static double fold_max_lane01(__m512d v)
{
__m512d s = _mm512_permutexvar_pd(_mm512_set1_epi64(1), v);
__m512d m = _mm512_max_pd(v, s);
return _mm_cvtsd_f64(_mm512_castpd512_pd128(m));
}
int main()
{
volatile double in[8] = {1.0, 8.0, 2.0, 7.0, 3.0, 6.0, 4.0, 5.0};
double r = fold_max_lane01(_mm512_loadu_pd((const double*)in));
std::printf("result=%.17g expected=8.0 -> %s\n", r, r == 8.0 ? "PASS" : "FAIL");
return r == 8.0 ? 0 : 1;
}
```
clang++ -O2 -march=skylake-avx512 repro.cpp -o repro && ./repro
Affected versions
19.1.7, 20.1.8, 21.1.5 and 22.1.8 are correct.
23.1.4, 23.1.5 and trunk are wrong.
According to Claude (I left it here as it might be helpful):
The bad narrowing is older. It became reachable after https://github.com/llvm/llvm-project/commit/961ab7a3696701f9cc0c82a4cde7fc9937141b01 ("[SDAG][X86] Uplift pseudo fmin/fmax from X86"), which routes the x86 fmin/fmax intrinsics through ISD::PSEUDO_FMAX. I found this by reading the code. I did not confirm it with a build bisect.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs