[Bug c/46374] Add nooverflow attribute

2010-11-08 Thread lfsxs0 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46374

--- Comment #2 from Luís Fernando Schultz Xavier da Silveira  2010-11-08 15:48:47 UTC ---
(In reply to comment #1)
> That code is really:
> bool
> f (uint16_t x, uint16_t y)
> {
>   return ((int)x) + 8 == ((int)y) - 17;
> }

I am very sorry. I forgot the implicit conversion rules.

Please consider:

bool
f (uint16_t x, uint16_t y)
{
  x+= 8;
  y-= 17;
  return x == y;
}


[Bug c/46374] New: Add nooverflow attribute

2010-11-08 Thread lfsxs0 at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46374

   Summary: Add nooverflow attribute
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: enhancement
  Priority: P3
 Component: c
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: lfs...@gmail.com


When representing a small width unsigned integer in a larger width register,
the compiler has to clear the upper bits of the register before many
expressions, notably shift rights and comparisons. Consider the additional
instructions that have to be inserted in the following code, as opposed to a
signed version in a cpu that always passes parameters in full registers, such
as the ARM.

bool
f (uint16_t x, uint16_t y)
{
  return x + 8 == y - 17;
}

It would be helpful if the compiler provided something such as a type attribute
nooverflow that would indicate no overflow involving values of the
corresponding unsigned type may occur. This way, not only this problem is
solved, but optimizations analogous to the ones involving signed values would
apply to these unsigned ones (such as turning for (i = 1; i != 0; ++i) into an
infinite loop).

I respect you possible decision to ignore this report. This is a mere
suggestion. Also, if you consider this a bad idea, please explain why.

Thank you for your attention.