From d3bc1d1b65a18177f6baacda0251b4777a2794f4 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 30 Jun 2015 16:35:16 +0000 Subject: [PATCH] match.pd (X - (X / Y) * Y): Use convert1 and convert2. * match.pd (X - (X / Y) * Y): Use convert1 and convert2. Convert both operands of the resulting expression. * gcc.dg/fold-minus-6.c: New test. From-SVN: r225195 --- gcc/ChangeLog | 5 ++++ gcc/match.pd | 4 +-- gcc/testsuite/ChangeLog | 4 +++ gcc/testsuite/gcc.dg/fold-minus-6.c | 42 +++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/fold-minus-6.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8ac39dc1930..3dabe907a44 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-06-30 Marek Polacek + + * match.pd (X - (X / Y) * Y): Use convert1 and convert2. Convert + both operands of the resulting expression. + 2015-06-30 Richard Biener * fold-const.c (fold_binary_loc): Move ~x & ~y -> ~(x | y) and diff --git a/gcc/match.pd b/gcc/match.pd index 682784b094b..e6728f47096 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -240,9 +240,9 @@ along with GCC; see the file COPYING3. If not see /* X - (X / Y) * Y is the same as X % Y. */ (simplify - (minus (convert? @0) (convert? (mult (trunc_div @0 @1) @1))) + (minus (convert1? @0) (convert2? (mult (trunc_div @0 @1) @1))) (if (INTEGRAL_TYPE_P (type) || VECTOR_INTEGER_TYPE_P (type)) - (convert (trunc_mod @0 @1)))) + (trunc_mod (convert @0) (convert @1)))) /* Optimize TRUNC_MOD_EXPR by a power of two into a BIT_AND_EXPR, i.e. "X % C" into "X & (C - 1)", if X and C are positive. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f766b0dcbb6..95a75e569ea 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-06-30 Marek Polacek + + * gcc.dg/fold-minus-6.c: New test. + 2015-06-30 Edward Smith-Rowland <3dw4rd@verizon.net> Implement N4197 - Adding u8 character literals diff --git a/gcc/testsuite/gcc.dg/fold-minus-6.c b/gcc/testsuite/gcc.dg/fold-minus-6.c new file mode 100644 index 00000000000..1c22c252f72 --- /dev/null +++ b/gcc/testsuite/gcc.dg/fold-minus-6.c @@ -0,0 +1,42 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-cddce1" } */ + +int +fn1 (int x) +{ + return 42L - (42 / x) * x; +} + +long +fn2 (int x) +{ + return 42L - (42 / x) * x; +} + +int +fn3 (long int x) +{ + return 42L - (42 / x) * x; +} + +int +fn4 (int a, int b) +{ + return a - (unsigned) ((a / b) * b); +} + +int +fn5 (int a, unsigned int b) +{ + return a - ((a / b) * b); +} + +unsigned int +fn6 (int a, int b) +{ + return a - ((a / b) * b); +} + +/* { dg-final { scan-tree-dump-not " / " "cddce1" } } */ +/* { dg-final { scan-tree-dump-not " - " "cddce1" } } */ +/* { dg-final { scan-tree-dump-not " \\+ " "cddce1" } } */ -- 2.30.2