Commit ece46666 by Marc Glisse Committed by Marc Glisse

match.pd: Relax some tree_nop_conversion_p

2016-05-23  Marc Glisse  <marc.glisse@inria.fr>

gcc/
	* match.pd (a * (1 << b), ~x & ~y, ~X ^ ~Y, (X ^ Y) ^ Y, ~ (-A),
	~ (A - 1), ~(~X >> Y), ~(~X >>r Y)): Relax constraints.

gcc/testsuite/
	* gcc.dg/fold-notshift-2.c: Adjust.

From-SVN: r236601
parent bb5e62d6
2016-05-23 Marc Glisse <marc.glisse@inria.fr>
* match.pd (a * (1 << b), ~x & ~y, ~X ^ ~Y, (X ^ Y) ^ Y, ~ (-A),
~ (A - 1), ~(~X >> Y), ~(~X >>r Y)): Relax constraints.
2016-05-23 Jeff Law <law@redhat.com> 2016-05-23 Jeff Law <law@redhat.com>
* tree-ssa-threadbackward.c (profitable_jump_thread_path): New function * tree-ssa-threadbackward.c (profitable_jump_thread_path): New function
......
...@@ -454,7 +454,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ...@@ -454,7 +454,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(simplify (simplify
(mult:c @0 (convert? (lshift integer_onep@1 @2))) (mult:c @0 (convert? (lshift integer_onep@1 @2)))
(if (! FLOAT_TYPE_P (type) (if (! FLOAT_TYPE_P (type)
&& tree_nop_conversion_p (type, TREE_TYPE (@1))) && (element_precision (type) <= element_precision (TREE_TYPE (@1))
|| TYPE_UNSIGNED (TREE_TYPE (@1))))
(lshift @0 @2))) (lshift @0 @2)))
/* Fold (C1/X)*C2 into (C1*C2)/X. */ /* Fold (C1/X)*C2 into (C1*C2)/X. */
...@@ -655,8 +656,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ...@@ -655,8 +656,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
rop (bit_ior bit_and) rop (bit_ior bit_and)
(simplify (simplify
(op (convert1? (bit_not @0)) (convert2? (bit_not @1))) (op (convert1? (bit_not @0)) (convert2? (bit_not @1)))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0)) (if (element_precision (type) <= element_precision (TREE_TYPE (@0))
&& tree_nop_conversion_p (type, TREE_TYPE (@1))) && element_precision (type) <= element_precision (TREE_TYPE (@1)))
(bit_not (rop (convert @0) (convert @1)))))) (bit_not (rop (convert @0) (convert @1))))))
/* If we are XORing or adding two BIT_AND_EXPR's, both of which are and'ing /* If we are XORing or adding two BIT_AND_EXPR's, both of which are and'ing
...@@ -681,8 +682,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ...@@ -681,8 +682,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* Convert ~X ^ ~Y to X ^ Y. */ /* Convert ~X ^ ~Y to X ^ Y. */
(simplify (simplify
(bit_xor (convert1? (bit_not @0)) (convert2? (bit_not @1))) (bit_xor (convert1? (bit_not @0)) (convert2? (bit_not @1)))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0)) (if (element_precision (type) <= element_precision (TREE_TYPE (@0))
&& tree_nop_conversion_p (type, TREE_TYPE (@1))) && element_precision (type) <= element_precision (TREE_TYPE (@1)))
(bit_xor (convert @0) (convert @1)))) (bit_xor (convert @0) (convert @1))))
/* Convert ~X ^ C to X ^ ~C. */ /* Convert ~X ^ C to X ^ ~C. */
...@@ -722,8 +723,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ...@@ -722,8 +723,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* (X ^ Y) ^ Y -> X */ /* (X ^ Y) ^ Y -> X */
(simplify (simplify
(bit_xor:c (convert? (bit_xor:c @0 @1)) (convert? @1)) (bit_xor:c (convert? (bit_xor:c @0 @1)) (convert? @1))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (convert @0))
(convert @0)))
/* (X & Y) & (X & Z) -> (X & Y) & Z /* (X & Y) & (X & Z) -> (X & Y) & Z
(X | Y) | (X | Z) -> (X | Y) | Z */ (X | Y) | (X | Z) -> (X | Y) | Z */
(for op (bit_and bit_ior) (for op (bit_and bit_ior)
...@@ -915,17 +915,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ...@@ -915,17 +915,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
/* Convert ~ (-A) to A - 1. */ /* Convert ~ (-A) to A - 1. */
(simplify (simplify
(bit_not (convert? (negate @0))) (bit_not (convert? (negate @0)))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (if (element_precision (type) <= element_precision (TREE_TYPE (@0))
|| !TYPE_UNSIGNED (TREE_TYPE (@0)))
(convert (minus @0 { build_each_one_cst (TREE_TYPE (@0)); })))) (convert (minus @0 { build_each_one_cst (TREE_TYPE (@0)); }))))
/* Convert ~ (A - 1) or ~ (A + -1) to -A. */ /* Convert ~ (A - 1) or ~ (A + -1) to -A. */
(simplify (simplify
(bit_not (convert? (minus @0 integer_each_onep))) (bit_not (convert? (minus @0 integer_each_onep)))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (if (element_precision (type) <= element_precision (TREE_TYPE (@0))
|| !TYPE_UNSIGNED (TREE_TYPE (@0)))
(convert (negate @0)))) (convert (negate @0))))
(simplify (simplify
(bit_not (convert? (plus @0 integer_all_onesp))) (bit_not (convert? (plus @0 integer_all_onesp)))
(if (tree_nop_conversion_p (type, TREE_TYPE (@0))) (if (element_precision (type) <= element_precision (TREE_TYPE (@0))
|| !TYPE_UNSIGNED (TREE_TYPE (@0)))
(convert (negate @0)))) (convert (negate @0))))
/* Part of convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */ /* Part of convert ~(X ^ Y) to ~X ^ Y or X ^ ~Y if ~X or ~Y simplify. */
...@@ -1505,9 +1508,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ...@@ -1505,9 +1508,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(simplify (simplify
(bit_not (convert1?:s (rshift:s (convert2?@0 (bit_not @1)) @2))) (bit_not (convert1?:s (rshift:s (convert2?@0 (bit_not @1)) @2)))
(if (!TYPE_UNSIGNED (TREE_TYPE (@0)) (if (!TYPE_UNSIGNED (TREE_TYPE (@0))
&& element_precision (TREE_TYPE (@0)) && (element_precision (TREE_TYPE (@0))
<= element_precision (TREE_TYPE (@1)) <= element_precision (TREE_TYPE (@1))
&& element_precision (type) <= element_precision (TREE_TYPE (@0))) || !TYPE_UNSIGNED (TREE_TYPE (@1))))
(with (with
{ tree shift_type = TREE_TYPE (@0); } { tree shift_type = TREE_TYPE (@0); }
(convert (rshift (convert:shift_type @1) @2))))) (convert (rshift (convert:shift_type @1) @2)))))
...@@ -1517,8 +1520,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ...@@ -1517,8 +1520,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
(for rotate (lrotate rrotate) (for rotate (lrotate rrotate)
(simplify (simplify
(bit_not (convert1?:s (rotate:s (convert2?@0 (bit_not @1)) @2))) (bit_not (convert1?:s (rotate:s (convert2?@0 (bit_not @1)) @2)))
(if (element_precision (TREE_TYPE (@0)) <= element_precision (TREE_TYPE (@1)) (if ((element_precision (TREE_TYPE (@0))
&& element_precision (type) <= element_precision (TREE_TYPE (@0))) <= element_precision (TREE_TYPE (@1))
|| !TYPE_UNSIGNED (TREE_TYPE (@1)))
&& (element_precision (type) <= element_precision (TREE_TYPE (@0))
|| !TYPE_UNSIGNED (TREE_TYPE (@0))))
(with (with
{ tree rotate_type = TREE_TYPE (@0); } { tree rotate_type = TREE_TYPE (@0); }
(convert (rotate (convert:rotate_type @1) @2)))))) (convert (rotate (convert:rotate_type @1) @2))))))
......
2016-05-23 Marc Glisse <marc.glisse@inria.fr>
* gcc.dg/fold-notshift-2.c: Adjust.
2016-05-23 Marek Polacek <polacek@redhat.com> 2016-05-23 Marek Polacek <polacek@redhat.com>
PR c/49859 PR c/49859
......
...@@ -15,17 +15,17 @@ sl (int a, int b) ...@@ -15,17 +15,17 @@ sl (int a, int b)
return ~((~a) << b); return ~((~a) << b);
} }
typedef __INT32_TYPE__ int32_t; typedef unsigned __INT32_TYPE__ uint32_t;
typedef __INT64_TYPE__ int64_t; typedef __INT64_TYPE__ int64_t;
int64_t int64_t
asr_widen1 (int32_t a, int b) asr_widen1 (uint32_t a, int b)
{ {
return ~((int64_t)(~a) >> b); return ~((int64_t)(~a) >> b);
} }
int64_t int64_t
asr_widen2 (int32_t a, int b) asr_widen2 (uint32_t a, int b)
{ {
return ~(int64_t)(~a >> b); return ~(int64_t)(~a >> b);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment