summaryrefslogtreecommitdiff
path: root/gcc/simplify-rtx.c
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2004-03-11 17:45:03 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2004-03-11 17:45:03 +0000
commit239a625ee83ff08df15beab3ca2f1b37881e7f10 (patch)
tree53c0a411f358defff23d8e0c39b1dc0819424479 /gcc/simplify-rtx.c
parent4b0b51c9706b25603247ec6e48d8ac53e8db64f3 (diff)
downloadgcc-239a625ee83ff08df15beab3ca2f1b37881e7f10.tar.gz
fold-const.c (negate_expr_p): We can optimize -((int)X>>C) where C is an integer constant one bit less than...
* fold-const.c (negate_expr_p) <RSHIFT_EXPR>: 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) <RSHIFT_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. From-SVN: r79334
Diffstat (limited to 'gcc/simplify-rtx.c')
-rw-r--r--gcc/simplify-rtx.c16
1 files changed, 16 insertions, 0 deletions
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: