This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
simplify some (and (plus x y) c)
- From: Richard Henderson <rth at twiddle dot net>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 11 Dec 2001 21:53:38 -0800
- Subject: simplify some (and (plus x y) c)
I noticed one case in which gcc could simplify loading
of a short on alpha ev4:
-: lda t0,65(sp)
-: extqh a1,t0,a1
+: sll a1,0x38,a1
: sra a1,0x38,a1
Unexpectedly this also turned up simplifications in cse.c:
#define HASH(X, M) \
((GET_CODE (X) == REG && REGNO (X) >= FIRST_PSEUDO_REGISTER \
? (((unsigned) REG << 7) + (unsigned) REG_QTY (REGNO (X))) \
: canon_hash (X, M)) & HASH_MASK)
Note that HASH_MASK is 0x1f, so (REG << 7) & 0x1f is obviously 0.
Bootstrapped on alphaev4-linux.
r~
* combine.c (simplify_and_const_int): Simplify (AND (PLUS X Y) C)
if C has only low bits set and doesn't intersect with X or Y.
Index: combine.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/combine.c,v
retrieving revision 1.243
diff -c -p -d -r1.243 combine.c
*** combine.c 2001/12/12 02:42:41 1.243
--- combine.c 2001/12/12 05:43:26
*************** simplify_and_const_int (x, mode, varop,
*** 7789,7794 ****
--- 7789,7811 ----
simplify_and_const_int (NULL_RTX, GET_MODE (varop),
XEXP (varop, 1), constop))));
+ /* If VAROP is PLUS, and the constant is a mask of low bite, distribute
+ the AND and see if one of the operands simplifies to zero. If so, we
+ may eliminate it. */
+
+ if (GET_CODE (varop) == PLUS
+ && exact_log2 (constop + 1) >= 0)
+ {
+ rtx o0, o1;
+
+ o0 = simplify_and_const_int (NULL_RTX, mode, XEXP (varop, 0), constop);
+ o1 = simplify_and_const_int (NULL_RTX, mode, XEXP (varop, 1), constop);
+ if (o0 == const0_rtx)
+ return o1;
+ if (o1 == const0_rtx)
+ return o0;
+ }
+
/* Get VAROP in MODE. Try to get a SUBREG if not. Don't make a new SUBREG
if we already had one (just check for the simplest cases). */
if (x && GET_CODE (XEXP (x, 0)) == SUBREG