From: Jakub Jelinek Date: Tue, 8 May 2018 12:04:25 +0000 (+0200) Subject: re PR target/85317 (missing constant propagation on _mm(256)_movemask_*) X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=ac6818591810af25dc9f91d28230f30494e22a71;p=gcc.git re PR target/85317 (missing constant propagation on _mm(256)_movemask_*) PR target/85317 * config/i386/i386.c (ix86_fold_builtin): Handle IX86_BUILTIN_{,P}MOVMSK{PS,PD,B}{,128,256}. * gcc.target/i386/pr85317.c: New test. * gcc.target/i386/avx2-vpmovmskb-2.c (avx2_test): Add asm volatile optimization barrier to avoid optimizing away the expected insn. From-SVN: r260040 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 74c90d83fbb..0ff143bf603 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2018-05-08 Jakub Jelinek + PR target/85317 + * config/i386/i386.c (ix86_fold_builtin): Handle + IX86_BUILTIN_{,P}MOVMSK{PS,PD,B}{,128,256}. + PR target/85480 * config/i386/sse.md (ssequaterinsnmode): New mode attribute. (*_vinsert_0): New pattern. diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 6a2141e48db..d99ff968c90 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -33477,6 +33477,37 @@ ix86_fold_builtin (tree fndecl, int n_args, } break; + case IX86_BUILTIN_MOVMSKPS: + case IX86_BUILTIN_PMOVMSKB: + case IX86_BUILTIN_MOVMSKPD: + case IX86_BUILTIN_PMOVMSKB128: + case IX86_BUILTIN_MOVMSKPD256: + case IX86_BUILTIN_MOVMSKPS256: + case IX86_BUILTIN_PMOVMSKB256: + gcc_assert (n_args == 1); + if (TREE_CODE (args[0]) == VECTOR_CST) + { + HOST_WIDE_INT res = 0; + for (unsigned i = 0; i < VECTOR_CST_NELTS (args[0]); ++i) + { + tree e = VECTOR_CST_ELT (args[0], i); + if (TREE_CODE (e) == INTEGER_CST && !TREE_OVERFLOW (e)) + { + if (wi::neg_p (wi::to_wide (e))) + res |= HOST_WIDE_INT_1 << i; + } + else if (TREE_CODE (e) == REAL_CST && !TREE_OVERFLOW (e)) + { + if (TREE_REAL_CST (e).sign) + res |= HOST_WIDE_INT_1 << i; + } + else + return NULL_TREE; + } + return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), res); + } + break; + default: break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 6d92f7ee1c2..c6d35858e4c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,5 +1,10 @@ 2018-05-08 Jakub Jelinek + PR target/85317 + * gcc.target/i386/pr85317.c: New test. + * gcc.target/i386/avx2-vpmovmskb-2.c (avx2_test): Add asm volatile + optimization barrier to avoid optimizing away the expected insn. + PR target/85480 * gcc.target/i386/avx512dq-pr85480-1.c: New test. * gcc.target/i386/avx512dq-pr85480-2.c: New test. diff --git a/gcc/testsuite/gcc.target/i386/avx2-vpmovmskb-2.c b/gcc/testsuite/gcc.target/i386/avx2-vpmovmskb-2.c index e5a9c10e147..71e65c93783 100644 --- a/gcc/testsuite/gcc.target/i386/avx2-vpmovmskb-2.c +++ b/gcc/testsuite/gcc.target/i386/avx2-vpmovmskb-2.c @@ -14,6 +14,7 @@ avx2_test (void) s.x = _mm256_set_epi8 (1, 2, 3, 4, 10, 20, 30, 90, -80, -40, -100, 15, 98, 25, 98, 7, 1, 2, 3, 4, 10, 20, 30, 90, -80, -40, -100, -15, 98, 25, 98, 7); + __asm volatile ("" : "+m" (s) : : "memory"); res = _mm256_movemask_epi8 (s.x); diff --git a/gcc/testsuite/gcc.target/i386/pr85317.c b/gcc/testsuite/gcc.target/i386/pr85317.c new file mode 100644 index 00000000000..78c5b0cd222 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr85317.c @@ -0,0 +1,38 @@ +/* PR target/85317 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -mavx2 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump-not "link_error" "optimized" } } */ + +#include + +extern void link_error (void); + +int +main () +{ + int a = _mm_movemask_pd (_mm_set_pd (-2.0, 2.0)); + if (a != 2) link_error (); + int b = _mm_movemask_pd (_mm_set_pd (0.0, __builtin_copysign (0.0, -4.0))); + if (b != 1) link_error (); + int c = _mm_movemask_ps (_mm_set_ps (__builtin_copysignf (0.0f, -4.0f), 0.0f, + -4.0f, 4.0f)); + if (c != 10) link_error (); + int d = _mm_movemask_epi8 (_mm_set_epi8 (-4, 8, -8, -12, 12, 15, 0, -1, -3, + -128, 127, 126, 120, -120, 0, 5)); + if (d != 0xb1c4) link_error (); + int e = _mm256_movemask_pd (_mm256_set_pd (-4.0, 0.0, 4.0, + __builtin_copysign (0.0, -4.0))); + if (e != 9) link_error (); + int f = _mm256_movemask_ps (_mm256_set_ps (-8.0f, -16.0f, 12.0f, 127.0f, + -4.0f, 0.0f, 4.0f, + __builtin_copysign (0.0f, + -4.0f))); + if (f != 0xc9) link_error (); + int g = _mm256_movemask_epi8 (_mm256_set_epi8 (-4, 8, -8, -12, 12, 15, 0, -1, + -3, -128, 127, 126, 120, -120, + 0, 5, 12, 100, -20, -50, -70, + 2, -65, 0, -1, 1, 2, -2, -9, + -9, 19, -64)); + if (g != (int) 0xb1c43a9dU) link_error (); + return 0; +}