This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Improvements to tree_expr_nonnegative_p
- From: "Joseph S. Myers" <jsm28 at cam dot ac dot uk>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: gcc-patches at gcc dot gnu dot org, Hakan Hjort <hakan at safelogic dot se>, dberlin at dberlin dot org
- Date: Sun, 8 Jun 2003 13:59:00 +0100 (BST)
- Subject: Re: [PATCH] Improvements to tree_expr_nonnegative_p
- References: <Pine.LNX.4.44.0306071830060.4813-100000@www.eyesopen.com>
On Sat, 7 Jun 2003, Roger Sayle wrote:
> addition and multiplication. It looks like tree_expr_nonnegative_p
> was originally designed to primarily handle integer expressions, where
> the perils of overflow means that x*y may be negative even though both
> x and y are non-negative. Floating point arithmetic on the other hand
> doesn't suffer from this problem.
Unless -fwrapv, neither does integer arithmetic. That way you can fix bug
168, the oldest open non-C++ bug. I pointed this out in a message I sent
to that bug (below), but Bugzilla appears to have silently lost that
message (it didn't get to gcc-bugs, I didn't get a bounce), although
messages I sent to 2493 the previous day and 704 on the 28th are recorded
fine.
--
Joseph S. Myers
jsm28@cam.ac.uk
Date: Mon, 26 May 2003 19:38:01 +0100 (BST)
From: Joseph S. Myers <jsm28@cam.ac.uk>
To: "pinskia@physics.uc.edu" <gcc-bugzilla@gcc.gnu.org>
Subject: Re: [Bug middle-end/168] Spurious signed/unsigned comparison
warning
On Mon, 26 May 2003, pinskia@physics.uc.edu wrote:
> still happens on the mainline (20030526).
I think that this bug - the oldest open non-C++ bug - should actually be
easily fixable, and does not need value range propagation as the comments
suggest.
In order to avoid warning for the code given:
int main () {
unsigned char uc;
unsigned short int usi;
unsigned int ui;
if (uc + usi >= ui);
}
you just need to know that signed arithmetic overflow is undefined, so
either the LHS is nonnegative or undefined behavior has occurred. Thus
tree_expr_nonnegative_p needs to know that unsigned values are
nonnegative, including when converted to wider signed values, and that the
sum or product of two nonnegative values is nonnegative.
--
Joseph S. Myers
jsm28@cam.ac.uk