From 109bd2e61facc408505321c37473c8033d7ab0c8 Mon Sep 17 00:00:00 2001 From: Bin Cheng Date: Tue, 23 Jun 2015 02:27:49 +0000 Subject: [PATCH] re PR tree-optimization/66449 (ICE: in build2_stat, at tree.c:4376 with -O3) PR tree-optimization/66449 * tree-ssa-loop-niter.c (loop_exits_before_overflow): Use POINTER_PLUS_EXPR for pointers. gcc/testsuite PR tree-optimization/66449 * gcc.dg/vect/pr66449.c: New test. From-SVN: r224769 --- gcc/ChangeLog | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/pr66449.c | 18 ++++++++++++++++++ gcc/tree-ssa-loop-niter.c | 7 ++++++- 4 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr66449.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 540685bc376..cd7074e5f15 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2015-06-23 Bin Cheng + + PR tree-optimization/66449 + * tree-ssa-loop-niter.c (loop_exits_before_overflow): Use + POINTER_PLUS_EXPR for pointers. + 2015-06-23 Alan Modra * rtlanal.c (commutative_operand_precedence): Correct comments. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fac610723d2..d5329af391c 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-06-23 Bin Cheng + + PR tree-optimization/66449 + * gcc.dg/vect/pr66449.c: New test. + 2015-06-22 Pierre-Marie de Rodat * g++.dg/other/dump-ada-spec-5.C: New test. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr66449.c b/gcc/testsuite/gcc.dg/tree-ssa/pr66449.c new file mode 100644 index 00000000000..986b3fb6b9a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr66449.c @@ -0,0 +1,18 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +void *fn1(void *p1, void *p2, long p3) +{ + long a = (long)p1, b = (long)p2, c = p3; + + while (c) + { + int d = ((int *)b)[0]; + + c--; + ((char *)a)[0] = d; + a++; + } + return 0; +} + diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 213d72e3dc4..855d32ceeb0 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -3888,7 +3888,12 @@ loop_exits_before_overflow (tree base, tree step, by proving the reverse conditions are false using loop's initial condition. */ - stepped = fold_build2 (PLUS_EXPR, TREE_TYPE (base), base, step); + if (POINTER_TYPE_P (TREE_TYPE (base))) + code = POINTER_PLUS_EXPR; + else + code = PLUS_EXPR; + + stepped = fold_build2 (code, TREE_TYPE (base), base, step); if (operand_equal_p (stepped, civ->base, 0)) { if (tree_int_cst_sign_bit (step)) -- 2.30.2