public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory
@ 2020-07-21 16:41 gabravier at gmail dot com
  2020-07-21 18:49 ` [Bug target/96271] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: gabravier at gmail dot com @ 2020-07-21 16:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96271
           Summary: Failure to optimize memcmp of doubles to avoid going
                    through memory
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

bool f(double a, double b)
{
   return memcmp(&a, &b, sizeof(double)) == 0;
}

With -O3, LLVM outputs this :

f(double, double):
  movq rax, xmm0
  movq rcx, xmm1
  cmp rax, rcx
  sete al
  ret

GCC outputs this:

f(double, double):
  movsd QWORD PTR [rsp-8], xmm0
  movsd QWORD PTR [rsp-16], xmm1
  mov rax, QWORD PTR [rsp-16]
  cmp QWORD PTR [rsp-8], rax
  sete al
  ret

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

* [Bug target/96271] Failure to optimize memcmp of doubles to avoid going through memory
  2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
@ 2020-07-21 18:49 ` pinskia at gcc dot gnu.org
  2020-07-21 22:13 ` gabravier at gmail dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-07-21 18:49 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|tree-optimization           |target

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Did you try -march=intel ?

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

* [Bug target/96271] Failure to optimize memcmp of doubles to avoid going through memory
  2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
  2020-07-21 18:49 ` [Bug target/96271] " pinskia at gcc dot gnu.org
@ 2020-07-21 22:13 ` gabravier at gmail dot com
  2020-07-22  7:23 ` crazylht at gmail dot com
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: gabravier at gmail dot com @ 2020-07-21 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Gabriel Ravier <gabravier at gmail dot com> ---
What do you mean ? -march=intel doesn't exist and I have tried -mtune=intel, I
see no difference in the handling of this regardless of any -march/tune flags
(I've tried : none, -march=nocona, -march=tigerlake, -mtune=intel,
-march=znver2), unless there is somehow a big problem with `movq r64, xmm` on
all x86-64 processors, this should be considered a bug.

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

* [Bug target/96271] Failure to optimize memcmp of doubles to avoid going through memory
  2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
  2020-07-21 18:49 ` [Bug target/96271] " pinskia at gcc dot gnu.org
  2020-07-21 22:13 ` gabravier at gmail dot com
@ 2020-07-22  7:23 ` crazylht at gmail dot com
  2020-07-22  7:59 ` [Bug tree-optimization/96271] " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: crazylht at gmail dot com @ 2020-07-22  7:23 UTC (permalink / raw)
  To: gcc-bugs

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

Hongtao.liu <crazylht at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crazylht at gmail dot com

--- Comment #3 from Hongtao.liu <crazylht at gmail dot com> ---
in for testcase.c.267r.dse1

pass_dse1 fail to delete

---
trying to replace DImode load in insn 7 from DFmode store in insn 2
-- could not extract bits of stored value

trying to replace DImode load in insn 8 from DFmode store in insn 3
-- could not extract bits of stored value

...


(insn 2 5 3 2 (set (mem/c:DF (plus:DI (reg/f:DI 19 frame)
                (const_int -8 [0xfffffffffffffff8])) [1 a+0 S8 A64])
        (reg:DF 20 xmm0 [ a ])) "pr96271_double.c":4:1 135 {*movdf_internal}
     (expr_list:REG_DEAD (reg:DF 20 xmm0 [ a ])

...


(insn 7 4 8 2 (set (reg:DI 87 [ MEM <unsigned long> [(char * {ref-all})&a] ])
        (mem/c:DI (plus:DI (reg/f:DI 19 frame)
                (const_int -8 [0xfffffffffffffff8])) [0 MEM <unsigned long>
[(char * {ref-all})&a]+0 S8 A64])) "pr96271_double.c":5:37 74 {*movdi_internal}
     (nil))

...

---

Shouldn't DImode load behave the same with DFmode load?

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

* [Bug tree-optimization/96271] Failure to optimize memcmp of doubles to avoid going through memory
  2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
                   ` (2 preceding siblings ...)
  2020-07-22  7:23 ` crazylht at gmail dot com
@ 2020-07-22  7:59 ` rguenth at gcc dot gnu.org
  2021-01-15 14:26 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-07-22  7:59 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
          Component|target                      |tree-optimization
   Last reconfirmed|                            |2020-07-22
     Ever confirmed|0                           |1

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note this could be folded on the GIMPLE level already similar to how we
inline string comparisons of size 1.  We should already fold this to
MEMCMP_EQ builtins and those can be inlined for bigger sizes, profitable
when we can emit a single load to a register for both values (thus
power-of-two size up to word_mode at least).  Desired gimple:

  _1 = VIEW_CONVERT <unsigned long> (a);
  _2 = VIEW_CONVERT <unsigned long> (b);
  _3 = _1 != _2;
  return _3;

and memcmp of size 1 can be inlined as two char loads and subtraction.

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

* [Bug tree-optimization/96271] Failure to optimize memcmp of doubles to avoid going through memory
  2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
                   ` (3 preceding siblings ...)
  2020-07-22  7:59 ` [Bug tree-optimization/96271] " rguenth at gcc dot gnu.org
@ 2021-01-15 14:26 ` jakub at gcc dot gnu.org
  2021-01-16  8:20 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-15 14:26 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |jakub at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 49974
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49974&action=edit
gcc11-pr96271.patch

We actually do that at the GIMPLE level, just quite late and don't set
TODO_update_address_taken if we do.

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

* [Bug tree-optimization/96271] Failure to optimize memcmp of doubles to avoid going through memory
  2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
                   ` (4 preceding siblings ...)
  2021-01-15 14:26 ` jakub at gcc dot gnu.org
@ 2021-01-16  8:20 ` cvs-commit at gcc dot gnu.org
  2021-01-16  8:26 ` jakub at gcc dot gnu.org
  2021-01-16  8:43 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-01-16  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <jakub@gcc.gnu.org>:

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

commit r11-6747-gb673e7547fb95d1f0d5cd17ae9e3874742cade66
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Sat Jan 16 09:17:38 2021 +0100

    cd_dce: Return TODO_update_address_taken from last cd_dce [PR96271]

    On the following testcase, handle_builtin_memcmp in the strlen pass folds
    the memcmp into comparison of two MEM_REFs.  But nothing triggers updating
    of addressable vars afterwards, so even when the parameters are no longer
    address taken, we force the parameters to stack and back anyway.

    This patch causes TODO_update_address_taken to happen right before last
forwprop
    pass (at the end of last cd_dce), so after strlen1 too.

    2021-01-16  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/96271
            * passes.def: Pass false argument to first two pass_cd_dce
            instances and true to last instance.  Add comment that
            last instance rewrites no longer addressed locals.
            * tree-ssa-dce.c (pass_cd_dce): Add update_address_taken_p member
and
            initialize it.
            (pass_cd_dce::set_pass_param): New method.
            (pass_cd_dce::execute): Return TODO_update_address_taken from
            last cd_dce instance.

            * gcc.target/i386/pr96271.c: New test.

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

* [Bug tree-optimization/96271] Failure to optimize memcmp of doubles to avoid going through memory
  2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
                   ` (5 preceding siblings ...)
  2021-01-16  8:20 ` cvs-commit at gcc dot gnu.org
@ 2021-01-16  8:26 ` jakub at gcc dot gnu.org
  2021-01-16  8:43 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-16  8:26 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Fixed.  Probably the last of these missed-optimization bugfixes from me for GCC
11, tomorrow starts stage4 and only regression bugfixes will be allowed.

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

* [Bug tree-optimization/96271] Failure to optimize memcmp of doubles to avoid going through memory
  2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
                   ` (6 preceding siblings ...)
  2021-01-16  8:26 ` jakub at gcc dot gnu.org
@ 2021-01-16  8:43 ` jakub at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-01-16  8:43 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
.

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

end of thread, other threads:[~2021-01-16  8:43 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 16:41 [Bug tree-optimization/96271] New: Failure to optimize memcmp of doubles to avoid going through memory gabravier at gmail dot com
2020-07-21 18:49 ` [Bug target/96271] " pinskia at gcc dot gnu.org
2020-07-21 22:13 ` gabravier at gmail dot com
2020-07-22  7:23 ` crazylht at gmail dot com
2020-07-22  7:59 ` [Bug tree-optimization/96271] " rguenth at gcc dot gnu.org
2021-01-15 14:26 ` jakub at gcc dot gnu.org
2021-01-16  8:20 ` cvs-commit at gcc dot gnu.org
2021-01-16  8:26 ` jakub at gcc dot gnu.org
2021-01-16  8:43 ` jakub at gcc dot gnu.org

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).