public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Schlie <schlie@comcast.net>
To: Matthew Woodcraft <mattheww@chiark.greenend.org.uk>
Cc: <gcc@gcc.gnu.org>
Subject: Re: Where does the C standard describe overflow of signed integers?
Date: Thu, 14 Jul 2005 19:09:00 -0000	[thread overview]
Message-ID: <BEFC30AD.AD16%schlie@comcast.net> (raw)

> Matthew Woodcraft writes:
>> Paul Schlie wrote:
>>As optimization seems to be a non-argument, as by analogy all
>>optimizations which are available for unsigned arithmetic are
>>correspondingly available for signed integer operations; as any signed
>>value may then be thought of as being unsigned for the purposes of
>>computation and/or comparison.
>
> What about optimising x*2/2 to x?

Given that "C" requires the above be evaluated as (x*2)/2, as the language
specifies that the syntax defines the precedence of the operations, and that
no optimization should alter the behavior as specified by the program; I'd
say that unless it was known that the value range of x was between 0
and INT_MAX, the optimization is simply invalid.

As programmers should know and often rely on the finite range of integers to
intentionally specify algebraically inconsistent transforms; which is why
various precision integers, and in the infinite precision libraries are
available for use when such overflow ambiguities are not acceptable or
desired; the complier should simply do what is asked, not pretend it knows
better, because it doesn't.

However it seems quite reasonable and desirable for the compiler to provide
feedback to the programmer, indicating that the expression specified may be
portably algebraically simplified to "x", if the negative value overflow
behavior was not intentionally desired; thereby enabling the programmer to
improve both the portability and performance of their specified program,
rather than assuming that a value altering optimization is desirable (which
in general it never is, and typically only leads to difficult to diagnose
problems, as the program isn't actually doing an equivalent of what was
specified).


             reply	other threads:[~2005-07-14 19:09 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-14 19:09 Paul Schlie [this message]
2005-07-14 19:13 ` Robert Dewar
2005-07-14 19:28   ` Paul Schlie
2005-07-14 19:33     ` Robert Dewar
2005-07-14 20:13       ` Paul Schlie
2005-07-15 13:20         ` Georg Bauhaus
2005-07-15 13:33           ` Georg Bauhaus
2005-07-15 14:31           ` Dave Korn
2005-07-16 12:04             ` Georg Bauhaus
2005-07-16 14:26               ` Paul Schlie
2005-07-15 15:03           ` Paul Schlie
2005-07-16 12:12             ` Georg Bauhaus
2005-07-14 20:35     ` Paul Koning
2005-07-14 21:58       ` Paul Schlie
2005-07-15  7:04         ` Avi Kivity
  -- strict thread matches above, loose matches on Subject: below --
2005-07-14  1:10 Paul Schlie
2005-07-14  1:59 ` Robert Dewar
2005-07-14  5:28   ` Paul Schlie
2005-07-14 17:57 ` Matthew Woodcraft
2005-07-14 18:36   ` Paul Koning
2005-07-11 14:58 Nicholas Nethercote
2005-07-11 15:07 ` Dave Korn
2005-07-11 16:07   ` Nicholas Nethercote
2005-07-11 17:04     ` Dave Korn
2005-07-11 15:15 ` Nathan Sidwell
2005-07-11 15:23   ` Dave Korn
2005-07-12 23:13 ` Michael Meissner

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=BEFC30AD.AD16%schlie@comcast.net \
    --to=schlie@comcast.net \
    --cc=gcc@gcc.gnu.org \
    --cc=mattheww@chiark.greenend.org.uk \
    /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).