public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/47579] New: STL size() == 0 does unnecessary shift
@ 2011-02-01 19:52 ian at airs dot com
  2011-02-01 22:54 ` [Bug tree-optimization/47579] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ian at airs dot com @ 2011-02-01 19:52 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47579

           Summary: STL size() == 0 does unnecessary shift
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ian@airs.com


Consider this C++ code:

#include <vector>
extern void b1(), b2();
void foo(const std::vector<int>& v) { if (v.size() == 0) b1(); else b2(); }

When I compile it with current mainline with -O2 on x86_64, I get this:

        movq    8(%rdi), %rax
        subq    (%rdi), %rax
        sarq    $2, %rax
        testq   %rax, %rax
        ...

That sarq instruction is useless.  We know that the two values being subtracted
are both aligned pointers, so we should know that the two least significant
bits of the result are zero.  And that should be enough to let us know that we
don't need to shift before comparing for equality with zero.


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

end of thread, other threads:[~2022-11-27  6:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-01 19:52 [Bug tree-optimization/47579] New: STL size() == 0 does unnecessary shift ian at airs dot com
2011-02-01 22:54 ` [Bug tree-optimization/47579] " rguenth at gcc dot gnu.org
2012-01-06  0:33 ` pinskia at gcc dot gnu.org
2020-12-25 12:43 ` vanyacpp at gmail dot com
2022-11-27  6:32 ` pinskia 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).