This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug middle-end/19912] GCC does not disclose parentheses
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 Feb 2005 21:34:45 -0000
- Subject: [Bug middle-end/19912] GCC does not disclose parentheses
- References: <20050211212331.19912.l_belev@yahoo.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From joseph at codesourcery dot com 2005-02-11 21:34 -------
Subject: Re: New: GCC does not disclose parentheses
On Fri, 11 Feb 2005, l_belev at yahoo dot com wrote:
> GCC generates different codes for the both functions:
> int f1(int k) { return k*k+k; }
> int f2(int k) { return k*(k+1); }
>
> also the generated code for, say '(k*k+k) + (k*(k+1))'
> calculates the two parts independently and then sums them,
> whereas the code for '(k*k+k) + (k*k+k)' just calculates
> k*k+k once and then doubles it.
Note that the first expression can involve undefined behavior when the
second doesn't, so transformations between these forms would be invalid
with -ftrapv and until we have internal overflow flags on expressions we
could only transform in one direction without -fwrapv.
(Consider k == -46341 with 32-bit int. The first expression involves
signed integer overflow, undefined behavior in ISO C which needs a trap
with -ftrapv, while the second doesn't.)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19912