diff mbox

Fix ICE in scev analysis (PR tree-optimization/46985)

Message ID 20101217195024.GF2198@tyan-ft48-01.lab.bos.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Dec. 17, 2010, 7:50 p.m. UTC
Hi!

On this testcase, we have x_1 = &tar[0].i + y_2; stmt in a loop and when
trying to find out if it is constant during the loop, during scev processing
folding of &tar[0].i + a multiplication folds it into the COMPONENT_REF.  As
COMPONENT_REF has TREE_CODE_LENGTH 3, instantiate_scev_r calls
instantiate_scev_3 on it.  COMPONENT_REF has just 2 mandated arguments
though and the third one is optional (I think there is a lot of other tree
codes with similar optional arguments) and thus instantiate_scev_r that is
called on the last argument which is missing (NULL) ICEs.

Fixed by passing through NULL_TREE, which means it handles all optional
arguments nicely.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2010-12-17  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/46985
	* tree-scalar-evolution.c (instantiate_scev_r): If chrec is NULL,
	return it immediately.

	* gfortran.dg/pr46985.f90: New test.


	Jakub

Comments

Sebastian Pop Dec. 17, 2010, 8:02 p.m. UTC | #1
On Fri, Dec 17, 2010 at 13:50, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> On this testcase, we have x_1 = &tar[0].i + y_2; stmt in a loop and when
> trying to find out if it is constant during the loop, during scev processing
> folding of &tar[0].i + a multiplication folds it into the COMPONENT_REF.  As
> COMPONENT_REF has TREE_CODE_LENGTH 3, instantiate_scev_r calls
> instantiate_scev_3 on it.  COMPONENT_REF has just 2 mandated arguments
> though and the third one is optional (I think there is a lot of other tree
> codes with similar optional arguments) and thus instantiate_scev_r that is
> called on the last argument which is missing (NULL) ICEs.
>
> Fixed by passing through NULL_TREE, which means it handles all optional
> arguments nicely.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2010-12-17  Jakub Jelinek  <jakub@redhat.com>
>
>        PR tree-optimization/46985
>        * tree-scalar-evolution.c (instantiate_scev_r): If chrec is NULL,
>        return it immediately.
>
>        * gfortran.dg/pr46985.f90: New test.
>

Looks good to me, please apply to trunk.
Thanks for the fix.

Sebastian

> --- gcc/tree-scalar-evolution.c.jj      2010-12-06 08:08:55.000000000 +0100
> +++ gcc/tree-scalar-evolution.c 2010-12-17 13:30:27.000000000 +0100
> @@ -2616,7 +2616,8 @@ instantiate_scev_r (basic_block instanti
>   if (size_expr++ > PARAM_VALUE (PARAM_SCEV_MAX_EXPR_SIZE))
>     return chrec_dont_know;
>
> -  if (automatically_generated_chrec_p (chrec)
> +  if (chrec == NULL_TREE
> +      || automatically_generated_chrec_p (chrec)
>       || is_gimple_min_invariant (chrec))
>     return chrec;
>
> --- gcc/testsuite/gfortran.dg/pr46985.f90.jj    2010-12-17 13:56:03.000000000 +0100
> +++ gcc/testsuite/gfortran.dg/pr46985.f90       2010-12-17 13:53:59.000000000 +0100
> @@ -0,0 +1,17 @@
> +! PR tree-optimization/46985
> +! { dg-do compile }
> +! { dg-options "-O -ftree-pre -ftree-vrp -fno-tree-ccp -fno-tree-dominator-opts -fno-tree-fre" }
> +
> +  type :: t
> +    integer :: i
> +  end type t
> +  type(t), target :: tar(2) = (/t(2), t(4)/)
> +  integer, pointer :: ptr(:)
> +  ptr => tar%i
> +  call foo (ptr)
> +contains
> +  subroutine foo (arg)
> +    integer :: arg(:)
> +    arg = arg - 1
> +  end subroutine
> +end
>
>        Jakub
>
diff mbox

Patch

--- gcc/tree-scalar-evolution.c.jj	2010-12-06 08:08:55.000000000 +0100
+++ gcc/tree-scalar-evolution.c	2010-12-17 13:30:27.000000000 +0100
@@ -2616,7 +2616,8 @@  instantiate_scev_r (basic_block instanti
   if (size_expr++ > PARAM_VALUE (PARAM_SCEV_MAX_EXPR_SIZE))
     return chrec_dont_know;
 
-  if (automatically_generated_chrec_p (chrec)
+  if (chrec == NULL_TREE
+      || automatically_generated_chrec_p (chrec)
       || is_gimple_min_invariant (chrec))
     return chrec;
 
--- gcc/testsuite/gfortran.dg/pr46985.f90.jj	2010-12-17 13:56:03.000000000 +0100
+++ gcc/testsuite/gfortran.dg/pr46985.f90	2010-12-17 13:53:59.000000000 +0100
@@ -0,0 +1,17 @@ 
+! PR tree-optimization/46985
+! { dg-do compile }
+! { dg-options "-O -ftree-pre -ftree-vrp -fno-tree-ccp -fno-tree-dominator-opts -fno-tree-fre" }
+
+  type :: t
+    integer :: i
+  end type t
+  type(t), target :: tar(2) = (/t(2), t(4)/)
+  integer, pointer :: ptr(:)
+  ptr => tar%i
+  call foo (ptr)
+contains
+  subroutine foo (arg)
+    integer :: arg(:)
+    arg = arg - 1
+  end subroutine
+end