summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-18 05:22:46 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2006-02-18 05:22:46 +0000
commit819aeb26f6dcc0f1759eed90116a5f9e9e0e480d (patch)
tree4d37d7702bbfbd33a364527a6c3b6ba57cad4e0a /gcc/fold-const.c
parent003f258f2ea9f8e5ee0e750e898b317b7cad9fac (diff)
downloadgcc-819aeb26f6dcc0f1759eed90116a5f9e9e0e480d.tar.gz
PR middle-end/25600
* fold-const.c (fold_binary): Fold (X >> C) != 0 into X < 0 when C is one less than the width of X (and related transformations). * simplify_rtx.c (simplify_unary_operation_1): Transform (neg (lt x 0)) into either (ashiftrt X C) or (lshiftrt X C) depending on STORE_FLAG_VALUE, were C is one less then the width of X. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111226 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 7413883a904..c77e7ba82eb 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -10042,6 +10042,30 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
return t1;
}
+ /* Fold (X >> C) != 0 into X < 0 if C is one less than the width
+ of X. Similarly fold (X >> C) == 0 into X >= 0. */
+ if ((code == EQ_EXPR || code == NE_EXPR)
+ && integer_zerop (arg1)
+ && TREE_CODE (arg0) == RSHIFT_EXPR
+ && TREE_CODE (TREE_OPERAND (arg0, 1)) == INTEGER_CST)
+ {
+ tree arg00 = TREE_OPERAND (arg0, 0);
+ tree arg01 = TREE_OPERAND (arg0, 1);
+ tree itype = TREE_TYPE (arg00);
+ if (TREE_INT_CST_HIGH (arg01) == 0
+ && TREE_INT_CST_LOW (arg01)
+ == (unsigned HOST_WIDE_INT) (TYPE_PRECISION (itype) - 1))
+ {
+ if (TYPE_UNSIGNED (itype))
+ {
+ itype = lang_hooks.types.signed_type (itype);
+ arg00 = fold_convert (itype, arg00);
+ }
+ return fold_build2 (code == EQ_EXPR ? GE_EXPR : LT_EXPR,
+ type, arg00, build_int_cst (itype, 0));
+ }
+ }
+
if ((code == EQ_EXPR || code == NE_EXPR)
&& integer_zerop (arg1)
&& tree_expr_nonzero_p (arg0))