This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Comitted] PR middle-end/30322: Fold X + ~X to -1


The following patch resolves PR middle-end/30322 by adding a missing
transformation to fold_binary.  When we don't care about trapping overflow
X + ~X (and by symmetry ~X + X) is equivalent to -1.  Even for unsigned
types, X + ~X is ~0.  This transformation is pretty much cut and paste
from the prototypical X ^ ~X, which is what's going on when there are no
carry bits in the addition.

Tested on i686-pc-linux-gnu with a full "make bootstrap", all default
languages including Ada and regression tested with a top-level "make -k
check" with no new failures.

Committed to mainline as revision 120300.
Happy New Year!

2006-12-31  Roger Sayle  <roger@eyesopen.com>

        PR middle-end/30322
        * fold-const.c (fold_binary): Fold X + ~X and ~X + X into -1 when
        we don't care about trapping overflow.  Only convert -A - 1 into ~A
        when we don't care about trapping overflow.

        * gcc.dg/fold-plusnot-1.c: New test case.

Roger
--

Attachment: patchf.txt
Description: Text document

Attachment: fold-plusnot-1.c
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]