From 1a00e5f7fbcf5c79571ed1f5dcf46c30031d37d1 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Fri, 24 Oct 2008 15:57:43 +0200 Subject: [PATCH] re PR tree-optimization/36038 (miscompiled loop in perlbmk for -Os) PR tree-optimization/36038 * tree-ssa-loop-ivopts.c (add_old_iv_candidates): For pointer bases add sizetype IV with initial value zero instead of pointer type. * gcc.c-torture/compile/pr36038.c: New test. From-SVN: r141343 --- gcc/ChangeLog | 6 ++++ gcc/testsuite/ChangeLog | 5 ++++ gcc/testsuite/gcc.c-torture/compile/pr36038.c | 43 +++++++++++++++++++++++++++ gcc/tree-ssa-loop-ivopts.c | 8 +++-- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr36038.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 18b0e80..ef9bfbc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-10-24 Jakub Jelinek + + PR tree-optimization/36038 + * tree-ssa-loop-ivopts.c (add_old_iv_candidates): For pointer bases + add sizetype IV with initial value zero instead of pointer type. + 2008-10-24 Manuel López-Ibáñez PR c/7543 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index bf56e53..9f82df3 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-10-24 Jakub Jelinek + + PR tree-optimization/36038 + * gcc.c-torture/compile/pr36038.c: New test. + 2008-10-24 Manuel López-Ibáñez PR c/7543 diff --git a/gcc/testsuite/gcc.c-torture/compile/pr36038.c b/gcc/testsuite/gcc.c-torture/compile/pr36038.c new file mode 100644 index 0000000..de4bef3 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/pr36038.c @@ -0,0 +1,43 @@ +/* PR tree-optimization/36038 */ + +long long list[10]; +long long expect[10] = { 0, 1, 2, 3, 4, 4, 5, 6, 7, 9 }; +long long *stack_base; +int indices[10]; +int *markstack_ptr; + +void +doit (void) +{ + long long *src; + long long *dst; + long long *sp = stack_base + 5; + int diff = 2; + int shift; + int count; + + shift = diff - (markstack_ptr[-1] - markstack_ptr[-2]); + count = (sp - stack_base) - markstack_ptr[-1] + 2; + src = sp; + dst = (sp += shift); + while (--count) + *dst-- = *src--; +} + +int +main () +{ + int i; + for (i = 0; i < 10; i++) + list[i] = i; + + markstack_ptr = indices + 9; + markstack_ptr[-1] = 2; + markstack_ptr[-2] = 1; + + stack_base = list + 2; + doit (); + if (__builtin_memcmp (expect, list, sizeof (list))) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c index 628d426..92d9c75 100644 --- a/gcc/tree-ssa-loop-ivopts.c +++ b/gcc/tree-ssa-loop-ivopts.c @@ -2228,9 +2228,11 @@ add_old_iv_candidates (struct ivopts_data *data, struct iv *iv) add_candidate (data, iv->base, iv->step, true, NULL); /* The same, but with initial value zero. */ - add_candidate (data, - build_int_cst (TREE_TYPE (iv->base), 0), - iv->step, true, NULL); + if (POINTER_TYPE_P (TREE_TYPE (iv->base))) + add_candidate (data, size_int (0), iv->step, true, NULL); + else + add_candidate (data, build_int_cst (TREE_TYPE (iv->base), 0), + iv->step, true, NULL); phi = SSA_NAME_DEF_STMT (iv->ssa_name); if (gimple_code (phi) == GIMPLE_PHI) -- 2.7.4