PATCH: PR middle-end/47383: ivopts miscompiles Pmode != ptr_mode
Richard Guenther
richard.guenther@gmail.com
Wed Feb 9 10:04:00 GMT 2011
On Wed, Feb 9, 2011 at 12:08 AM, H.J. Lu <hongjiu.lu@intel.com> wrote:
> Hi,
>
> tree-ssa-loop-ivopts.c has
>
> ---
> /* Returns variant of TYPE that can be used as base for different uses.
> We return unsigned type with the same precision, which avoids problems
> with overflows. */
>
> static tree
> generic_type_for (tree type)
> {
> if (POINTER_TYPE_P (type))
> return unsigned_type_for (type);
>
> if (TYPE_UNSIGNED (type))
> return type;
>
> return unsigned_type_for (type);
> }
> ---
>
> It converts negative step to unsigned type with the same precision.
> It doesn't work when Pmode != ptr_mode. This patch disables it.
> OK for trunk in stage 1?
This does not look correct. It rather sounds you are expanding
TARGET_MEM_REFs the wrong way - the address computed by
it is supposed to be calculated in ptr_mode and only the final
result extended to Pmode.
Richard.
> Thanks.
>
>
> H.J.
> ---
> commit 9e7f4aa92d09f7ae75086c52f0c5fa66257da4ca
> Author: H.J. Lu <hjl.tools@gmail.com>
> Date: Tue Feb 8 14:58:19 2011 -0800
>
> Disable bivs when step is negative for Pmode != ptr_mode.
>
> diff --git a/gcc/ChangeLog.x32 b/gcc/ChangeLog.x32
> index 41bfe18..e7c20bf 100644
> --- a/gcc/ChangeLog.x32
> +++ b/gcc/ChangeLog.x32
> @@ -1,3 +1,9 @@
> +2011-02-08 H.J. Lu <hongjiu.lu@intel.com>
> +
> + PR middle-end/47383
> + * tree-ssa-loop-ivopts.c (find_bivs): Disabled when step is
> + negative for Pmode != ptr_mode.
> +
> 2011-01-29 H.J. Lu <hongjiu.lu@intel.com>
>
> PR target/47537
> diff --git a/gcc/testsuite/ChangeLog.x32 b/gcc/testsuite/ChangeLog.x32
> index 8759881..f87c9f9 100644
> --- a/gcc/testsuite/ChangeLog.x32
> +++ b/gcc/testsuite/ChangeLog.x32
> @@ -1,3 +1,8 @@
> +2011-02-08 H.J. Lu <hongjiu.lu@intel.com>
> +
> + PR middle-end/47383
> + * gcc.dg/torture/pr47383.c: New.
> +
> 2011-01-27 H.J. Lu <hongjiu.lu@intel.com>
>
> PR rtl-optimization/47502
> diff --git a/gcc/testsuite/gcc.dg/torture/pr47383.c b/gcc/testsuite/gcc.dg/torture/pr47383.c
> new file mode 100644
> index 0000000..ae8d670
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/torture/pr47383.c
> @@ -0,0 +1,30 @@
> +/* { dg-do run } */
> +
> +static int heap[2*(256 +1+29)+1];
> +static int heap_len;
> +static int heap_max;
> +void
> +__attribute__ ((noinline))
> +foo (int elems)
> +{
> + int n, m;
> + int max_code = -1;
> + int node = elems;
> + heap_len = 0, heap_max = (2*(256 +1+29)+1);
> + for (n = 0; n < elems; n++)
> + heap[++heap_len] = max_code = n;
> + do {
> + n = heap[1];
> + heap[1] = heap[heap_len--];
> + m = heap[1];
> + heap[--heap_max] = n;
> + heap[--heap_max] = m;
> + } while (heap_len >= 2);
> +}
> +
> +int
> +main ()
> +{
> + foo (286);
> + return 0;
> +}
> diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
> index 479b46f..8427bb5 100644
> --- a/gcc/tree-ssa-loop-ivopts.c
> +++ b/gcc/tree-ssa-loop-ivopts.c
> @@ -1026,6 +1026,15 @@ find_bivs (struct ivopts_data *data)
> base = fold_convert (type, base);
> if (step)
> {
> + /* FIXME: add_candidate_1 calls generic_type_for to cast STEP
> + to unsigned type with the same precision when BASE isn't
> + NULL. It leads to many problems when STEP is negative and
> + Pmode != ptr_mode. Disable it for now. */
> + if (base
> + && Pmode != ptr_mode
> + && !tree_expr_nonnegative_p (step))
> + continue;
> +
> if (POINTER_TYPE_P (type))
> step = fold_convert (sizetype, step);
> else
>
More information about the Gcc-patches
mailing list