public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/94403] New: Missed optimization bswap
@ 2020-03-30 15:40 boris_oncev at hotmail dot com
  2020-03-30 15:46 ` [Bug other/94403] " boris_oncev at hotmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: boris_oncev at hotmail dot com @ 2020-03-30 15:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94403
           Summary: Missed optimization bswap
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: boris_oncev at hotmail dot com
  Target Milestone: ---

full code:
https://godbolt.org/z/zjNqYV

template <typename T>
auto reverse(T num) {

    // misses optimization when num is int32_t OK for int64_t
    auto* bytes = reinterpret_cast<char*>(&num);

    // misses optimization for both 32 and 64 bit ints
    //auto* bytes = reinterpret_cast<std::byte*>(&num);

    constexpr auto size = sizeof(num);
    for (int i = 0; i < size / 2; i++) {
        std::swap(bytes[i], bytes[size-i-1]);
    }

    return num;
}

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

* [Bug other/94403] Missed optimization bswap
  2020-03-30 15:40 [Bug other/94403] New: Missed optimization bswap boris_oncev at hotmail dot com
@ 2020-03-30 15:46 ` boris_oncev at hotmail dot com
  2020-03-30 16:40 ` [Bug tree-optimization/94403] " jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: boris_oncev at hotmail dot com @ 2020-03-30 15:46 UTC (permalink / raw)
  To: gcc-bugs

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

Boris <boris_oncev at hotmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #1 from Boris <boris_oncev at hotmail dot com> ---
Very similar

*** This bug has been marked as a duplicate of bug 93328 ***

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

* [Bug tree-optimization/94403] Missed optimization bswap
  2020-03-30 15:40 [Bug other/94403] New: Missed optimization bswap boris_oncev at hotmail dot com
  2020-03-30 15:46 ` [Bug other/94403] " boris_oncev at hotmail dot com
@ 2020-03-30 16:40 ` jakub at gcc dot gnu.org
  2020-03-30 16:55 ` jakub at gcc dot gnu.org
  2020-03-31  9:05 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-30 16:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|other                       |tree-optimization
   Last reconfirmed|                            |2020-03-30
     Ever confirmed|0                           |1
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|DUPLICATE                   |---
             Status|RESOLVED                    |REOPENED

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I don't see how it is similar except that it is about bswap detection.
Your comment is weird, because bswap is detected for int32_t and not for
int64_t, while the comment suggests otherwise.
And the reason this is optimized for int32_t only is that the loop is
completely unrolled in that case, but not for int64_t, where cunrolli punts on
it even with -O2 -funroll-loops or -O3.

And, the std::byte issue is unrelated to that.
--- gcc/gimple-ssa-store-merging.c.jj   2020-03-20 09:33:03.602112329 +0100
+++ gcc/gimple-ssa-store-merging.c      2020-03-30 18:30:31.723341519 +0200
@@ -315,7 +315,8 @@ verify_symbolic_number_p (struct symboli

   lhs_type = gimple_expr_type (stmt);

-  if (TREE_CODE (lhs_type) != INTEGER_TYPE)
+  if (TREE_CODE (lhs_type) != INTEGER_TYPE
+      && TREE_CODE (lhs_type) != ENUMERAL_TYPE)
     return false;

   if (TYPE_PRECISION (lhs_type) != TYPE_PRECISION (n->type))
can fix that one.

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

* [Bug tree-optimization/94403] Missed optimization bswap
  2020-03-30 15:40 [Bug other/94403] New: Missed optimization bswap boris_oncev at hotmail dot com
  2020-03-30 15:46 ` [Bug other/94403] " boris_oncev at hotmail dot com
  2020-03-30 16:40 ` [Bug tree-optimization/94403] " jakub at gcc dot gnu.org
@ 2020-03-30 16:55 ` jakub at gcc dot gnu.org
  2020-03-31  9:05 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-30 16:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Created attachment 48147
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48147&action=edit
gcc10-pr94403.patch

Untested fix for the std::byte part.  Not a regression, so will have to wait
for GCC11.  Also, if the testcase doesn't have the assignment of the parameter
into a separate local temporary (i.e. when the parameter itself is
addressable), then it doesn't work either, the loads stay as MEM_REFs instead
of being transformed to BIT_FIELD_REFs on the parameter.

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

* [Bug tree-optimization/94403] Missed optimization bswap
  2020-03-30 15:40 [Bug other/94403] New: Missed optimization bswap boris_oncev at hotmail dot com
                   ` (2 preceding siblings ...)
  2020-03-30 16:55 ` jakub at gcc dot gnu.org
@ 2020-03-31  9:05 ` cvs-commit at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-03-31  9:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 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:5ea39b2412269d208bb6ebd78303815957bd4f70

commit r10-7470-g5ea39b2412269d208bb6ebd78303815957bd4f70
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Tue Mar 31 11:04:32 2020 +0200

    store-merging: Allow enums during bswap recognition [PR94403]

    The following testcase is optimized with char/unsigned char/signed char,
    but not with std::byte.  The following patch fixes that.  Didn't use
    INTEGRAL_TYPE_P because bswapping bools is just too weird.

    2020-03-31  Jakub Jelinek  <jakub@redhat.com>

            PR tree-optimization/94403
            * gimple-ssa-store-merging.c (verify_symbolic_number_p): Allow also
            ENUMERAL_TYPE lhs_type.

            * g++.dg/tree-ssa/pr94403.C: New test.

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

end of thread, other threads:[~2020-03-31  9:05 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-30 15:40 [Bug other/94403] New: Missed optimization bswap boris_oncev at hotmail dot com
2020-03-30 15:46 ` [Bug other/94403] " boris_oncev at hotmail dot com
2020-03-30 16:40 ` [Bug tree-optimization/94403] " jakub at gcc dot gnu.org
2020-03-30 16:55 ` jakub at gcc dot gnu.org
2020-03-31  9:05 ` cvs-commit 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).