From 1e3d54b4299c69b4e40205dd7d6cabc888b307c5 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Tue, 5 Jul 2016 18:17:12 +0200 Subject: [PATCH] tree-scalar-evolution.c (iv_can_overflow_p): New function. * tree-scalar-evolution.c (iv_can_overflow_p): New function. (simple_iv): Use it. * gcc.dg/tree-ssa/scev-14.c: new testcase. From-SVN: r238012 --- gcc/ChangeLog | 5 ++ gcc/testsuite/ChangeLog | 4 ++ gcc/testsuite/gcc.dg/tree-ssa/scev-14.c | 11 +++ gcc/tree-scalar-evolution.c | 89 +++++++++++++++++++++++++ 4 files changed, 109 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/scev-14.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index bc4b4db8944..c7468666273 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2016-07-05 Jan Hubicka + + * tree-scalar-evolution.c (iv_can_overflow_p): New function. + (simple_iv): Use it. + 2016-07-05 Jan Hubicka * tree-ssa-loop-niter.c (nowrap_type_p): Use ANY_INTEGRAL_TYPE_P. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f86ee90ec5e..d57f9c3eede 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2016-07-05 Jan Hubicka + + * gcc.dg/tree-ssa/scev-14.c: new testcase. + 2016-07-05 David Malcolm PR c++/62314 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/scev-14.c b/gcc/testsuite/gcc.dg/tree-ssa/scev-14.c new file mode 100644 index 00000000000..43af7d3dab4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/scev-14.c @@ -0,0 +1,11 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-ivopts-details" } */ +int a[100]; +void t(unsigned int n) +{ + unsigned int i; + for (i=0; i TYPE_PRECISION (type)) + return true; + wide_int nit2 = wide_int::from (nit, TYPE_PRECISION (type), UNSIGNED); + + /* If step can be positive, check that nit*step <= type_max-base. + This can be done by unsigned arithmetic and we only need to watch overflow + in the multiplication. The right hand side can always be represented in + the type. */ + if (sgn == UNSIGNED || !wi::neg_p (step_max)) + { + bool overflow = false; + if (wi::gtu_p (wi::mul (step_max, nit2, UNSIGNED, &overflow), + type_max - base_max) + || overflow) + return true; + } + /* If step can be negative, check that nit*(-step) <= base_min-type_min. */ + if (sgn == SIGNED && wi::neg_p (step_min)) + { + bool overflow = false, overflow2 = false; + if (wi::gtu_p (wi::mul (wi::neg (step_min, &overflow2), + nit2, UNSIGNED, &overflow), + base_min - type_min) + || overflow || overflow2) + return true; + } + + return false; +} + /* Checks whether use of OP in USE_LOOP behaves as a simple affine iv with respect to WRTO_LOOP and returns its base and step in IV if possible (see analyze_scalar_evolution_in_loop for more details on USE_LOOP @@ -3377,6 +3462,10 @@ simple_iv (struct loop *wrto_loop, struct loop *use_loop, tree op, iv->no_overflow = !folded_casts && nowrap_type_p (type); + if (!iv->no_overflow + && !iv_can_overflow_p (wrto_loop, type, iv->base, iv->step)) + iv->no_overflow = true; + /* Try to simplify iv base: (signed T) ((unsigned T)base + step) ;; TREE_TYPE (base) == signed T -- 2.30.2