This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/54027] possible mis-optimization of signed left shift in c89 mode
- From: "joseph at codesourcery dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 19 Jul 2012 15:07:54 +0000
- Subject: [Bug c/54027] possible mis-optimization of signed left shift in c89 mode
- Auto-submitted: auto-generated
- References: <bug-54027-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54027
--- Comment #2 from joseph at codesourcery dot com <joseph at codesourcery dot com> 2012-07-19 15:07:54 UTC ---
On Thu, 19 Jul 2012, rguenth at gcc dot gnu.org wrote:
> Isn't it invoking undefined behavior by means of a signed integer overflow?
> (if shifts are not defined in terms of multiplies we may not internally
> fold x << 1 to x * 2).
Shifts in GCC are supposed to be defined as long as the shift amount is in
range, independent of the LHS, so it should not be folding like that.
(Although we document in implement-c.texi that this is subject to change
for signed left shift, I don't think changing it would be a particularly
good idea.)