From: Agner Fog <agner@agner.org>
To: Andrew Haley <aph@redhat.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Is it OK that gcc optimizes away overflow check?
Date: Wed, 27 Jul 2011 15:03:00 -0000 [thread overview]
Message-ID: <4E30289F.2050004@agner.org> (raw)
In-Reply-To: <4E2EED47.2010806@redhat.com>
On 26-07-2011 18:37, Andrew Haley wrote:
> On 07/26/2011 11:35 AM, Andrew Haley wrote:
>
>> Consider
>>
>> for (i = 0; i< limit; i++)
>> f(i * 2);
>>
>> which can be rewritten to
>>
>> int tmp = limit * 2;
>> for (i = 0; i< tmp; i += 2)
>> f(i);
>>
I tried your example. It doesn't make an induction variable because it
can do i*2 with the LEA instruction at no extra cost. With i*11 it makes
two counters:
for (i=0, k=0; i<limit; i++, k+=11) f(k);
I can't make it do what we both expect unless limit is a compile-time
constant:
for (k=0; k<limit*11; k+=11) f(k);
The reason I'm asking is that it would be interesting to know whether it
is better to use signed or unsigned integers in order to get the best
optimizations. I would publish that in my optimization manuals (
http://www.agner.org/optimize/#manuals )
Can you give any examples where optimization is better for signed
integers than for unsigned, or vice versa?
next prev parent reply other threads:[~2011-07-27 15:03 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-23 20:14 Agner Fog
2011-07-23 21:06 ` Jeffrey Walton
2011-07-25 6:07 ` Ian Lance Taylor
2011-07-25 6:04 ` Ian Lance Taylor
2011-07-25 8:32 ` Agner Fog
2011-07-25 17:18 ` me22
2011-07-25 17:50 ` Ian Lance Taylor
2011-07-26 9:39 ` Agner Fog
2011-07-26 10:35 ` Andrew Haley
2011-07-26 17:31 ` Andrew Haley
2011-07-27 15:03 ` Agner Fog [this message]
2011-07-26 14:55 ` Jeffrey Walton
[not found] ` <4E2E6CC6.3040106@agner.org>
2011-07-26 14:44 ` Ian Lance Taylor
2011-07-26 16:24 ` Agner Fog
2011-07-26 18:17 ` Ian Lance Taylor
2011-07-25 9:43 ` Andrew Haley
2011-07-25 15:38 ` Agner Fog
2011-07-25 16:22 ` Andrew Haley
2011-07-30 23:30 ` Vincent Lefevre
2011-08-01 8:59 ` Andrew Haley
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4E30289F.2050004@agner.org \
--to=agner@agner.org \
--cc=aph@redhat.com \
--cc=gcc-help@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).