Commit 9ebc3467 by Yury Gribov Committed by Maxim Ostapenko

match.pd: New pattern.

2017-06-13  Yury Gribov  <tetra2005@gmail.com>

gcc/
	* match.pd: New pattern.

gcc/testsuite/
	* c-c++-common/fold-masked-cmp-3.c: New test.

From-SVN: r249151
parent df067572
2017-06-13 Yury Gribov <tetra2005@gmail.com>
* match.pd: New pattern.
2017-06-13 Yury Gribov <tetra2005@gmail.com>
* tree-vrp.c (is_masked_range_test): New function.
(register_edge_assert_for): Determine ranges for
some bit tests.
......
......@@ -2741,6 +2741,34 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
|| VECTOR_INTEGER_TYPE_P (TREE_TYPE (@0)))
{ constant_boolean_node (false, type); })))
/* A & (2**N - 1) <= 2**K - 1 -> A & (2**N - 2**K) == 0
A & (2**N - 1) > 2**K - 1 -> A & (2**N - 2**K) != 0
Note that comparisons
A & (2**N - 1) < 2**K -> A & (2**N - 2**K) == 0
A & (2**N - 1) >= 2**K -> A & (2**N - 2**K) != 0
will be canonicalized to above so there's no need to
consider them here.
*/
(for cmp (le gt)
eqcmp (eq ne)
(simplify
(cmp (bit_and@0 @1 INTEGER_CST@2) INTEGER_CST@3)
(if (INTEGRAL_TYPE_P (TREE_TYPE (@0)))
(with
{
tree ty = TREE_TYPE (@0);
unsigned prec = TYPE_PRECISION (ty);
wide_int mask = wi::to_wide (@2, prec);
wide_int rhs = wi::to_wide (@3, prec);
signop sgn = TYPE_SIGN (ty);
}
(if ((mask & (mask + 1)) == 0 && wi::gt_p (rhs, 0, sgn)
&& (rhs & (rhs + 1)) == 0 && wi::ge_p (mask, rhs, sgn))
(eqcmp (bit_and @1 { wide_int_to_tree (ty, mask - rhs); })
{ build_zero_cst (ty); }))))))
/* -A CMP -B -> B CMP A. */
(for cmp (tcc_comparison)
scmp (swapped_tcc_comparison)
......
2017-06-12 Yury Gribov <tetra2005@gmail.com>
* c-c++-common/fold-masked-cmp-3.c: New test.
2017-06-13 Yury Gribov <tetra2005@gmail.com>
PR tree-optimization/67328
......
/* { dg-do compile { target x86_64-*-* } } */
/* { dg-options "-fdump-tree-original" } */
void foo (int *p, int x)
{
if ((x & 0xff) <= 7)
*p = 0;
}
void bar (int *p, int x)
{
if ((x & 0xff) < 8)
*p = 0;
}
/* { dg-final { scan-tree-dump-times "(x & .*) == 0" 2 "original" } } */
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