[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..."
From: |
Duncan Sands |
Subject: |
Re: changing "configure" to default to "gcc -g -O2 -fwrapv ..." |
Date: |
Sun, 31 Dec 2006 17:52:25 +0100 |
User-agent: |
KMail/1.9.5 |
On Sunday 31 December 2006 16:19, Richard Kenner wrote:
> > If done in unsigned, this won't lead to any optimization, as unsigned
> > arithmetic doesn't have overflows. So, if you write "a - 10" where a
> > is unsigned, the compiler can't assume anything, whereas is a is
> > signed, the compiler can assume that a >= INT_MIN + 10, reducing
> > the range for a, and possibly allowing some optimizations.
>
> I don't follow. The purpose of this hand-optimization (whch is also done
> by GCC) is to replace two comparisons with one subtraction and one
> comparison, which is faster on most machines. It's not CORRECT to do this
> transformation in signed unless you know there won't be overflow.
>
> In general, for modern compilers it's best not to do this transformation
> AT ALL and let the compiler figure out the best way to do the range tst.
Funny you should say that, because the Ada front-end likes to do this
transformation, rather than leaving it to the back-end. For example:
procedure P (X : Natural) is
subtype Y is Natural range 10 .. 20;
begin
if X in Y then
raise Program_Error;
end if;
end;
turns into
P (x)
{
typedef p__y___XDLU_10__20 p__y___XDLU_10__20;
typedef p__y___XDLU_10__20 p__y___XDLU_10__20;
if ((unsigned int) ((integer) x - 10) <= 10)
{
__gnat_rcheck_17 ("p.adb", 5);
}
else
{
}
return;
}
The C front-end performs this transformation too. I'm not claiming that the
back-end optimizers would actually do something sensible if the front-end
didn't transform this code (in fact they don't seem too), but since the
optimal way of doing the check presumably depends on the target, wouldn't
it make sense if the backend took care of it?
Best wishes,
Duncan.
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", (continued)
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Vincent Lefevre, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Robert Dewar, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Vincent Lefevre, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Robert Dewar, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Vincent Lefevre, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gerald Pfeifer, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Robert Dewar, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Gabriel Dos Reis, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Vincent Lefevre, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...",
Duncan Sands <=
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Robert Dewar, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Vincent Lefevre, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Robert Dewar, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Vincent Lefevre, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Michael Veksler, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Richard Kenner, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Michael Veksler, 2006/12/31
- Re: changing "configure" to default to "gcc -g -O2 -fwrapv ...", Ian Lance Taylor, 2006/12/31