public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Martin.vGagern at gmx dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/48580] missed optimization: integer overflow checks
Date: Sat, 02 Feb 2013 14:03:00 -0000	[thread overview]
Message-ID: <bug-48580-4-vz2miUBBUu@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-48580-4@http.gcc.gnu.org/bugzilla/>


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48580

Martin von Gagern <Martin.vGagern at gmx dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Martin.vGagern at gmx dot
                   |                            |net

--- Comment #15 from Martin von Gagern <Martin.vGagern at gmx dot net> 2013-02-02 14:03:12 UTC ---
(In reply to comment #7)
> […] built-in operations where you can just say "multiply two 
> (signed) values, check whether the result fits in 31-bit unsigned and set 
> an overflow flag accordingly".

Would be easier to read, easier to maintain, and less difficult to detect.
Sounds like an overall win. I'm very much in favor of builtins like these.

(In reply to comment #9)
> arith_mul_signed_check (a, b, 32, ARITH_WRAP, &overflow_p)

I'd rather make the overflow indicator the return value, and transfer the
result to a location indicated via a pointer. I.e.

overflow_p = arith_mul_signed_check (a, b, 32, ARITH_WRAP, &a_times_b)

One reason is that one usually wants to check for overflow BEFORE using the
result, i.e. the common use case would likely use the above as a condition of
some branching construct. A second reason is that this would allow for a flavor
which will not modify a_times_b in case of an overflow, which might be useful
for some scenarios, particularly if the result is stored in the same location
as one of the operands, thus overwriting the operand. So an unchecked a*=b
could be transformed into the checked construct

overflow_p = arith_mul_signed_check (a, b, 32, ARITH_CAREFUL, &a)

(In reply to comment #14)
> The trouble is that the nature of an operation is more a property of the 
> operation than of the type

I agree. The main point of all of this is optimization. And in terms of
optimization, one would want to examine some flag immediately after an
operation setting that flag. One would act upon the flag, and then discard it.
If the information were part of the type, one would require extra storage to
save those flags, which would lead to a change in the size of these types,
which in turn would severely impact many other things.


  parent reply	other threads:[~2013-02-02 14:03 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-12 18:36 [Bug rtl-optimization/48580] New: " zackw at panix dot com
2011-04-12 20:18 ` [Bug rtl-optimization/48580] " joseph at codesourcery dot com
2011-04-12 20:40 ` zackw at panix dot com
2011-04-12 20:52 ` joseph at codesourcery dot com
2011-04-12 21:03 ` zackw at panix dot com
2011-04-12 21:04 ` zackw at panix dot com
2011-04-12 21:10 ` joseph at codesourcery dot com
2011-04-12 21:16 ` joseph at codesourcery dot com
2011-04-13 12:11 ` [Bug middle-end/48580] " rguenth at gcc dot gnu.org
2011-04-13 12:46 ` joseph at codesourcery dot com
2011-04-13 17:44 ` svfuerst at gmail dot com
2011-06-20  9:47 ` jsm28 at gcc dot gnu.org
2011-10-05 12:44 ` jules at gcc dot gnu.org
2011-10-05 13:08 ` jules at gcc dot gnu.org
2011-10-05 15:20 ` joseph at codesourcery dot com
2013-02-02 14:03 ` Martin.vGagern at gmx dot net [this message]
2013-02-02 17:02 ` noloader at gmail dot com
2013-02-02 18:54 ` Martin.vGagern at gmx dot net
2013-02-02 21:59 ` zackw at panix dot com
2013-02-02 22:08 ` Martin.vGagern at gmx dot net
2013-05-19 13:04 ` glisse at gcc dot gnu.org
2014-08-24  7:06 ` Martin.vGagern at gmx dot net
2021-08-15 11:45 ` pinskia at gcc dot gnu.org
2021-08-15 11:49 ` pinskia at gcc dot gnu.org
2021-10-22 22:18 ` pinskia at gcc dot gnu.org
2023-08-09 22:29 ` pinskia at gcc dot gnu.org

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=bug-48580-4-vz2miUBBUu@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).