[Bug tree-optimization/47579] New: STL size() == 0 does unnecessary shift
ian at airs dot com
gcc-bugzilla@gcc.gnu.org
Tue Feb 1 19:52:00 GMT 2011
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.
More information about the Gcc-bugs
mailing list