This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [middle-end] PR c/29092, vector types not compatible when they should be [take 2]
- From: Paolo Bonzini <paolo dot bonzini at lu dot unisi dot ch>
- To: Roger Sayle <roger at eyesopen dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 13 Oct 2006 16:01:16 +0200
- Subject: Re: [middle-end] PR c/29092, vector types not compatible when they should be [take 2]
- References: <Pine.LNX.4.44.0609282017330.28256-100000@www.eyesopen.com>
Hmm. I'm not really happy with the way that you're using the front-end
specific types_compatible_p langhook to decide whether to create a new
VECTOR_TYPE node or not. The middle-end, and particulary new type
construction in tree.c has/needs a stricter type system...
Right. I am now using GCC's type_hash_canon machinery. It is a bit
weird, because you have to build a type in order to get the canonical
version, but type creation happens rarely enough that this should not be
a problem.
As you suspected, this requires a different handling of attributed and
qualified types. There was a function "almost" doing what I wanted, but
it took the qualifiers from the basic type (and added the attributes).
So I added a new function to build a type variant with the requested
attributes *and* qualifiers.
The patch was bootstrapped (all languages except Ada) and regtested on
i686-pc-linux-gnu, together with the other part of PR29092 already
approved by Joseph.
Paolo
2006-10-13 Paolo Bonzini <bonzini@gnu.org>
* tree.c (build_type_attribute_qual_variant): New, based on
build_type_attribute_variant.
(build_type_attribute_variant): Rewrite using the former.
(make_vector_type): Use build_type_attribute_qual_variant to build
type variants. Use type_hash_canon on the others.
2006-10-13 Paolo Bonzini <bonzini@gnu.org>
* gcc.dg/simd-5.c: New.
* gcc.dg/simd-6.c: New.
Index: tree.c
===================================================================
--- tree.c (revision 117666)
+++ tree.c (working copy)
@@ -3356,12 +3355,12 @@ iterative_hash_host_wide_int (HOST_WIDE_
}
/* Return a type like TTYPE except that its TYPE_ATTRIBUTE
- is ATTRIBUTE.
+ is ATTRIBUTE and its qualifiers are QUALS.
Record such modified types already made so we don't make duplicates. */
-tree
-build_type_attribute_variant (tree ttype, tree attribute)
+static tree
+build_type_attribute_qual_variant (tree ttype, tree attribute, int quals)
{
if (! attribute_list_equal (TYPE_ATTRIBUTES (ttype), attribute))
{
@@ -3412,13 +3411,25 @@ build_type_attribute_variant (tree ttype
}
ntype = type_hash_canon (hashcode, ntype);
- ttype = build_qualified_type (ntype, TYPE_QUALS (ttype));
+ ttype = build_qualified_type (ntype, quals);
}
return ttype;
}
+/* Return a type like TTYPE except that its TYPE_ATTRIBUTE
+ is ATTRIBUTE.
+
+ Record such modified types already made so we don't make duplicates. */
+
+tree
+build_type_attribute_variant (tree ttype, tree attribute)
+{
+ return build_type_attribute_qual_variant (ttype, attribute,
+ TYPE_QUALS (ttype));
+}
+
/* Return nonzero if IDENT is a valid name for attribute ATTR,
or zero if not.
@@ -6384,8 +6395,18 @@ omp_clause_operand_check_failed (int idx
static tree
make_vector_type (tree innertype, int nunits, enum machine_mode mode)
{
- tree t = make_node (VECTOR_TYPE);
+ tree t;
+ hashval_t hashcode = 0;
+ /* Build a main variant, based on the main variant of the inner type, then
+ use it to build the variant we return. */
+ if (TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
+ return build_type_attribute_qual_variant (
+ make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode),
+ TYPE_ATTRIBUTES (innertype),
+ TYPE_QUALS (innertype));
+
+ t = make_node (VECTOR_TYPE);
TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
SET_TYPE_VECTOR_SUBPARTS (t, nunits);
TYPE_MODE (t) = mode;
@@ -6410,17 +6431,10 @@ make_vector_type (tree innertype, int nu
TYPE_UID (rt) = TYPE_UID (t);
}
- /* Build our main variant, based on the main variant of the inner type. */
- if (TYPE_MAIN_VARIANT (innertype) != innertype)
- {
- tree innertype_main_variant = TYPE_MAIN_VARIANT (innertype);
- unsigned int hash = TYPE_HASH (innertype_main_variant);
- TYPE_MAIN_VARIANT (t)
- = type_hash_canon (hash, make_vector_type (innertype_main_variant,
- nunits, mode));
- }
-
- return t;
+ hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
+ hashcode = iterative_hash_host_wide_int (mode, hashcode);
+ hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode);
+ return type_hash_canon (hashcode, t);
}
static tree
/* Ensure that we don't need a typedef to initialize a vector type. */
#define vector __attribute__ ((vector_size (8)))
vector char x = (vector char) {1,2,3,4,5,6,7,8}; /* { dg-bogus "initializer" } */
vector char y = (vector short) {1,2,3,4}; /* { dg-error "initializer" } */
/* { dg-do compile } */
/* { dg-options "-O2 -std=gnu99" } */
/* Ensure that we don't need a typedef to initialize a vector type. */
#define vector __attribute__ ((vector_size (8)))
vector char x = (vector char) {1,2,3,4,5,6,7,8}; /* { dg-bogus "initializer" } */
vector char y = (vector short) {1,2,3,4}; /* { dg-error "initializer" } */