public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/99396] std::rotl and std::rotr Does not convert into ROTATE on the gimple level
Date: Fri, 05 Mar 2021 09:36:25 +0000	[thread overview]
Message-ID: <bug-99396-4-sb0rYtyqaF@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99396-4@http.gcc.gnu.org/bugzilla/>

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
There is absolutely no reason why libstdc++ should use any intrinsics for the
rotates, gcc recognizes a lot of patterns into rotates.
Just not the extra verbose one used in libstdc++.
The comment in gcc says:
/* Recognize rotation patterns.  Return true if a transformation
   applied, otherwise return false.

   We are looking for X with unsigned type T with bitsize B, OP being
   +, | or ^, some type T2 wider than T.  For:
   (X << CNT1) OP (X >> CNT2)                           iff CNT1 + CNT2 == B
   ((T) ((T2) X << CNT1)) OP ((T) ((T2) X >> CNT2))     iff CNT1 + CNT2 == B

   transform these into:
   X r<< CNT1

   Or for:
   (X << Y) OP (X >> (B - Y))
   (X << (int) Y) OP (X >> (int) (B - Y))
   ((T) ((T2) X << Y)) OP ((T) ((T2) X >> (B - Y)))
   ((T) ((T2) X << (int) Y)) OP ((T) ((T2) X >> (int) (B - Y)))
   (X << Y) | (X >> ((-Y) & (B - 1)))
   (X << (int) Y) | (X >> (int) ((-Y) & (B - 1)))
   ((T) ((T2) X << Y)) | ((T) ((T2) X >> ((-Y) & (B - 1))))
   ((T) ((T2) X << (int) Y)) | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))

   transform these into:
   X r<< Y

   Or for:
   (X << (Y & (B - 1))) | (X >> ((-Y) & (B - 1)))
   (X << (int) (Y & (B - 1))) | (X >> (int) ((-Y) & (B - 1)))
   ((T) ((T2) X << (Y & (B - 1)))) | ((T) ((T2) X >> ((-Y) & (B - 1))))
   ((T) ((T2) X << (int) (Y & (B - 1)))) \
     | ((T) ((T2) X >> (int) ((-Y) & (B - 1))))

   transform these into:
   X r<< (Y & (B - 1))

   Note, in the patterns with T2 type, the type of OP operands
   might be even a signed type, but should have precision B.
   Expressions with & (B - 1) should be recognized only if B is
   a power of 2.  */

but libstdc++ does e.g.
      constexpr auto _Nd = __gnu_cxx::__int_traits<_Tp>::__digits;
      const int __r = __s % _Nd;
      if (__r == 0)
        return __x;
      else if (__r > 0)
        return (__x << __r) | (__x >> ((_Nd - __r) % _Nd));
      else
        return (__x >> -__r) | (__x << ((_Nd + __r) % _Nd)); // rotr(x, -r)
So, can't it e.g. use
      constexpr auto _Nd = __gnu_cxx::__int_traits<_Tp>::__digits;
      const auto __r = static_cast<unsigned int>(__s);
      return (__x << (__r % _Nd)) | (__x >> ((-__r) % _Nd));
?

  parent reply	other threads:[~2021-03-05  9:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-04 23:09 [Bug libstdc++/99396] New: std::rotl and std::rotr do not invoke intrinsics, leading to serious performance issues unlvsur at live dot com
2021-03-05  0:05 ` [Bug tree-optimization/99396] " pinskia at gcc dot gnu.org
2021-03-05  0:06 ` [Bug tree-optimization/99396] std::rotl and std::rotr Does not convert into ROTATE on the gimple level pinskia at gcc dot gnu.org
2021-03-05  2:08 ` unlvsur at live dot com
2021-03-05  3:12 ` pinskia at gcc dot gnu.org
2021-03-05  3:18 ` unlvsur at live dot com
2021-03-05  8:25 ` redi at gcc dot gnu.org
2021-03-05  9:36 ` jakub at gcc dot gnu.org [this message]
2021-03-05  9:44 ` jakub at gcc dot gnu.org
2021-03-05  9:50 ` jakub at gcc dot gnu.org
2021-03-05 10:38 ` jakub at gcc dot gnu.org
2021-03-05 10:47 ` redi at gcc dot gnu.org
2021-03-05 10:52 ` jakub at gcc dot gnu.org
2021-03-05 11:02 ` jakub at gcc dot gnu.org
2021-03-05 11:59 ` unlvsur at live dot com
2021-03-05 12:03 ` jakub at gcc dot gnu.org
2021-03-05 12:04 ` jakub at gcc dot gnu.org
2021-03-05 12:08 ` unlvsur at live dot com
2021-03-05 12:09 ` unlvsur at live dot com
2021-03-05 12:12 ` unlvsur at live dot com
2021-03-06 10:12 ` cvs-commit at gcc dot gnu.org
2021-03-06 10:13 ` jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-99396-4-sb0rYtyqaF@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).