On 02.02.2021 02:00, Ivan Sorokin wrote: > [PATCH] [PR91400] build only one __cpu_model variable
This is my first patch to GCC. So I might have done something totally stupid or totally wrong. Caution is required for reviewing. :-) > gcc/ChangeLog: > > PR target/91400 > * config/i386/i386-builtins.c (fold_builtin_cpu): Extract > building of __cpu_model and __processor_model into new > function. > * config/i386/i386-builtins.c (init_cpu_model_var): New. > Cache creation of __cpu_model and __processor_model. > > gcc/testsuite/Changelog: > > PR target/91400 > * gcc.target/i386/pr91400.c: New. I wrote the change log text manually. I hope I didn't mess up the formatting. > +static GTY(()) tree __cpu_model_var; > +static GTY(()) tree __processor_model_type; I felt a bit uneasy writing global variables, but this file contains other global variables already and they are used for similar purpose. > +static void > +init_cpu_model_var() > +{ > + if (__cpu_model_var != NULL_TREE) > + { > + gcc_assert(__processor_model_type != NULL_TREE); > + return; > + } > + > + __processor_model_type = build_processor_model_struct (); > + __cpu_model_var = make_var_decl (__processor_model_type, > + "__cpu_model"); > + > + varpool_node::add (__cpu_model_var); I have no idea what this line does. But I decided that perhaps we want to do it only once instead of once for each usage of __builtin_cpu_supports. > diff --git a/gcc/testsuite/gcc.target/i386/pr91400.c > b/gcc/testsuite/gcc.target/i386/pr91400.c > new file mode 100644 > index 00000000000..e8b7d9285f9 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr91400.c > @@ -0,0 +1,11 @@ > +/* PR target/91400 */ > +/* { dg-do compile { target { ! ia32 } } } */ > +/* { dg-options "-O2" } */ > +/* { dg-final { scan-assembler-times "andl" 1 } } */ > +/* { dg-final { scan-assembler-times "68" 2 } } */ > +/* { dg-final { scan-assembler-not "je" } } */ > + > +_Bool f() > +{ > + return __builtin_cpu_supports("popcnt") && > __builtin_cpu_supports("ssse3"); > +} The test was the most complicated thing for me. Previous versions of GCC did two instructions andl, so I written check for them. Current master does a conditional jump, so I add test for it too. Any suggestions for better checks are welcomed.