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]

Re: [patch] fold-const.c: Fold (A & ~3) - (A & 3) into (A ^ 3) - 3.


    Here is a quick proof:

    (A & ~3) - (A & 3) = (A & ~3) + ~(A & 3) + 1

This is not a "proof", but an *example*.  However, I worked out an
informal-enough proof on paper to be convinced that it's actually correct.

+	  /* Fold (A & ~3) - (A & 3) into (A ^ 3) - 3.  */

This should say "B" not "3" and then say that it's a power of two minus 1.

+	      && !TREE_SIDE_EFFECTS (TREE_OPERAND (arg0, 0))
+	      && operand_equal_p (TREE_OPERAND (arg0, 0),
+				  TREE_OPERAND (arg1, 0), 0)

operand_equal_p can't be true if there are side-effects, so that test
is redundant.

Otherwise OK.


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