public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/67014] New: builtin_tolower is inefficient.
@ 2015-07-26  4:53 neleai at seznam dot cz
  2021-06-04 21:45 ` [Bug ipa/67014] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: neleai at seznam dot cz @ 2015-07-26  4:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 67014
           Summary: builtin_tolower is inefficient.
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: neleai at seznam dot cz
  Target Milestone: ---

Hi,

When one uses __builtin_tolower it could be much slower to tolower. In this
example builtin_tolower gets just expanded to call. If one uses tolower instead 
it gets expanded to getting table with __ctype_tolower_loc and then doing 1000
table lookups instead 1000 calls.

#include <ctype.h>
int foo(char *c)
{
 int i;
 for(i=0;i<1000;i++)
   c[i]=__builtin_tolower(c[i]);
}


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

* [Bug ipa/67014] builtin_tolower is inefficient.
  2015-07-26  4:53 [Bug middle-end/67014] New: builtin_tolower is inefficient neleai at seznam dot cz
@ 2021-06-04 21:45 ` pinskia at gcc dot gnu.org
  2021-06-10 15:17 ` marxin at gcc dot gnu.org
  2021-08-18 12:40 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-06-04 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|middle-end                  |ipa
                 CC|                            |marxin at gcc dot gnu.org
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2021-06-04

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
tolower is defined in the header file as:
extern __inline __attribute__ ((__gnu_inline__)) int
__attribute__ ((__nothrow__ , __leaf__)) tolower (int __c)
{
  return __c >= -128 && __c < 256 ? (*__ctype_tolower_loc ())[__c] : __c;
}


So __builtin_tolower is not using that inline function. So this is a front-end
issue where the the two function decls are not being merged into one or is an
inliner issue.

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

* [Bug ipa/67014] builtin_tolower is inefficient.
  2015-07-26  4:53 [Bug middle-end/67014] New: builtin_tolower is inefficient neleai at seznam dot cz
  2021-06-04 21:45 ` [Bug ipa/67014] " pinskia at gcc dot gnu.org
@ 2021-06-10 15:17 ` marxin at gcc dot gnu.org
  2021-08-18 12:40 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-06-10 15:17 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

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

--- Comment #2 from Martin Liška <marxin at gcc dot gnu.org> ---
I can take a look.

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

* [Bug ipa/67014] builtin_tolower is inefficient.
  2015-07-26  4:53 [Bug middle-end/67014] New: builtin_tolower is inefficient neleai at seznam dot cz
  2021-06-04 21:45 ` [Bug ipa/67014] " pinskia at gcc dot gnu.org
  2021-06-10 15:17 ` marxin at gcc dot gnu.org
@ 2021-08-18 12:40 ` marxin at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-08-18 12:40 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW

--- Comment #3 from Martin Liška <marxin at gcc dot gnu.org> ---
So the macro definition comes from glibc:
ctype/ctype.h

# if __GNUC__ >= 2 && defined __OPTIMIZE__ && !defined __cplusplus
#  define tolower(c)    __tobody (c, tolower, *__ctype_tolower_loc (), (c))
#  define toupper(c)    __tobody (c, toupper, *__ctype_toupper_loc (), (c))
# endif /* Optimizing gcc */

That's why the GCC compiler can't map it to a builtin. On the other hand, I
don't see why would it be beneficial in this case?

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

end of thread, other threads:[~2021-08-18 12:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-26  4:53 [Bug middle-end/67014] New: builtin_tolower is inefficient neleai at seznam dot cz
2021-06-04 21:45 ` [Bug ipa/67014] " pinskia at gcc dot gnu.org
2021-06-10 15:17 ` marxin at gcc dot gnu.org
2021-08-18 12:40 ` marxin 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).