* [PATCH] Fix PR66423
@ 2015-06-09 12:32 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2015-06-09 12:32 UTC (permalink / raw)
To: gcc-patches
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied.
Richard.
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.
Index: gcc/match.pd
===================================================================
*** gcc/match.pd (revision 224271)
--- gcc/match.pd (working copy)
*************** (define_operator_list swapped_tcc_compar
*** 248,258 ****
(lshift INTEGER_CST@1 @2))
(for mod (trunc_mod floor_mod)
(simplify
! (mod @0 (power_of_two_cand@1 @2))
(if ((TYPE_UNSIGNED (type)
|| tree_expr_nonnegative_p (@0))
&& integer_pow2p (@2) && tree_int_cst_sgn (@2) > 0)
! (bit_and @0 (minus @1 { build_int_cst (TREE_TYPE (@1), 1); })))))
/* X % Y is smaller than Y. */
(for cmp (lt ge)
--- 248,259 ----
(lshift INTEGER_CST@1 @2))
(for mod (trunc_mod floor_mod)
(simplify
! (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 (convert (minus @1 { build_int_cst (TREE_TYPE (@1), 1); }))))))
/* X % Y is smaller than Y. */
(for cmp (lt ge)
Index: gcc/testsuite/gcc.dg/fold-modpow2.c
===================================================================
*** gcc/testsuite/gcc.dg/fold-modpow2.c (revision 0)
--- gcc/testsuite/gcc.dg/fold-modpow2.c (working copy)
***************
*** 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" } } */
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2015-06-09 12:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-09 12:32 [PATCH] Fix PR66423 Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).