Hi, As reported in PR70715, GCC failed to prove no-overflows of IV(&p[n]) for simple example like: int foo (char *p, unsigned n) { while(n--) { p[n]='A'; } return 0; } Actually, code has already been added to handle this form loops when fixing PR68529. Problem with this case is loop niter analyzer records control_IV with its base expanded by calling expand_simple_operations. This patch simply adds code expanding BASE before we check its equality against control_IV.base. In the long run, we might want to remove the use of expand_simple_operations.
Bootstrap and test on x86_64. Is it OK? Thanks, bin 2016-04-20 Bin Cheng <bin.ch...@arm.com> PR tree-optimization/70715 * tree-ssa-loop-niter.c (loop_exits_before_overflow): Check equality after expanding BASE using expand_simple_operations.
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 81689fc..c61083e 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -4141,7 +4141,11 @@ loop_exits_before_overflow (tree base, tree step, continue; /* Done proving if this is a no-overflow control IV. */ - if (operand_equal_p (base, civ->base, 0)) + if (operand_equal_p (base, civ->base, 0) + /* Control IV is recorded after expanding simple operations, + Here we compare it against expanded base too. */ + || operand_equal_p (expand_simple_operations (base), + civ->base, 0)) return true; /* If this is a before stepping control IV, in other words, we have diff --git a/gcc/testsuite/gcc.dg/tree-ssa/scev-11.c b/gcc/testsuite/gcc.dg/tree-ssa/scev-11.c new file mode 100644 index 0000000..b9223c8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/scev-11.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-ldist" } */ + +int +foo (char *p, unsigned n) +{ + while(n--) + { + p[n]='A'; + } + return 0; +} + +/* Loop can be transformed into builtin memset since &p[n] is SCEV. */ +/* { dg-final { scan-tree-dump "builtin_memset" "ldist" } } */