diff options
author | Jakub Jelinek <jakub@redhat.com> | 2017-07-19 15:10:05 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2017-07-19 15:10:05 +0200 |
commit | 564e405c138dc1891ca92462a585bf89444d7dd1 (patch) | |
tree | 9e875de35ac0f6800dfa505953c13e700cc8a307 /gcc | |
parent | 3717fbe35e288a02ddf97367355b15530745cecb (diff) | |
download | gcc-564e405c138dc1891ca92462a585bf89444d7dd1.zip gcc-564e405c138dc1891ca92462a585bf89444d7dd1.tar.gz gcc-564e405c138dc1891ca92462a585bf89444d7dd1.tar.bz2 |
re PR tree-optimization/81346 (Missed constant propagation into comparison)
PR tree-optimization/81346
* match.pd: Optimize (X - 1U) <= INT_MAX-1U into (int) X > 0.
* gcc.dg/tree-ssa/pr81346-5.c: New test.
From-SVN: r250342
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/match.pd | 13 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/tree-ssa/pr81346-5.c | 17 |
4 files changed, 40 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bdd1234..c87edc1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2017-07-19 Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/81346 + * match.pd: Optimize (X - 1U) <= INT_MAX-1U into (int) X > 0. + 2017-07-19 Tom de Vries <tom@codesourcery.com> * config/nvptx/nvptx.md (VECIM): Add V2DI. diff --git a/gcc/match.pd b/gcc/match.pd index fe27093..56d13b3 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -1125,6 +1125,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && wi::neg_p (@1, TYPE_SIGN (TREE_TYPE (@1)))) (cmp @2 @0)))))) +/* (X - 1U) <= INT_MAX-1U into (int) X > 0. */ +(for cmp (le gt) + icmp (gt le) + (simplify + (cmp (plus @0 integer_minus_onep@1) INTEGER_CST@2) + (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) + && TYPE_UNSIGNED (TREE_TYPE (@0)) + && TYPE_PRECISION (TREE_TYPE (@0)) > 1 + && wi::eq_p (@2, wi::max_value (TYPE_PRECISION (TREE_TYPE (@0)), + SIGNED) - 1)) + (with { tree stype = signed_type_for (TREE_TYPE (@0)); } + (icmp (convert:stype @0) { build_int_cst (stype, 0); }))))) + /* X / 4 < Y / 4 iff X < Y when the division is known to be exact. */ (for cmp (simple_comparison) (simplify diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index e0526a5c..a193548 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-07-19 Jakub Jelinek <jakub@redhat.com> + + PR tree-optimization/81346 + * gcc.dg/tree-ssa/pr81346-5.c: New test. + 2017-07-19 Tom de Vries <tom@codesourcery.com> * gcc.target/nvptx/decl-init.c: Update alignment. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr81346-5.c b/gcc/testsuite/gcc.dg/tree-ssa/pr81346-5.c new file mode 100644 index 0000000..14562a1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr81346-5.c @@ -0,0 +1,17 @@ +/* PR tree-optimization/81346 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ +/* { dg-final { scan-tree-dump-times "\\(signed int\\) x" 10 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " <= 0;" 5 "optimized" } } */ +/* { dg-final { scan-tree-dump-times " > 0;" 5 "optimized" } } */ + +int f1 (unsigned x) { return x - 1 <= __INT_MAX__ - 1; } +int f2 (unsigned x) { unsigned a = 1, b = __INT_MAX__ - 1; return x - a <= b; } +int f3 (unsigned x) { return x - 1 < __INT_MAX__; } +int f4 (unsigned x) { unsigned a = 1, b = __INT_MAX__; return x - a < b; } +int f5 (unsigned x) { return x >= 1 && x <= __INT_MAX__; } +int f6 (unsigned x) { return x - 1 > __INT_MAX__ - 1; } +int f7 (unsigned x) { unsigned a = 1, b = __INT_MAX__ - 1; return x - a > b; } +int f8 (unsigned x) { return x - 1 >= __INT_MAX__; } +int f9 (unsigned x) { unsigned a = 1, b = __INT_MAX__; return x - a >= b; } +int f10 (unsigned x) { return x < 1 || x > __INT_MAX__; } |