diff options
author | Alexander Monakov <amonakov@ispras.ru> | 2016-05-30 17:37:02 +0300 |
---|---|---|
committer | Alexander Monakov <amonakov@gcc.gnu.org> | 2016-05-30 17:37:02 +0300 |
commit | 0557293fc21c8c9ba94acb48e4373f974bf09d2e (patch) | |
tree | 09ffb39fe015722f03d20261e2515223b6538e85 /gcc | |
parent | e5b1fae41b02c97227598559e6d3601a109d9e49 (diff) | |
download | gcc-0557293fc21c8c9ba94acb48e4373f974bf09d2e.zip gcc-0557293fc21c8c9ba94acb48e4373f974bf09d2e.tar.gz gcc-0557293fc21c8c9ba94acb48e4373f974bf09d2e.tar.bz2 |
match.pd: optimize unsigned mul overflow check
gcc/
2016-05-28 Alexander Monakov <amonakov@ispras.ru>
Marc Glisse <marc.glisse@inria.fr>
PR tree-optimization/71289
* match.pd (-1 / B < A, A > -1 / B): New transformations.
gcc/testsuite/
2016-05-28 Alexander Monakov <amonakov@ispras.ru>
PR tree-optimization/71289
* gcc.dg/pr71289.c: New test.
Co-Authored-By: Marc Glisse <marc.glisse@inria.fr>
From-SVN: r236882
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/match.pd | 19 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr71289.c | 18 |
4 files changed, 48 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index df40818..80e53ba 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-05-30 Alexander Monakov <amonakov@ispras.ru> + Marc Glisse <marc.glisse@inria.fr> + + PR tree-optimization/71289 + * match.pd (-1 / B < A, A > -1 / B): New transformations. + 2016-05-30 Jan Hubicka <hubicka@ucw.cz> * tree-vect-loop.c (vect_transform_loop): Update likely bounds. diff --git a/gcc/match.pd b/gcc/match.pd index 8d05e86..953c070 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -2657,6 +2657,25 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && types_match (TREE_TYPE (@0), TREE_TYPE (@1))) (out (imagpart @2) { build_zero_cst (TREE_TYPE (@0)); })))) +/* For unsigned operands, A > -1 / B checks whether A * B would overflow. + Simplify it to __builtin_mul_overflow (A, B, <unused>). */ +/* -1 / B < A */ +(for cmp (lt ge) + out (ne eq) + (simplify + (cmp (trunc_div:s integer_all_onesp @1) @0) + (if (TYPE_UNSIGNED (TREE_TYPE (@0)) && !VECTOR_TYPE_P (TREE_TYPE (@0))) + (with { tree t = TREE_TYPE (@0), cpx = build_complex_type (t); } + (out (imagpart (IFN_MUL_OVERFLOW:cpx @0 @1)) { build_zero_cst (t); }))))) + +/* A > -1 / B */ +(for cmp (gt le) + out (ne eq) + (simplify + (cmp @0 (trunc_div:s integer_all_onesp @1)) + (if (TYPE_UNSIGNED (TREE_TYPE (@0)) && !VECTOR_TYPE_P (TREE_TYPE (@0))) + (with { tree t = TREE_TYPE (@0), cpx = build_complex_type (t); } + (out (imagpart (IFN_MUL_OVERFLOW:cpx @0 @1)) { build_zero_cst (t); }))))) /* Simplification of math builtins. These rules must all be optimizations as well as IL simplifications. If there is a possibility that the new diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 9d233f1..ae0a669 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-30 Alexander Monakov <amonakov@ispras.ru> + + PR tree-optimization/71289 + * gcc.dg/pr71289.c: New test. + 2016-05-30 Kugan Vivekanandarajah <kuganv@linaro.org> PR middle-end/71269 diff --git a/gcc/testsuite/gcc.dg/pr71289.c b/gcc/testsuite/gcc.dg/pr71289.c new file mode 100644 index 0000000..39837b9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr71289.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-optimized-raw" } */ + +int f(unsigned a, unsigned b, unsigned *c) +{ + if (a > -1 / b) + return -1; + *c = a * b; + return 0; +} + +void g(unsigned long long a, unsigned long long b, unsigned long long *c) +{ + if (a <= -1 / b) + *c = a * b; +} + +/* { dg-final { scan-tree-dump-not "trunc_div_expr" "optimized" } } */ |