diff options
author | James A. Morrison <phython@gcc.gnu.org> | 2005-06-13 00:18:41 +0000 |
---|---|---|
committer | James A. Morrison <phython@gcc.gnu.org> | 2005-06-13 00:18:41 +0000 |
commit | a165e746471b32ea442c325732f5c2907034db45 (patch) | |
tree | 0e491ce1198062f770844aa5c3a1dadc4b298c0c /gcc/fold-const.c | |
parent | 61e58d36f29d9c190c6e520a47f45e83582d9b74 (diff) | |
download | gcc-a165e746471b32ea442c325732f5c2907034db45.zip gcc-a165e746471b32ea442c325732f5c2907034db45.tar.gz gcc-a165e746471b32ea442c325732f5c2907034db45.tar.bz2 |
re PR tree-optimization/14796 ([tree-ssa] combine two shifts into one)
2005-06-12 James A. Morrison <phython@gcc.gnu.org>
PR tree-optimization/14796
* fold-const (fold_binary): Transform (X << C) >> C into X & (-1>>C)
for unsigned types.
From-SVN: r100869
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 1994410..af3f01c 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8768,8 +8768,11 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) build_int_cst (type, low)); } - /* Transform (x >> c) << c into x & (-1<<c) */ - if (code == LSHIFT_EXPR && TREE_CODE (arg0) == RSHIFT_EXPR + /* Transform (x >> c) << c into x & (-1<<c), or transform (x << c) >> c + into x & ((unsigned)-1 >> c) for unsigned types. */ + if (((code == LSHIFT_EXPR && TREE_CODE (arg0) == RSHIFT_EXPR) + || (TYPE_UNSIGNED (type) + && code == RSHIFT_EXPR && TREE_CODE (arg0) == LSHIFT_EXPR)) && host_integerp (arg1, false) && TREE_INT_CST_LOW (arg1) < TYPE_PRECISION (type) && host_integerp (TREE_OPERAND (arg0, 1), false) @@ -8777,8 +8780,6 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) { HOST_WIDE_INT low0 = TREE_INT_CST_LOW (TREE_OPERAND (arg0, 1)); HOST_WIDE_INT low1 = TREE_INT_CST_LOW (arg1); - unsigned HOST_WIDE_INT low; - HOST_WIDE_INT high; tree lshift; tree arg00; @@ -8786,15 +8787,13 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1) { arg00 = fold_convert (type, TREE_OPERAND (arg0, 0)); - lshift_double (-1, -1, low0 < low1 ? low0 : low1, - TYPE_PRECISION (type), &low, &high, 1); - lshift = build_int_cst_wide (type, low, high); + lshift = build_int_cst (type, -1); + lshift = int_const_binop (code, lshift, arg1, 0); return fold_build2 (BIT_AND_EXPR, type, arg00, lshift); } } - /* Rewrite an LROTATE_EXPR by a constant into an RROTATE_EXPR by a new constant. */ if (code == LROTATE_EXPR && TREE_CODE (arg1) == INTEGER_CST) |