This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

--- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]