This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [patch] fold-const.c: Fold (A & ~3) - (A & 3) into (A ^ 3) - 3.
- From: Segher Boessenkool <segher at d12relay02 dot megacenter dot de dot ibm dot com>
- To: Kazu Hirata <kazu at cs dot umass dot edu>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Tue, 30 Sep 2003 13:44:19 +0200 (CEST)
- Subject: Re: [patch] fold-const.c: Fold (A & ~3) - (A & 3) into (A ^ 3) - 3.
> Attached is a patch to fold (A & ~B) - (A & B) into (A ^ B) - B, where
> B is any power of 2 minus 1.
This actually works for any B:
(A & ~B) - (A & B) = (A & ~B) + ~(A & B) + 1
= (A & ~B) + (~A & B) + ~B + 1
= (A & ~B) + (~A & B) - B
= (A ^ B) - B.
Segher