[PATCH] Fix PR43390

Richard Guenther rguenther@suse.de
Mon Mar 22 13:30:00 GMT 2010


This fixes the type verification ICEs we get when extracting a
scalar component of a vector with element types whose precision
do not match that of their mode (and thus in reality the vector
operations do not operate on a vector of corresponding scalar
types).  In odd situations this may even lead to wrong code
when a specific sign/zero extension is assumed and thus omitted
from further operations on extracted elements.

The safe thing is to refuse to vectorize code that does computations
on such types.

Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to trunk.

Richard.

2010-03-22  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/43390
	* tree-vect-stmts.c (get_vectype_for_scalar_type): Make
	sure vector extracts are type correct.

	* gfortran.fortran-torture/execute/pr43390.f90: New testcase.

Index: gcc/tree-vect-stmts.c
===================================================================
*** gcc/tree-vect-stmts.c	(revision 157619)
--- gcc/tree-vect-stmts.c	(working copy)
*************** get_vectype_for_scalar_type (tree scalar
*** 4417,4422 ****
--- 4417,4430 ----
    if (nbytes < TYPE_ALIGN_UNIT (scalar_type))
      return NULL_TREE;
  
+   /* If we'd build a vector type of elements whose mode precision doesn't
+      match their types precision we'll get mismatched types on vector
+      extracts via BIT_FIELD_REFs.  This effectively means we disable
+      vectorization of bool and/or enum types in some languages.  */
+   if (INTEGRAL_TYPE_P (scalar_type)
+       && GET_MODE_BITSIZE (inner_mode) != TYPE_PRECISION (scalar_type))
+     return NULL_TREE;
+ 
    /* FORNOW: Only a single vector size per mode (UNITS_PER_SIMD_WORD)
       is expected.  */
    nunits = UNITS_PER_SIMD_WORD (inner_mode) / nbytes;
Index: gcc/testsuite/gfortran.fortran-torture/execute/pr43390.f90
===================================================================
*** gcc/testsuite/gfortran.fortran-torture/execute/pr43390.f90	(revision 0)
--- gcc/testsuite/gfortran.fortran-torture/execute/pr43390.f90	(revision 0)
***************
*** 0 ****
--- 1,9 ----
+    logical :: l1(4)
+    logical :: l2(4)
+    l1 = (/.TRUE.,.FALSE.,.TRUE.,.FALSE./)
+    l2 = (/.FALSE.,.TRUE.,.FALSE.,.TRUE./)
+    if (dot_product (l1, l2)) call abort ()
+    l2 = .TRUE.
+    if (.not.dot_product (l1, l2)) call abort ()
+ end
+ 



More information about the Gcc-patches mailing list