diff options
author | Marek Polacek <polacek@redhat.com> | 2015-06-30 16:35:16 +0000 |
---|---|---|
committer | Marek Polacek <mpolacek@gcc.gnu.org> | 2015-06-30 16:35:16 +0000 |
commit | d3bc1d1b65a18177f6baacda0251b4777a2794f4 (patch) | |
tree | 9c5d36cde1742c9db75b3a2bdbaabd50eb9dc5ff /gcc | |
parent | b451c27117636e7ca6f09fc4ac86a3623decf8fa (diff) | |
download | gcc-d3bc1d1b65a18177f6baacda0251b4777a2794f4.zip gcc-d3bc1d1b65a18177f6baacda0251b4777a2794f4.tar.gz gcc-d3bc1d1b65a18177f6baacda0251b4777a2794f4.tar.bz2 |
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/match.pd | 4 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/fold-minus-6.c | 42 |
4 files changed, 53 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8ac39dc..3dabe90 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2015-06-30 Marek Polacek <polacek@redhat.com> + + * match.pd (X - (X / Y) * Y): Use convert1 and convert2. Convert + both operands of the resulting expression. + 2015-06-30 Richard Biener <rguenther@suse.de> * fold-const.c (fold_binary_loc): Move ~x & ~y -> ~(x | y) and diff --git a/gcc/match.pd b/gcc/match.pd index 682784b..e6728f4 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 f766b0d..95a75e5 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-06-30 Marek Polacek <polacek@redhat.com> + + * 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 0000000..1c22c25 --- /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" } } */ |