This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: x86 gcc lacks simple optimization


On Fri, 6 Dec 2013, Konstantin Vladimirov wrote:

Consider code:

int foo(char *t, char *v, int w)
{
int i;

for (i = 1; i != w; ++i)
{
int x = i << 2;

A side note, but something too few people seem to be aware of: writing i<<2 can pessimize code compared to i*4 (and it is never faster). That is because, at a high level, signed multiplication overflow is undefined behavior while shift isn't. At a low level, gcc knows it can implement *4 as a shift anyway.

v[x + 4] = t[x + 4];
}

return 0;
}

--
Marc Glisse


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]