public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/91400] __builtin_cpu_supports conjunction is optimized poorly
       [not found] <bug-91400-4@http.gcc.gnu.org/bugzilla/>
@ 2021-02-04  8:07 ` vanyacpp at gmail dot com
  2021-05-05 18:42 ` cvs-commit at gcc dot gnu.org
  2021-05-06 13:40 ` hjl.tools at gmail dot com
  2 siblings, 0 replies; 3+ messages in thread
From: vanyacpp at gmail dot com @ 2021-02-04  8:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91400

--- Comment #2 from Ivan Sorokin <vanyacpp at gmail dot com> ---
I've sent a patch to gcc-patches mailing list:
https://gcc.gnu.org/pipermail/gcc-patches/2021-February/564663.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/91400] __builtin_cpu_supports conjunction is optimized poorly
       [not found] <bug-91400-4@http.gcc.gnu.org/bugzilla/>
  2021-02-04  8:07 ` [Bug target/91400] __builtin_cpu_supports conjunction is optimized poorly vanyacpp at gmail dot com
@ 2021-05-05 18:42 ` cvs-commit at gcc dot gnu.org
  2021-05-06 13:40 ` hjl.tools at gmail dot com
  2 siblings, 0 replies; 3+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-05-05 18:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91400

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by H.J. Lu <hjl@gcc.gnu.org>:

https://gcc.gnu.org/g:a0b4e09ab0102d9c0a5e6d603a080cb78600c40d

commit r12-524-ga0b4e09ab0102d9c0a5e6d603a080cb78600c40d
Author: Ivan Sorokin <vanyacpp@gmail.com>
Date:   Mon May 3 11:39:48 2021 +0300

    x86: Build only one __cpu_model/__cpu_features2 variables

    GCC -O2 generated quite bad code for this function:

    bool
    f (void)
    {
      return __builtin_cpu_supports("popcnt")
             && __builtin_cpu_supports("ssse3");
    }

    f:
            movl    __cpu_model+12(%rip), %edx
            movl    %edx, %eax
            shrl    $6, %eax
            andl    $1, %eax
            andl    $4, %edx
            movl    $0, %edx
            cmove   %edx, %eax
            ret

    The problem was caused by the fact that internally every invocation of
    __builtin_cpu_supports built a new variable __cpu_model and a new type
    __processor_model.  Because of this, GIMPLE level optimizers weren't able
    to CSE the loads of __cpu_model and optimize bit-operations properly.

    Improve GCC -O2 code generation by caching __cpu_model and__cpu_features2
    variables as well as their types:

    f:
            movl    __cpu_model+12(%rip), %eax
            andl    $68, %eax
            cmpl    $68, %eax
            sete    %al
            ret

    2021-05-05  Ivan Sorokin <vanyacpp@gmail.com>
                H.J. Lu <hjl.tools@gmail.com>

    gcc/

            PR target/91400
            * config/i386/i386-builtins.c (ix86_cpu_model_type_node): New.
            (ix86_cpu_model_var): Likewise.
            (ix86_cpu_features2_type_node): Likewise.
            (ix86_cpu_features2_var): Likewise.
            (fold_builtin_cpu): Cache __cpu_model and __cpu_features2 with
            their types.

    gcc/testsuite/

            PR target/91400
            * gcc.target/i386/pr91400-1.c: New test.
            * gcc.target/i386/pr91400-2.c: Likewise.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug target/91400] __builtin_cpu_supports conjunction is optimized poorly
       [not found] <bug-91400-4@http.gcc.gnu.org/bugzilla/>
  2021-02-04  8:07 ` [Bug target/91400] __builtin_cpu_supports conjunction is optimized poorly vanyacpp at gmail dot com
  2021-05-05 18:42 ` cvs-commit at gcc dot gnu.org
@ 2021-05-06 13:40 ` hjl.tools at gmail dot com
  2 siblings, 0 replies; 3+ messages in thread
From: hjl.tools at gmail dot com @ 2021-05-06 13:40 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91400

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|unknown                     |12.0
         Resolution|---                         |FIXED
   Target Milestone|---                         |12.0
             Status|NEW                         |RESOLVED

--- Comment #4 from H.J. Lu <hjl.tools at gmail dot com> ---
Fixed for GCC 12.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-05-06 13:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-91400-4@http.gcc.gnu.org/bugzilla/>
2021-02-04  8:07 ` [Bug target/91400] __builtin_cpu_supports conjunction is optimized poorly vanyacpp at gmail dot com
2021-05-05 18:42 ` cvs-commit at gcc dot gnu.org
2021-05-06 13:40 ` hjl.tools at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).