Commit 4349b15f by Sudakshina Das Committed by Wilco Dijkstra

PR80131: Simplification of 1U << (31 - x)

Currently the code A << (B - C) is not simplified.
However at least a more specific case of 1U << (C -x) where
C = precision(type) - 1 can be simplified to (1 << C) >> x.

This is done by adding a new simplification rule in match.pd.

2017-11-07  Sudakshina Das  <sudi.das@arm.com>

    gcc/
	PR middle-end/80131
	* match.pd: Simplify 1 << (C - x) where C = precision (x) - 1.

    testsuite/
	PR middle-end/80131
	* testsuite/gcc.dg/pr80131-1.c: New Test.

From-SVN: r254496
parent e268a77b
2017-11-07 Sudakshina Das <sudi.das@arm.com>
PR middle-end/80131
* match.pd: Simplify 1 << (C - x) where C = precision (x) - 1.
2017-11-07 Marc Glisse <marc.glisse@inria.fr>
* match.pd ((a&~b)|(a^b),(a&~b)^~a,(a|b)&~(a^b),a|~(a^b),
......@@ -605,6 +605,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
&& tree_nop_conversion_p (type, TREE_TYPE (@1)))
(lshift @0 @2)))
/* Fold (1 << (C - x)) where C = precision(type) - 1
into ((1 << C) >> x). */
(simplify
(lshift integer_onep@0 (minus@1 INTEGER_CST@2 @3))
(if (INTEGRAL_TYPE_P (type)
&& wi::eq_p (@2, TYPE_PRECISION (type) - 1)
&& single_use (@1))
(if (TYPE_UNSIGNED (type))
(rshift (lshift @0 @2) @3)
(with
{ tree utype = unsigned_type_for (type); }
(convert (rshift (lshift (convert:utype @0) @2) @3))))))
/* Fold (C1/X)*C2 into (C1*C2)/X. */
(simplify
(mult (rdiv@3 REAL_CST@0 @1) REAL_CST@2)
......
2017-11-07 Sudakshina Das <sudi.das@arm.com>
PR middle-end/80131
* testsuite/gcc.dg/pr80131-1.c: New Test.
2017-11-07 Marc Glisse <marc.glisse@inria.fr>
* gcc.dg/tree-ssa/bitops-1.c: New file.
......
/* { dg-do compile } */
/* { dg-require-effective-target int32plus } */
/* { dg-options "-fdump-tree-gimple" } */
/* Checks the simplification of:
1 << (C - x) to (1 << C) >> x, where C = precision (type) - 1
f1 is not simplified but f2, f3 and f4 are. */
__INT64_TYPE__ f1 (__INT64_TYPE__ i)
{
return (__INT64_TYPE__)1 << (31 - i);
}
__INT64_TYPE__ f2 (__INT64_TYPE__ i)
{
return (__INT64_TYPE__)1 << (63 - i);
}
__UINT64_TYPE__ f3 (__INT64_TYPE__ i)
{
return (__UINT64_TYPE__)1 << (63 - i);
}
__INT32_TYPE__ f4 (__INT32_TYPE__ i)
{
return (__INT32_TYPE__)1 << (31 - i);
}
/* { dg-final { scan-tree-dump-times "= 31 -" 1 "gimple" } } */
/* { dg-final { scan-tree-dump-times "9223372036854775808 >>" 2 "gimple" } } */
/* { dg-final { scan-tree-dump "2147483648 >>" "gimple" } } */
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