Bug 30771 - [4.3 Regression] ice for legal code with -O2 -ftree-vectorize
Summary: [4.3 Regression] ice for legal code with -O2 -ftree-vectorize
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-12 08:52 UTC by David Binderman
Modified: 2007-02-16 01:58 UTC (History)
4 users (show)

See Also:
Host: x86_64-suse-linux
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
C++ source code (24.84 KB, text/plain)
2007-02-12 08:53 UTC, David Binderman
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Binderman 2007-02-12 08:52:10 UTC
I just tried to compile Suse Linux package ladspa-1.12.code10-56
with the GNU C++ compiler version 4.3 snapshot 20070209.

The compiler said

Descriptor.h: In static member function 'static void* Descriptor<T>::_instantiate(const _LADSPA_Descriptor*, ulong) [with T = CabinetII]':
Descriptor.h:117: internal compiler error: in vectorizable_type_promotion, at tree-vect-transform.c:2601
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Preprocessed source code attached. Flags -ftree-vectorize -O2 required.
Comment 1 David Binderman 2007-02-12 08:53:13 UTC
Created attachment 13038 [details]
C++ source code
Comment 2 Richard Biener 2007-02-12 09:58:06 UTC
Confirmed.  We hit

#1  0x0000000000ecf362 in vectorizable_type_promotion (stmt=0x2afac97cd000, 
    bsi=0x0, vec_stmt=0x0)
    at /space/rguenther/src/svn/trunk/gcc/tree-vect-transform.c:2752
2752      gcc_assert (ncopies >= 1);

because nunits_in is 4 but LOOP_VINFO_VECT_FACTOR (loop_vinfo) is 2. As this is
actually a widening (i_45 is int):

D.6364_12 = (long unsigned int) i_45

This is the loop:

  # SMT.373_48 = PHI <SMT.373_35(5), SMT.373_33(3)>
  # SMT.372_46 = PHI <SMT.372_34(5), SMT.372_32(3)>
  # i_45 = PHI <i_17(5), 0(3)>
<L0>:;
  d.29_10 = pretmp.393_8;
  D.6363_11 = pretmp.394_7;
  D.6364_12 = (long unsigned int) i_45;
  D.6365_13 = D.6364_12 * 12;
  D.6366_14 = (struct LADSPA_PortRangeHint *) D.6365_13;
  D.6367_15 = pretmp.394_7 + D.6366_14;
  D.6368_16 = &D.6367_15->LowerBound;
  # SMT.372_34 = VDEF <SMT.372_46>
  # SMT.373_35 = VDEF <SMT.373_48>
  plugin_3->ports[i_45] = D.6368_16;
  i_17 = i_45 + 1;
  if (i_17 < D.6359_44) goto <L9>; else goto <L2>;

so we are actually trying to vectorize a widening of the induction variable.
Comment 3 Dorit Naishlos 2007-02-12 10:11:29 UTC
I'll look into it.
Comment 4 Dorit Naishlos 2007-02-12 14:23:37 UTC
I'm testing the patch below. (wasn;t able to reproduce the problem in the attched testcase, but here's a reduced testcase for the problem that Richi described - thanks!:

int a[128];
int
main()
{
  short i;

  for (i=0; i<64; i++){
    a[i] = (int)i;
  }
  return 0;
}

)

Index: tree-vect-analyze.c
===================================================================
--- tree-vect-analyze.c	(revision 121843)
+++ tree-vect-analyze.c	(working copy)
@@ -97,8 +97,12 @@
   int nbbs = loop->num_nodes;
   block_stmt_iterator si;
   unsigned int vectorization_factor = 0;
+  tree scalar_type;
+  tree phi;
+  tree vectype;
+  unsigned int nunits;
+  stmt_vec_info stmt_info;
   int i;
-  tree scalar_type;
 
   if (vect_print_dump_info (REPORT_DETAILS))
     fprintf (vect_dump, "=== vect_determine_vectorization_factor ===");
@@ -107,12 +111,67 @@
     {
       basic_block bb = bbs[i];
 
+      for (phi = phi_nodes (bb); phi; phi = PHI_CHAIN (phi))
+	{
+	  stmt_info = vinfo_for_stmt (phi);
+	  if (vect_print_dump_info (REPORT_DETAILS))
+	    {
+	      fprintf (vect_dump, "==> examining phi: ");
+	      print_generic_expr (vect_dump, phi, TDF_SLIM);
+	    }
+
+	  gcc_assert (stmt_info);
+
+	  /* Two cases of "relevant" phis: those that define an 
+	     induction that is used in the loop, and those that
+	     define a reduction.  */
+	  if ((STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_loop
+	       && STMT_VINFO_DEF_TYPE (stmt_info) == vect_induction_def)
+	      || (STMT_VINFO_RELEVANT (stmt_info) == vect_used_by_reduction
+		  && STMT_VINFO_DEF_TYPE (stmt_info) == vect_reduction_def))
+            {
+	      gcc_assert (!STMT_VINFO_VECTYPE (stmt_info));
+              scalar_type = TREE_TYPE (PHI_RESULT (phi));
+
+	      if (vect_print_dump_info (REPORT_DETAILS))
+		{
+		  fprintf (vect_dump, "get vectype for scalar type:  ");
+		  print_generic_expr (vect_dump, scalar_type, TDF_SLIM);
+		}
+
+	      vectype = get_vectype_for_scalar_type (scalar_type);
+	      if (!vectype)
+		{
+		  if (vect_print_dump_info (REPORT_UNVECTORIZED_LOOPS))
+		    {
+		      fprintf (vect_dump,
+		               "not vectorized: unsupported data-type ");
+		      print_generic_expr (vect_dump, scalar_type, TDF_SLIM);
+		    }
+		  return false;
+		}
+	      STMT_VINFO_VECTYPE (stmt_info) = vectype;
+
+	      if (vect_print_dump_info (REPORT_DETAILS))
+		{
+		  fprintf (vect_dump, "vectype: ");
+		  print_generic_expr (vect_dump, vectype, TDF_SLIM);
+		}
+
+	      nunits = TYPE_VECTOR_SUBPARTS (vectype);
+	      if (vect_print_dump_info (REPORT_DETAILS))
+		fprintf (vect_dump, "nunits = %d", nunits);
+
+	      if (!vectorization_factor
+		  || (nunits > vectorization_factor))
+		vectorization_factor = nunits;
+	    }
+	}
+
       for (si = bsi_start (bb); !bsi_end_p (si); bsi_next (&si))
         {
 	  tree stmt = bsi_stmt (si);
-	  unsigned int nunits;
-	  stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
-	  tree vectype;
+	  stmt_info = vinfo_for_stmt (stmt);
 
 	  if (vect_print_dump_info (REPORT_DETAILS))
 	    {
@@ -269,10 +328,11 @@
 	    return false;
 	  }
 
-	  if (STMT_VINFO_RELEVANT_P (stmt_info))
+	  if (STMT_VINFO_RELEVANT (stmt_info) == vect_used_in_loop
+	      && STMT_VINFO_DEF_TYPE (stmt_info) != vect_induction_def)
 	    {
 	      /* Most likely a reduction-like computation that is used
-	         in the loop.  */
+		 in the loop.  */
 	      if (vect_print_dump_info (REPORT_UNVECTORIZED_LOOPS))
 	        fprintf (vect_dump, "not vectorized: unsupported pattern.");
  	     return false;
@@ -2235,17 +2295,7 @@
 
 	 (case 2)
            If STMT has been identified as defining a reduction variable, then
-	   we have two cases:
-	   (case 2.1)
-	     The last use of STMT is the reduction-variable, which is defined
-	     by a loop-header-phi. We don't want to mark the phi as live or
-	     relevant (because it does not need to be vectorized, it is handled
-             as part of the vectorization of the reduction), so in this case we
-	     skip the call to vect_mark_relevant.
-	   (case 2.2)
-	     The rest of the uses of STMT are defined in the loop body. For
-             the def_stmt of these uses we want to set liveness/relevance
-             as follows:
+           we want to set liveness/relevance as follows:
                STMT_VINFO_LIVE_P (DEF_STMT_info) <-- false
                STMT_VINFO_RELEVANT (DEF_STMT_info) <-- vect_used_by_reduction
              because even though STMT is classified as live (since it defines a
@@ -2297,16 +2347,6 @@
 	  bb = bb_for_stmt (def_stmt);
 	  if (!flow_bb_inside_loop_p (loop, bb))
 	    continue;
-
-	  /* case 2.1: the reduction-use does not mark the defining-phi
-	     as relevant.  */
-	  if (STMT_VINFO_DEF_TYPE (stmt_vinfo) == vect_reduction_def
-	      && TREE_CODE (def_stmt) == PHI_NODE)
-	    continue;
-
-	  if (dt == vect_induction_def && TREE_CODE (def_stmt) == PHI_NODE)
-	    continue;
-
 	  vect_mark_relevant (&worklist, def_stmt, relevant, live_p);
 	}
     }				/* while worklist */
Comment 5 patchapp@dberlin.org 2007-02-14 05:26:32 UTC
Subject: Bug number PR tree-optimization/30771

A patch for this bug has been added to the patch tracker.
The mailing list url for the patch is http://gcc.gnu.org/ml/gcc-patches/2007-02/msg01186.html
Comment 6 dorit 2007-02-14 14:11:09 UTC
Subject: Bug 30771

Author: dorit
Date: Wed Feb 14 14:10:57 2007
New Revision: 121950

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=121950
Log:
         PR tree-optimization/30771
        * tree-vect-analyze.c (vect_determine_vectorization_factor): Traverse
        also phi nodes.
        (vect_analyze_operations): Induction phis can now be marked as
        used_in_loop.
        (vect_mark_stmts_to_be_vectorized): No special treatment for phis.
        Update documentation accordingly.


Added:
    trunk/gcc/testsuite/gcc.dg/vect/pr30771.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-vect-analyze.c

Comment 7 Andrew Pinski 2007-02-16 01:58:11 UTC
Fixed.