From b09bae6856c0869e7e763e5a13154210bb5f54bc Mon Sep 17 00:00:00 2001 From: Richard Guenther Date: Tue, 16 Feb 2010 16:11:28 +0000 Subject: [PATCH] re PR middle-end/41043 (virtual memory exhausted: Cannot allocate memory) 2010-02-16 Richard Guenther PR tree-optimization/41043 * tree-vrp.c (vrp_var_may_overflow): Only ask SCEV for real loops. (vrp_visit_assignment_or_call): Do not ask SCEV for regular statements ... (vrp_visit_phi_node): ... but only for loop PHI nodes. * gfortran.dg/pr41043.f90: New testcase. * gcc.dg/Wstrict-overflow-18.c: XFAIL. From-SVN: r156808 --- gcc/ChangeLog | 9 +++++++++ gcc/testsuite/ChangeLog | 6 ++++++ gcc/testsuite/gcc.dg/Wstrict-overflow-18.c | 7 +++++-- gcc/tree-vrp.c | 19 +++++++++++-------- 4 files changed, 31 insertions(+), 10 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 4495a3109973..eaa030f49eba 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2010-02-16 Richard Guenther + + PR tree-optimization/41043 + * tree-vrp.c (vrp_var_may_overflow): Only ask SCEV for + real loops. + (vrp_visit_assignment_or_call): Do not ask SCEV for regular + statements ... + (vrp_visit_phi_node): ... but only for loop PHI nodes. + 2010-02-16 Ira Rosen PR tree-optimization/43074 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fa0ac072019d..c70a97982486 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2010-02-16 Richard Guenther + + PR tree-optimization/41043 + * gfortran.dg/pr41043.f90: New testcase. + * gcc.dg/Wstrict-overflow-18.c: XFAIL. + 2010-02-16 Jason Merrill * g++.dg/cpp0x/initlist-opt.C: Declare max_val inline. diff --git a/gcc/testsuite/gcc.dg/Wstrict-overflow-18.c b/gcc/testsuite/gcc.dg/Wstrict-overflow-18.c index e26e7e914e5e..2767c44fbf24 100644 --- a/gcc/testsuite/gcc.dg/Wstrict-overflow-18.c +++ b/gcc/testsuite/gcc.dg/Wstrict-overflow-18.c @@ -2,7 +2,10 @@ /* { dg-options "-fstrict-overflow -O2 -Wstrict-overflow" } */ /* Don't warn about an overflow when folding i > 0. The loop analysis - should determine that i does not wrap. */ + should determine that i does not wrap. + + The test is really bogus, p->a - p->b can be larger than INT_MAX + and thus i can very well wrap. */ struct c { unsigned int a; unsigned int b; }; extern void bar (struct c *); @@ -14,7 +17,7 @@ foo (struct c *p) for (i = 0; i < p->a - p->b; ++i) { - if (i > 0) + if (i > 0) /* { dg-bogus "warning" "" { xfail *-*-* } } */ sum += 2; bar (p); } diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c index 81645485f8b2..2f0f05965c1b 100644 --- a/gcc/tree-vrp.c +++ b/gcc/tree-vrp.c @@ -3280,7 +3280,8 @@ vrp_var_may_overflow (tree var, gimple stmt) return true; l = loop_containing_stmt (stmt); - if (l == NULL) + if (l == NULL + || !loop_outer (l)) return true; chrec = instantiate_parameters (l, analyze_scalar_evolution (l, var)); @@ -5342,7 +5343,6 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p) && TYPE_MAX_VALUE (TREE_TYPE (lhs))) || POINTER_TYPE_P (TREE_TYPE (lhs)))) { - struct loop *l; value_range_t new_vr = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }; if (code == GIMPLE_CALL) @@ -5350,12 +5350,6 @@ vrp_visit_assignment_or_call (gimple stmt, tree *output_p) else extract_range_from_assignment (&new_vr, stmt); - /* If STMT is inside a loop, we may be able to know something - else about the range of LHS by examining scalar evolution - information. */ - if (current_loops && (l = loop_containing_stmt (stmt))) - adjust_range_with_scev (&new_vr, l, stmt, lhs); - if (update_value_range (lhs, &new_vr)) { *output_p = lhs; @@ -6259,6 +6253,7 @@ vrp_visit_phi_node (gimple phi) value_range_t *lhs_vr = get_value_range (lhs); value_range_t vr_result = { VR_UNDEFINED, NULL_TREE, NULL_TREE, NULL }; int edges, old_edges; + struct loop *l; copy_value_range (&vr_result, lhs_vr); @@ -6322,6 +6317,14 @@ vrp_visit_phi_node (gimple phi) } } + /* If this is a loop PHI node SCEV may known more about its + value-range. + ??? Identify loop PHI nodes properly. */ + if (current_loops + && (l = loop_containing_stmt (phi)) + && loop_outer (l)) + adjust_range_with_scev (&vr_result, l, phi, lhs); + if (vr_result.type == VR_VARYING) goto varying; -- 2.43.5