Sorry,i mistakenly deleted local mail for https://gcc.gnu.org/pipermail/gcc-patches/2020-June/548174.html, so i send an another email.
> What I mean is that op2 is a CONST_INT, which in theory can have any
> HOST_WIDE_INT values.
> By assigning that to unsigned int variable, you are effectively
> testing shift % 0x100000000ULL instead of the shift.
>
> So, it is fine to use unsigned int (or even unsigned char) var for the
> shift_constant (shouldn't that be shift_amount?), but the test if it is
> outside of range then should be performed on if (UINTVAL (op2) > 7).
> And perhaps just don't bother with the out of bounds shifts, so just
> if (UINTVAL (op2) > 7)
> return false;
> because that is just UB and no need to optimize invalid code.
Changed and updated patch.
gcc/ChangeLog:
PR target/95524
* config/i386/i386-expand.c
(ix86_expand_vec_shift_qihi_constant): New function.
* config/i386/i386-protos.h
(ix86_expand_vec_shift_qihi_constant): Declare.
* config/i386/sse.md (<shift_insn><mode>3): Optimize shift
V*QImode by constant.
gcc/testsuite/ChangeLog:
* gcc.target/i386/avx2-shiftqihi-constant-1.c: New test.
* gcc.target/i386/avx2-shiftqihi-constant-2.c: Ditto.
* gcc.target/i386/avx512bw-shiftqihi-constant-1.c: Ditto.
* gcc.target/i386/avx512bw-shiftqihi-constant-2.c: Ditto.
* gcc.target/i386/sse2-shiftqihi-constant-1.c: Ditto.
* gcc.target/i386/sse2-shiftqihi-constant-2.c: Ditto.
--
BR,
Hongtao
0001-Optimize-V16QI-V32QI-V64QI-shift-by-constant_V2.patch
Description: Binary data
