From a22fd5558187765decae31fe6fcf761c4a5468ab Mon Sep 17 00:00:00 2001 From: sayle Date: Thu, 11 Mar 2004 17:45:03 +0000 Subject: * fold-const.c (negate_expr_p) : We can optimize -((int)X>>C) where C is an integer constant one bit less than the size of X into (unsigned)X>>C. Similarly for unsigned->signed. (negate_expr) : Implement the above transformations. * simplify-rtx.c (simplify_unary_operation): Also implement the above transformations at the RTL level. * gcc.c-torture/execute/20040311-1.c: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@79334 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/simplify-rtx.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'gcc/simplify-rtx.c') diff --git a/gcc/simplify-rtx.c b/gcc/simplify-rtx.c index 3647c244077..2846bb7a80d 100644 --- a/gcc/simplify-rtx.c +++ b/gcc/simplify-rtx.c @@ -1013,6 +1013,22 @@ simplify_unary_operation (enum rtx_code code, enum machine_mode mode, XEXP (op, 1)); } + /* (neg (ashiftrt X C)) can be replaced by (lshiftrt X C) when + C is equal to the width of MODE minus 1. */ + if (GET_CODE (op) == ASHIFTRT + && GET_CODE (XEXP (op, 1)) == CONST_INT + && INTVAL (XEXP (op, 1)) == GET_MODE_BITSIZE (mode) - 1) + return simplify_gen_binary (LSHIFTRT, mode, + XEXP (op, 0), XEXP (op, 1)); + + /* (neg (lshiftrt X C)) can be replaced by (ashiftrt X C) when + C is equal to the width of MODE minus 1. */ + if (GET_CODE (op) == LSHIFTRT + && GET_CODE (XEXP (op, 1)) == CONST_INT + && INTVAL (XEXP (op, 1)) == GET_MODE_BITSIZE (mode) - 1) + return simplify_gen_binary (ASHIFTRT, mode, + XEXP (op, 0), XEXP (op, 1)); + break; case SIGN_EXTEND: -- cgit v1.2.1