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]

Recognize another way to express rotation


Xor can be used to encore rotations.  In fact, it may seem more
natural for a hash function, e.g.,

	i = (i << 2) ^ (i >> 30) ^ *n++;
instead of
	i = ((i << 2) | (i >> 30)) ^ *n++;


Wed Oct 13 17:27:05 CEST 1999	Marc Espie <espie@cvs.openbsd.org>
	* combine.c (simplify_logical):  recognize xor pattern that encodes
	rotation.

--- combine.c.orig	Wed Oct 13 17:24:54 1999
+++ combine.c	Wed Oct 13 17:26:27 1999
@@ -5217,6 +5217,21 @@ simplify_logical (x, last)
 	  && reversible_comparison_p (op0))
 	return gen_rtx_combine (reverse_condition (GET_CODE (op0)),
 				mode, XEXP (op0, 0), XEXP (op0, 1));
+
+      /* Convert (xor (ashift A CX) (lshiftrt A CY)) where CX+CY equals the
+	 mode size to (rotate A CX).  */
+
+      if (((GET_CODE (op0) == ASHIFT && GET_CODE (op1) == LSHIFTRT)
+	   || (GET_CODE (op1) == ASHIFT && GET_CODE (op0) == LSHIFTRT))
+	  && rtx_equal_p (XEXP (op0, 0), XEXP (op1, 0))
+	  && GET_CODE (XEXP (op0, 1)) == CONST_INT
+	  && GET_CODE (XEXP (op1, 1)) == CONST_INT
+	  && (INTVAL (XEXP (op0, 1)) + INTVAL (XEXP (op1, 1))
+	      == GET_MODE_BITSIZE (mode)))
+	return gen_rtx_ROTATE (mode, XEXP (op0, 0),
+			       (GET_CODE (op0) == ASHIFT
+				? XEXP (op0, 1) : XEXP (op1, 1)));
+
       break;
 
     default:


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