[X86][AVX512] suboptimal codegen with target x86-64-v4
from: https://github.com/llvm/llvm-project/issues/48223#issuecomment-5994295547
llvm generates for target x86-64-v4 with changed datatype from int16_t to int32_t or int64_t suboptimal code: https://gcc.godbolt.org/z/65rc6oaWY
@llvm/issue-subscribers-backend-x86
Author: Grenzschutzeinheit
llvm generates for target x86-64-v4 with changed datatype from int16_t to int32_t or int64_t suboptimal code: https://gcc.godbolt.org/z/65rc6oaWY
https://godbolt.org/z/3rGGz76ao
-mprefer-vector-width=512 gets the expected codegen.
So the issue is: should we remove TuningPrefer256Bit from x86-64-v4?
https://godbolt.org/z/3rGGz76ao
-mprefer-vector-width=512 gets the expected codegen.
So the issue is: should we remove TuningPrefer256Bit from x86-64-v4?
I suggest we should; we are collecting some data which seems to be supporting that case which we shall share soon. cc @ganeshgit
atm, nearly all Intel targets (i tested with core2 upwards) and also some AMD (znver2, znver3) produces better code at this case with x86-64-v4 then native: pantherlake https://godbolt.org/z/nc9GW6f5q
with additional -mprefer-vector-width=512 some targets also improve (haswell,ivybridge) and some fail (lunarlake, znver2, znver3) with:
error: found an unsupported instruction in the input assembly sequence, use -skip-unsupported-instructions=lack-sched to ignore these on the input.
note: instruction: vpminsq (%rsi), %zmm0, %zmm0
What's strange about that? vpminsq is avx512-only.
haswell, ivybridge even pantherlake etc. dont have AVX512 but get better code with that target (x86-64-v4) then with her own native. when x86-64-v4 get changed to prefer 512 then some targets even improve more (despite they dont have 512 bit Registers, some will fail. in my eyes then the native should be improved to be at least generate the code as x86-64-v4 gets today. i dont would call it regression as the x86-64-v4 isnt for non AVX512 targets but it works atm for some targets better then their own.
There is no room for improvement here. The reason x86-64-v4 looks better just because i64 smin can be directly lowered to vpminsq, but pantherlake doesn't support vpminsq (avx512-only), so instead use cmp+select to emulate it.
ok but then mca should show an unsupported instruction error with the given mcpu?
@Andarwinux Am I correct in understanding that llvm-mca with the -mcpu argument should display an "unsupported instruction" error if the code is not executable on that CPU?
For example: vpminsq on a Panther Lake
Assemblers don't verify instructions supported by specific target either. I think it's assemble users' responsibility to make sure they are valid. Compiler defines features only to make sure auto generated instructions are compatible. Even higher languages don't do such checks out of it. E.g., inline assemble in C, or target builtins in LLVM IR.