public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/95534] New: Failure to optimize out atoi when used as operand of _tzcnt_u64
@ 2020-06-04 13:08 gabravier at gmail dot com
  2020-06-04 15:28 ` [Bug tree-optimization/95534] " jakub at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: gabravier at gmail dot com @ 2020-06-04 13:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95534
           Summary: Failure to optimize out atoi when used as operand of
                    _tzcnt_u64
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gabravier at gmail dot com
  Target Milestone: ---

#include <x86intrin.h>

void f(char *s)
{
    _tzcnt_u64(atol(s));
}

This can be optimized to doing nothing.

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

* [Bug tree-optimization/95534] Failure to optimize out atoi when used as operand of _tzcnt_u64
  2020-06-04 13:08 [Bug target/95534] New: Failure to optimize out atoi when used as operand of _tzcnt_u64 gabravier at gmail dot com
@ 2020-06-04 15:28 ` jakub at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-06-04 15:28 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
          Component|target                      |tree-optimization
   Last reconfirmed|                            |2020-06-04
             Status|UNCONFIRMED                 |NEW
                 CC|                            |hubicka at gcc dot gnu.org,
                   |                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
That has nothing to do with tzcnt, that one is pure and optimized as pure.
You can just try
#include <stdlib.h>
void foo (const char *x) { atol (x); }
and you'll get the same, the problem is that glibc defines extern inline
function in addition to the atol prototype, and while atol itself is marked
pure and thus can be optimized away, the inline function lowers it into strtol
call which is not pure and thus can't be optimized away.

Reduced testcase that shows this:
int qux (const char *);
int bar (const char *) __attribute__((pure));
int baz (const char *) __attribute__((pure));
extern inline __attribute__((gnu_inline, pure)) int baz (const char *x) {
return qux (x); }
void foo (const char *x) { bar (x); }
void quux (const char *x) { baz (x); }

We do optimize foo into nothing but don't optimize quux into nothing.
The reason for that is that the first pass in which we optimize away const/pure
calls without lhs is the cddce1 pass, which is after einline.
So, perhaps the einline pass should for const or pure calls it is considering
to inline and which don't have lhs used DCE them instead (at least if
flag_tree_dce)?  One could still construct a testcase like:
const char *qux (const char *);
const char *baz (const char *) __attribute__((pure));
extern inline __attribute__((gnu_inline, pure)) char *baz (const char *x) {
return qux (x); }
void
foo (const char *x)
{
  baz (baz (baz (baz (x))));
}
so either einline would handle only one level in those cases (if it processes
bbs from start to end), or we'd need to perform normal dce before einline.

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

end of thread, other threads:[~2020-06-04 15:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-04 13:08 [Bug target/95534] New: Failure to optimize out atoi when used as operand of _tzcnt_u64 gabravier at gmail dot com
2020-06-04 15:28 ` [Bug tree-optimization/95534] " 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).