re PR tree-optimization/66423 (a % (1 << b) no longer gets folded to a & (1 << b) for unsigned a)

2015-06-09  Richard Biener  <rguenther@suse.de>

	PR middle-end/66423
	* match.pd: Handle A % (unsigned)(1 << B).

	* gcc.dg/fold-modpow2.c: New testcase.

From-SVN: r224279
This commit is contained in:
Richard Biener 2015-06-09 12:31:43 +00:00 committed by Richard Biener
parent 9aa5f7ec0c
commit 4ab1e111ef
4 changed files with 24 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2015-06-09 Richard Biener <rguenther@suse.de>
PR middle-end/66423
* match.pd: Handle A % (unsigned)(1 << B).
2015-06-09 Aldy Hernandez <aldyh@redhat.com>
* varasm.c (output_object_block_htab): Remove.

View File

@ -248,11 +248,12 @@ along with GCC; see the file COPYING3. If not see
(lshift INTEGER_CST@1 @2))
(for mod (trunc_mod floor_mod)
(simplify
(mod @0 (power_of_two_cand@1 @2))
(mod @0 (convert?@3 (power_of_two_cand@1 @2)))
(if ((TYPE_UNSIGNED (type)
|| tree_expr_nonnegative_p (@0))
&& tree_nop_conversion_p (type, TREE_TYPE (@3))
&& integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0)
(bit_and @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))))
(bit_and @0 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))))
/* X % Y is smaller than Y. */
(for cmp (lt ge)

View File

@ -1,3 +1,8 @@
2015-06-09 Richard Biener <rguenther@suse.de>
PR middle-end/66423
* gcc.dg/fold-modpow2.c: New testcase.
2015-06-09 Richard Biener <rguenther@suse.de>
PR tree-optimization/66419

View File

@ -0,0 +1,11 @@
/* { dg-do compile } */
/* { dg-options "-fdump-tree-original" } */
unsigned int
my_mod (unsigned int a, unsigned int b)
{
return a % (1 << b);
}
/* The above should be simplified to (unsigned int) ((1 << b) + -1) & a */
/* { dg-final { scan-tree-dump "& a;" "original" } } */