From patchwork Tue Aug 27 22:29:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joern Rennecke X-Patchwork-Id: 270275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "www.sourceware.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by ozlabs.org (Postfix) with ESMTPS id 20B6B2C00A8 for ; Wed, 28 Aug 2013 08:30:05 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:to:cc:subject:references:in-reply-to :mime-version:content-type:content-transfer-encoding; q=dns; s= default; b=yoyqKZ2I0DOei5zFaDRnwNmpj/tCnOZJps/wyrcLHZp+zmnuUe5ys iB7XipeZBN3sGwiqwHrZDeMEhj8VlR6ZzN245ars2w0s/sPBQ5SFrfXAZ1QDTju6 pFFs7iOP5fQBp+XJxomBumKnMi5bzHmb0bcyfHhlI+zK1lQKYxCy3g= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :message-id:date:from:to:cc:subject:references:in-reply-to :mime-version:content-type:content-transfer-encoding; s=default; bh=v3lfvIGrLkst8OLlTK3dvClykbc=; b=k9dSgUtzf9uLn3Ns+Vryk2ksqkLN j53mx5PaP9sZ63MCSvm8rTDgxLOWQSHHMZI4vCnPzIMzl8HDH5gRheaNI7wyqMVL v8/pm0TJtWm7+HZLAb7VpOc2bdvjuu3vc5DuPn7hqTnlutfHqWWWCJrGB3446Om5 9ffEh5YwxFfMGlw= Received: (qmail 9835 invoked by alias); 27 Aug 2013 22:29:57 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 9826 invoked by uid 89); 27 Aug 2013 22:29:57 -0000 Received: from c62.cesmail.net (HELO c62.cesmail.net) (216.154.195.54) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 27 Aug 2013 22:29:57 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FSL_HELO_NON_FQDN_1, KHOP_THREADED, RDNS_NONE autolearn=no version=3.3.2 X-HELO: c62.cesmail.net Received: from unknown (HELO epsilon2) ([192.168.1.60]) by c62.cesmail.net with ESMTP; 27 Aug 2013 18:29:53 -0400 Received: from cust213-dsl91-135-11.idnet.net (cust213-dsl91-135-11.idnet.net [91.135.11.213]) by webmail.spamcop.net (Horde MIME library) with HTTP; Tue, 27 Aug 2013 18:29:53 -0400 Message-ID: <20130827182953.861lvln5p0ckggkg-nzlynne@webmail.spamcop.net> Date: Tue, 27 Aug 2013 18:29:53 -0400 From: Joern Rennecke To: gcc-patches@gcc.gnu.org, Marc Glisse Cc: Joseph Myers , Richard Henderson , Jason Merrill , Mark Mitchell , Nathan Sidwell Subject: Re: RFA: Consider int and same-size short as equivalent vector components References: <20130826121845.hp0ac9mlhc4ccwsw-nzlynne@webmail.spamcop.net> <20130826151736.utwsd1n6ogcw084w-nzlynne@webmail.spamcop.net> In-Reply-To: MIME-Version: 1.0 User-Agent: Internet Messaging Program (IMP) H3 (4.1.4) Quoting Marc Glisse : > On Mon, 26 Aug 2013, Joern Rennecke wrote: > >> Quoting Marc Glisse : >> >>> The issue seems larger than just short/int. On x86, (l>> compile for a vector of long, with l>> int, that seems wrong. >> >> I don't understand what you mean here. Could you post the actual >> code sample? > > typedef long vl __attribute__((vector_size(16))); > > void f(vl l){ > (l } > > it compiles fine on x86_64 but not on x86. > (btw, my sentence was ambiguous, what I find wrong is the failure to > compile, not the type of l gcc/c-family: * c-common.c (same_scalar_type_ignoring_signedness): Delete. (vector_types_compatible_elements_p): New function. * c-common.h: (same_scalar_type_ignoring_signedness): Delete prototype. (vector_types_compatible_elements_p): Prototype. gcc/c: * c-typeck.c (build_binary_op): Use vector_types_compatible_elements_p. gcc/cp: * typeck.c (cp_build_binary_op): Use vector_types_compatible_elements_p. gcc/testsuite: * c-c++-common/opaque-vector.c: New test. Index: c-family/c-common.c =================================================================== --- c-family/c-common.c (revision 202008) +++ c-family/c-common.c (working copy) @@ -10690,20 +10690,36 @@ resolve_overloaded_builtin (location_t l } } -/* Ignoring their sign, return true if two scalar types are the same. */ +/* True if vector types T1 and T2 can be inputs to the same binary + operator without conversion. + We don't check the overall vector size here because some of our callers + want to give different error messages when the vectors are compatible + except for the element count. */ + bool -same_scalar_type_ignoring_signedness (tree t1, tree t2) +vector_types_compatible_elements_p (tree t1, tree t2) { + bool opaque = TYPE_VECTOR_OPAQUE (t1) || TYPE_VECTOR_OPAQUE (t2); + t1 = TREE_TYPE (t1); + t2 = TREE_TYPE (t2); + enum tree_code c1 = TREE_CODE (t1), c2 = TREE_CODE (t2); gcc_assert ((c1 == INTEGER_TYPE || c1 == REAL_TYPE || c1 == FIXED_POINT_TYPE) && (c2 == INTEGER_TYPE || c2 == REAL_TYPE || c2 == FIXED_POINT_TYPE)); + t1 = c_common_signed_type (t1); + t2 = c_common_signed_type (t2); /* Equality works here because c_common_signed_type uses TYPE_MAIN_VARIANT. */ - return c_common_signed_type (t1) - == c_common_signed_type (t2); + if (t1 == t2) + return true; + if (opaque && c1 == c2 + && (c1 == INTEGER_TYPE || c1 == REAL_TYPE) + && TYPE_PRECISION (t1) == TYPE_PRECISION (t2)) + return true; + return false; } /* Check for missing format attributes on function pointers. LTYPE is Index: c-family/c-common.h =================================================================== --- c-family/c-common.h (revision 202008) +++ c-family/c-common.h (working copy) @@ -766,7 +766,7 @@ extern void warn_logical_operator (locat enum tree_code, tree, enum tree_code, tree); extern void check_main_parameter_types (tree decl); extern bool c_determine_visibility (tree); -extern bool same_scalar_type_ignoring_signedness (tree, tree); +extern bool vector_types_compatible_elements_p (tree, tree); extern void mark_valid_location_for_stdc_pragma (bool); extern bool valid_location_for_stdc_pragma_p (void); extern void set_float_const_decimal64 (void); Index: c/c-typeck.c =================================================================== --- c/c-typeck.c (revision 202008) +++ c/c-typeck.c (working copy) @@ -9973,7 +9973,7 @@ build_binary_op (location_t location, en if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE) { tree intt; - if (TREE_TYPE (type0) != TREE_TYPE (type1)) + if (!vector_types_compatible_elements_p (type0, type1)) { error_at (location, "comparing vectors with different " "element types"); @@ -10110,7 +10110,7 @@ build_binary_op (location_t location, en if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE) { tree intt; - if (TREE_TYPE (type0) != TREE_TYPE (type1)) + if (!vector_types_compatible_elements_p (type0, type1)) { error_at (location, "comparing vectors with different " "element types"); @@ -10216,8 +10216,7 @@ build_binary_op (location_t location, en if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE && (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)) - || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0), - TREE_TYPE (type1)))) + ||!vector_types_compatible_elements_p (type0, type1))) { binary_op_error (location, code, type0, type1); return error_mark_node; Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 202008) +++ cp/typeck.c (working copy) @@ -4534,7 +4534,8 @@ cp_build_binary_op (location_t location, vector_compare: tree intt; if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (type0), - TREE_TYPE (type1))) + TREE_TYPE (type1)) + && !vector_types_compatible_elements_p (type0, type1)) { if (complain & tf_error) { @@ -4650,8 +4651,7 @@ cp_build_binary_op (location_t location, if (code0 == VECTOR_TYPE && code1 == VECTOR_TYPE) { if (!tree_int_cst_equal (TYPE_SIZE (type0), TYPE_SIZE (type1)) - || !same_scalar_type_ignoring_signedness (TREE_TYPE (type0), - TREE_TYPE (type1))) + || !vector_types_compatible_elements_p (type0, type1)) { if (complain & tf_error) binary_op_error (location, code, type0, type1); Index: testsuite/c-c++-common/opaque-vector.c =================================================================== --- testsuite/c-c++-common/opaque-vector.c (revision 0) +++ testsuite/c-c++-common/opaque-vector.c (working copy) @@ -0,0 +1,22 @@ +#define B_TEST(TYPE) { TYPE v __attribute__((vector_size(16))); (void)((v < v) < v); } +#ifdef __cplusplus +#define T_TEST(TYPE) { TYPE s; TYPE v __attribute__((vector_size(16))); __typeof((v