On Tue, Jun 20, 2023 at 6:11 PM liuhongt via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > I notice there's some refactor in vectorizable_conversion > for code_helper,so I've adjusted my patch to that. > Here's the patch I'm going to commit. > > We have already use intermidate type in case WIDEN, but not for NONE, > this patch extended that. > > gcc/ChangeLog: > > PR target/110018 > * tree-vect-stmts.cc (vectorizable_conversion): Use > intermiediate integer type for float_expr/fix_trunc_expr when > direct optab is not existed. > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/pr110018-1.c: New test.
> + > + /* For conversions between float and smaller integer types try whether > we > + can use intermediate signed integer types to support the > + conversion. */ I'm trying to enhance testcase coverage with explicit signed/unsigned types (patch attached), and I have noticed that zero-extension is used for unsigned types. So, the above comment that mentions only signed integer types is not entirely correct. Uros.
diff --git a/gcc/testsuite/gcc.target/i386/pr110018-1.c b/gcc/testsuite/gcc.target/i386/pr110018-1.c index b1baffd7af1..b6a3be7b7a2 100644 --- a/gcc/testsuite/gcc.target/i386/pr110018-1.c +++ b/gcc/testsuite/gcc.target/i386/pr110018-1.c @@ -4,14 +4,14 @@ /* { dg-final { scan-assembler-times {(?n)vcvt[dqw]*2p[dsh]} 5 } } */ void -foo (double* __restrict a, char* b) +foo (double* __restrict a, signed char* b) { a[0] = b[0]; a[1] = b[1]; } void -foo1 (float* __restrict a, char* b) +foo1 (float* __restrict a, signed char* b) { a[0] = b[0]; a[1] = b[1]; @@ -20,7 +20,7 @@ foo1 (float* __restrict a, char* b) } void -foo2 (_Float16* __restrict a, char* b) +foo2 (_Float16* __restrict a, signed char* b) { a[0] = b[0]; a[1] = b[1]; @@ -33,14 +33,14 @@ foo2 (_Float16* __restrict a, char* b) } void -foo3 (double* __restrict a, short* b) +foo3 (double* __restrict a, signed short* b) { a[0] = b[0]; a[1] = b[1]; } void -foo4 (float* __restrict a, char* b) +foo4 (float* __restrict a, signed char* b) { a[0] = b[0]; a[1] = b[1]; @@ -49,14 +49,14 @@ foo4 (float* __restrict a, char* b) } void -foo5 (double* __restrict b, char* a) +foo5 (double* __restrict b, signed char* a) { a[0] = b[0]; a[1] = b[1]; } void -foo6 (float* __restrict b, char* a) +foo6 (float* __restrict b, signed char* a) { a[0] = b[0]; a[1] = b[1]; @@ -65,7 +65,7 @@ foo6 (float* __restrict b, char* a) } void -foo7 (_Float16* __restrict b, char* a) +foo7 (_Float16* __restrict b, signed char* a) { a[0] = b[0]; a[1] = b[1]; @@ -78,14 +78,14 @@ foo7 (_Float16* __restrict b, char* a) } void -foo8 (double* __restrict b, short* a) +foo8 (double* __restrict b, signed short* a) { a[0] = b[0]; a[1] = b[1]; } void -foo9 (float* __restrict b, char* a) +foo9 (float* __restrict b, signed char* a) { a[0] = b[0]; a[1] = b[1]; diff --git a/gcc/testsuite/gcc.target/i386/pr110018-2.c b/gcc/testsuite/gcc.target/i386/pr110018-2.c new file mode 100644 index 00000000000..a663e074698 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr110018-2.c @@ -0,0 +1,94 @@ +/* { dg-do compile } */ +/* { dg-options "-mavx512fp16 -mavx512vl -O2 -mavx512dq" } */ +/* { dg-final { scan-assembler-times {(?n)vcvttp[dsh]2[dqw]} 5 } } */ +/* { dg-final { scan-assembler-times {(?n)vcvt[dqw]*2p[dsh]} 5 } } */ + +void +foo (double* __restrict a, unsigned char* b) +{ + a[0] = b[0]; + a[1] = b[1]; +} + +void +foo1 (float* __restrict a, unsigned char* b) +{ + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; +} + +void +foo2 (_Float16* __restrict a, unsigned char* b) +{ + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; + a[4] = b[4]; + a[5] = b[5]; + a[6] = b[6]; + a[7] = b[7]; +} + +void +foo3 (double* __restrict a, unsigned short* b) +{ + a[0] = b[0]; + a[1] = b[1]; +} + +void +foo4 (float* __restrict a, unsigned char* b) +{ + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; +} + +void +foo5 (double* __restrict b, unsigned char* a) +{ + a[0] = b[0]; + a[1] = b[1]; +} + +void +foo6 (float* __restrict b, unsigned char* a) +{ + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; +} + +void +foo7 (_Float16* __restrict b, unsigned char* a) +{ + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; + a[4] = b[4]; + a[5] = b[5]; + a[6] = b[6]; + a[7] = b[7]; +} + +void +foo8 (double* __restrict b, unsigned short* a) +{ + a[0] = b[0]; + a[1] = b[1]; +} + +void +foo9 (float* __restrict b, unsigned char* a) +{ + a[0] = b[0]; + a[1] = b[1]; + a[2] = b[2]; + a[3] = b[3]; +}