On Wed, Nov 14, 2018 at 1:21 PM Jakub Jelinek <ja...@redhat.com> wrote: > > On Wed, Nov 14, 2018 at 09:29:15AM +0100, Richard Biener wrote: > > So where do the zero_extracts come from? Can we somehow avoid > > zero-sized bit-extracts at expansion time by folding them to zero? > > The following patch implements the missing folding. > Note, as I've mentioned, it is just an optimization, as if we are unlucky > enough, a constant could be propagated to the insn only at RTL optimization > time. So the other patch is needed, even when this patch also fixes the > bmi2-bzhi-2.c testcase execution. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? > > 2018-11-14 Jakub Jelinek <ja...@redhat.com> > > PR rtl-optimization/87817 > * config/i386/i386.c (ix86_fold_builtin): For _bzhi_u{32,64} if > last argument has low 8 bits clear, fold to 0. > > * gcc.target/i386/bmi2-bzhi-3.c (main): Add a couple of new tests.
OK. Thanks, Uros. > --- gcc/config/i386/i386.c.jj 2018-11-14 00:55:50.199357949 +0100 > +++ gcc/config/i386/i386.c 2018-11-14 10:28:29.492491865 +0100 > @@ -32671,6 +32671,8 @@ ix86_fold_builtin (tree fndecl, int n_ar > unsigned int idx = tree_to_uhwi (args[1]) & 0xff; > if (idx >= TYPE_PRECISION (TREE_TYPE (args[0]))) > return args[0]; > + if (idx == 0) > + return build_int_cst (TREE_TYPE (TREE_TYPE (fndecl)), 0); > if (!tree_fits_uhwi_p (args[0])) > break; > unsigned HOST_WIDE_INT res = tree_to_uhwi (args[0]); > --- gcc/testsuite/gcc.target/i386/bmi2-bzhi-3.c.jj 2016-10-31 > 13:28:07.961422421 +0100 > +++ gcc/testsuite/gcc.target/i386/bmi2-bzhi-3.c 2018-11-14 10:38:40.352417418 > +0100 > @@ -58,7 +58,11 @@ main () > link_error (); > if (_bzhi_u32 (c, 32) != c > || _bzhi_u32 (c, 64) != c > - || _bzhi_u32 (c, 255) != c) > + || _bzhi_u32 (c, 255) != c > + || _bzhi_u32 (c, 544) != c > + || _bzhi_u32 (c, 0) != 0 > + || _bzhi_u32 (c, 256) != 0 > + || _bzhi_u32 (c, 1024) != 0) > link_error (); > #ifdef __x86_64__ > if (f21 () != 0 || f22 (-1ULL) != 0 > @@ -70,7 +74,11 @@ main () > || f33 () != -1ULL || f34 (-1ULL) != -1ULL) > link_error (); > if (_bzhi_u64 (d, 64) != d > - || _bzhi_u64 (d, 255) != d) > + || _bzhi_u64 (d, 255) != d > + || _bzhi_u64 (d, 576) != d > + || _bzhi_u64 (d, 0) != 0 > + || _bzhi_u64 (d, 256) != 0 > + || _bzhi_u64 (d, 512) != 0) > link_error (); > #endif > return 0; > > > Jakub