From patchwork Wed Oct 8 21:27:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: DJ Delorie X-Patchwork-Id: 397808 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 175491400E0 for ; Thu, 9 Oct 2014 08:27:59 +1100 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :message-id:from:to:cc:in-reply-to:subject:references; q=dns; s= default; b=c3BTjEvCTtL25xSlonnQSYcpXvHcPG2lsLPbdtyFFI17C7n+hmosT msg/6UGTbJcGRILAs/77KXcAkhn/ySUyJp4RmHtnxWwMwrjdDyjeaOTMWQPxv+sF Lgfk3OaawlW8M8lL65+cIAlOMJFRS5Yn731O77KH1M0aVsNRSHklFA= 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:date :message-id:from:to:cc:in-reply-to:subject:references; s= default; bh=UTrPx+OvIqRbSzeQo49m6n8grEk=; b=tbF/k2Y/ma02TGmRVN5T xEV1DexUsc293wg/Y0Iq++++CkEaAbOwVwVqYIi4P0pFatbYRcl2Y6lihN6N7IDB GCYfN5Ll0csYdX1OpSqzQU5BWX6S5lF0cXefGRuEFyFHB8IALzZUgiCf2hAa1o87 HrUim9JIAKCh2eTQYwCMKAA= Received: (qmail 5333 invoked by alias); 8 Oct 2014 21:27:23 -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 5324 invoked by uid 89); 8 Oct 2014 21:27:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.5 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 08 Oct 2014 21:27:22 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s98LRIDY027833 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 8 Oct 2014 17:27:19 -0400 Received: from greed.delorie.com (ovpn-113-33.phx2.redhat.com [10.3.113.33]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s98LRH7c001579 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Wed, 8 Oct 2014 17:27:18 -0400 Received: from greed.delorie.com (greed.delorie.com [127.0.0.1]) by greed.delorie.com (8.14.4/8.14.4) with ESMTP id s98LRHrR032387; Wed, 8 Oct 2014 17:27:17 -0400 Received: (from dj@localhost) by greed.delorie.com (8.14.4/8.14.4/Submit) id s98LRGn7032386; Wed, 8 Oct 2014 17:27:16 -0400 Date: Wed, 8 Oct 2014 17:27:16 -0400 Message-Id: <201410082127.s98LRGn7032386@greed.delorie.com> From: DJ Delorie To: Jason Merrill CC: nathan@codesourcery.com, gcc-patches@gcc.gnu.org In-reply-to: <54303821.2090205@redhat.com> (message from Jason Merrill on Sat, 04 Oct 2014 14:10:41 -0400) Subject: Re: __intN patch 3/5: main __int128 -> __intN conversion. References: <201408132211.s7DMBGBu016387@greed.delorie.com> <201408212123.s7LLNPIQ018746@greed.delorie.com> <201408220515.s7M5Fhpa007479@greed.delorie.com> <201408221924.s7MJOcjB022631@greed.delorie.com> <201408260303.s7Q33nqm024601@greed.delorie.com> <201409302314.s8UNE7LP020494@greed.delorie.com> <542CC4FA.70609@redhat.com> <201410020352.s923qLlm002274@greed.delorie.com> <542D5FA4.6020401@redhat.com> <201410021641.s92GfTcV024373@greed.delorie.com> <542D8F05.7090705@redhat.com> <201410021800.s92I04Nk026647@greed.delorie.com> <542EAD69.9090306@redhat.com> <201410032011.s93KBpc2005414@greed.delorie.com> <54303821.2090205@redhat.com> X-IsSubscribed: yes > > if (same_type_p (TYPE_MAIN_VARIANT (t1), long_long_unsigned_type_node) > > || same_type_p (TYPE_MAIN_VARIANT (t2), long_long_unsigned_type_node)) > > return build_type_attribute_variant (long_long_unsigned_type_node, > > attributes); > > Your patch only compares t1/t2 to int_n_trees[i].signed_type. Checking the code before this logic, we can make some assumptions: /* Both real or both integers; use the one with greater precision. */ * we can assume the two types have the same precision /* The types are the same; no need to do anything fancy. */ * we can assume the two types are different In the case of non-128 __intN, checking only for signed *should* work - the only other type that's the same precision but a different type *is* the unsigned variant (enforced in toplev.c). Even in the case of __int128, if either type is signed __int128 and the other type is different AT ALL, the result will be unsigned __int128 if either type is unsigned, or signed __int128. But a new patch which checks everything anyway is attached :-) Index: typeck.c =================================================================== --- typeck.c (revision 216012) +++ typeck.c (working copy) @@ -270,6 +270,7 @@ enum tree_code code1 = TREE_CODE (t1); enum tree_code code2 = TREE_CODE (t2); tree attributes; + int i; /* In what follows, we slightly generalize the rules given in [expr] so @@ -364,17 +365,6 @@ : long_long_integer_type_node); return build_type_attribute_variant (t, attributes); } - if (int128_integer_type_node != NULL_TREE - && (same_type_p (TYPE_MAIN_VARIANT (t1), - int128_integer_type_node) - || same_type_p (TYPE_MAIN_VARIANT (t2), - int128_integer_type_node))) - { - tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2)) - ? int128_unsigned_type_node - : int128_integer_type_node); - return build_type_attribute_variant (t, attributes); - } /* Go through the same procedure, but for longs. */ if (same_type_p (TYPE_MAIN_VARIANT (t1), long_unsigned_type_node) @@ -388,6 +378,26 @@ ? long_unsigned_type_node : long_integer_type_node); return build_type_attribute_variant (t, attributes); } + + /* For __intN types, either the type is __int128 (and is lower + priority than the types checked above, but higher than other + 128-bit types) or it's known to not be the same size as other + types (enforced in toplev.c). Prefer the unsigned type. */ + for (i = 0; i < NUM_INT_N_ENTS; i ++) + { + if (int_n_enabled_p [i] + && (same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].signed_type) + || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].signed_type) + || same_type_p (TYPE_MAIN_VARIANT (t1), int_n_trees[i].unsigned_type) + || same_type_p (TYPE_MAIN_VARIANT (t2), int_n_trees[i].unsigned_type))) + { + tree t = ((TYPE_UNSIGNED (t1) || TYPE_UNSIGNED (t2)) + ? int_n_trees[i].unsigned_type + : int_n_trees[i].signed_type); + return build_type_attribute_variant (t, attributes); + } + } + /* Otherwise prefer the unsigned one. */ if (TYPE_UNSIGNED (t1)) return build_type_attribute_variant (t1, attributes);