From 5f8d832e470c6faefcf12440e1eef1f6f9b4af28 Mon Sep 17 00:00:00 2001 From: "Naveen H.S" Date: Fri, 24 Jul 2015 04:50:41 +0000 Subject: [PATCH] re PR middle-end/25530 ((unsigned / 2)*2 is not changed into unsigned &~1) PR middle-end/25530 2015-07-24 Naveen H.S gcc/testsuite/ChangeLog: * gcc.dg/pr25530.c: New test. gcc/ChangeLog: * match.pd (mult (trunc_div @0 integer_pow2p@1) @1) : New simplifier. From-SVN: r226137 --- gcc/ChangeLog | 5 +++++ gcc/match.pd | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr25530.c | 11 +++++++++++ 4 files changed, 27 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/pr25530.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index aca1f829b76..075c0fd4d96 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-07-24 Naveen H.S + + PR middle-end/25530 + * match.pd (mult (trunc_div @0 integer_pow2p@1) @1) : New simplifier. + 2015-07-24 Naveen H.S PR middle-end/25529 diff --git a/gcc/match.pd b/gcc/match.pd index cc3089753aa..2ee36dec1ed 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -289,6 +289,12 @@ along with GCC; see the file COPYING3. If not see (type, wi::mask (TYPE_PRECISION (type) - wi::exact_log2 (@1), false, TYPE_PRECISION (type))); }))) +/* Simplify (unsigned t / 2) * 2 -> unsigned t & ~1. */ +(simplify + (mult (trunc_div @0 integer_pow2p@1) @1) + (if (TYPE_UNSIGNED (TREE_TYPE (@0))) + (bit_and @0 (negate @1)))) + /* X % Y is smaller than Y. */ (for cmp (lt ge) (simplify diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9adf8768165..7e94b2fe724 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-07-24 Naveen H.S + + PR middle-end/25530 + * gcc.dg/pr25530.c: New test. + 2015-07-24 Naveen H.S PR middle-end/25529 diff --git a/gcc/testsuite/gcc.dg/pr25530.c b/gcc/testsuite/gcc.dg/pr25530.c new file mode 100644 index 00000000000..b846ab30140 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr25530.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-require-effective-target int32 } */ + +int +f (unsigned t) +{ + return (t / 2) * 2; +} + +/* { dg-final { scan-tree-dump "\& -2" "optimized" } } */ -- 2.30.2