[Commited] Constant fold (x | 5) != 0
Joseph S. Myers
jsm@polyomino.org.uk
Tue Mar 23 19:50:00 GMT 2004
On Tue, 23 Mar 2004, Roger Sayle wrote:
> [1] The expression "A & B" is nonnegative, if A or B is nonnegative.
> [2] The expression "A | B" is nonnegative, if A and B are nonnegative.
> [3] The expression "A | B" is nonzero, if A is nonzero or B is nonzero.
It should be possible to write testcases for these, using the tree-level
warnings that depend on whether something is known to be nonnegative.
For example,
int
f(unsigned short a1, unsigned short a2, unsigned int b)
{
return ((a1+a2)|5) > b ? 2 : 3;
}
should no longer warn with -Wsign-compare.
--
Joseph S. Myers
jsm@polyomino.org.uk
More information about the Gcc-patches
mailing list