diff options
author | Ilya Enkovich <ilya.enkovich@intel.com> | 2015-01-28 11:41:40 +0000 |
---|---|---|
committer | Ilya Enkovich <ienkovich@gcc.gnu.org> | 2015-01-28 11:41:40 +0000 |
commit | fa8e5051889f8bc0610e3400152b73755d12d04e (patch) | |
tree | e6469b694b55626902fc049cce1aff45c3c3499f | |
parent | 8447859b3ecba626580a9b812a236ecc6438d730 (diff) | |
download | gcc-fa8e5051889f8bc0610e3400152b73755d12d04e.zip gcc-fa8e5051889f8bc0610e3400152b73755d12d04e.tar.gz gcc-fa8e5051889f8bc0610e3400152b73755d12d04e.tar.bz2 |
re PR tree-optimization/64277 (Incorrect warning "array subscript is above array bounds")
gcc/
PR tree-optimization/64277
* tree-ssa-loop-niter.c (record_nonwrapping_iv): Use base
range info when possible to refine estimation.
gcc/testsuite/
PR tree-optimization/64277
* gcc.dg/pr64277.c: New.
From-SVN: r220204
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr64277.c | 23 | ||||
-rw-r--r-- | gcc/tree-ssa-loop-niter.c | 19 |
4 files changed, 51 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7141347..61b36b1 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-01-28 Ilya Enkovich <ilya.enkovich@intel.com> + + PR tree-optimization/64277 + * tree-ssa-loop-niter.c (record_nonwrapping_iv): Use base + range info when possible to refine estimation. + 2015-01-28 Thomas Preud'homme <thomas.preudhomme@arm.com> PR tree-optimization/64718 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 4f4e72c..6a6a245 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-01-28 Ilya Enkovich <ilya.enkovich@intel.com> + + PR tree-optimization/64277 + * gcc.dg/pr64277.c: New. + 2015-01-28 Thomas Preud'homme <thomas.preudhomme@arm.com> PR tree-optimization/64718 diff --git a/gcc/testsuite/gcc.dg/pr64277.c b/gcc/testsuite/gcc.dg/pr64277.c new file mode 100644 index 0000000..c6ef331 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr64277.c @@ -0,0 +1,23 @@ +/* PR tree-optimization/64277 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -Wall -Werror -fdump-tree-cunroll-details" } */ +/* { dg-final { scan-tree-dump "loop with 5 iterations completely unrolled" "cunroll" } } */ +/* { dg-final { scan-tree-dump "loop with 6 iterations completely unrolled" "cunroll" } } */ +/* { dg-final { cleanup-tree-dump "cunroll" } } */ + +int f1[10]; +void test1 (short a[], short m, unsigned short l) +{ + int i = l; + for (i = i + 5; i < m; i++) + f1[i] = a[i]++; +} + +void test2 (short a[], short m, short l) +{ + int i; + if (m > 5) + m = 5; + for (i = m; i > l; i--) + f1[i] = a[i]++; +} diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 919f5c0..a677958 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -2754,6 +2754,7 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt, { tree niter_bound, extreme, delta; tree type = TREE_TYPE (base), unsigned_type; + tree orig_base = base; if (TREE_CODE (step) != INTEGER_CST || integer_zerop (step)) return; @@ -2777,16 +2778,30 @@ record_nonwrapping_iv (struct loop *loop, tree base, tree step, gimple stmt, if (tree_int_cst_sign_bit (step)) { + wide_int min, max; extreme = fold_convert (unsigned_type, low); - if (TREE_CODE (base) != INTEGER_CST) + if (TREE_CODE (orig_base) == SSA_NAME + && TREE_CODE (high) == INTEGER_CST + && INTEGRAL_TYPE_P (TREE_TYPE (orig_base)) + && get_range_info (orig_base, &min, &max) == VR_RANGE + && wi::gts_p (high, max)) + base = wide_int_to_tree (unsigned_type, max); + else if (TREE_CODE (base) != INTEGER_CST) base = fold_convert (unsigned_type, high); delta = fold_build2 (MINUS_EXPR, unsigned_type, base, extreme); step = fold_build1 (NEGATE_EXPR, unsigned_type, step); } else { + wide_int min, max; extreme = fold_convert (unsigned_type, high); - if (TREE_CODE (base) != INTEGER_CST) + if (TREE_CODE (orig_base) == SSA_NAME + && TREE_CODE (low) == INTEGER_CST + && INTEGRAL_TYPE_P (TREE_TYPE (orig_base)) + && get_range_info (orig_base, &min, &max) == VR_RANGE + && wi::gts_p (min, low)) + base = wide_int_to_tree (unsigned_type, min); + else if (TREE_CODE (base) != INTEGER_CST) base = fold_convert (unsigned_type, low); delta = fold_build2 (MINUS_EXPR, unsigned_type, extreme, base); } |