From patchwork Mon Apr 28 15:42:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 343484 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 829431400A0 for ; Tue, 29 Apr 2014 01:42:44 +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:from :to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type; q=dns; s=default; b=AmAqwZlpM3a6ZYWp czh7YnKkEPFLIPLzjBc6a3s61wgjIeNF2aYmiPdadOjKT9Nf6OCkfEkLSWoC/7z6 pXGe6j3wbzbkWvOGmNX+Pnqcv25rvcYtAsNSObVbz0T+mFzl9+z2Ms/p9Qma8M7W iZrlt7ZG1L0txi5OsZxhWhkiqx0= 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:from :to:cc:subject:references:date:in-reply-to:message-id :mime-version:content-type; s=default; bh=yWvgKCJB0kFwjZWDtuqx9q rVZXo=; b=RErqeExA/JxaEq+E6nw2Pl6y2pAEitywdjA9aPp/Mj3nbxAmRhdHpI HXgFtEqURALTnlKkfd8avH1c4A0j3pjdRRUoTZ2v3qUd4ILq+dCUStdALdNHXv60 EBFqnd+LyIrPPdEhDXSY9JPlt6InEYAzA6ckxxUq5iQeP+wpeiEt4= Received: (qmail 4135 invoked by alias); 28 Apr 2014 15:42:37 -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 4124 invoked by uid 89); 28 Apr 2014 15:42:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: e06smtp13.uk.ibm.com Received: from e06smtp13.uk.ibm.com (HELO e06smtp13.uk.ibm.com) (195.75.94.109) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Mon, 28 Apr 2014 15:42:34 +0000 Received: from /spool/local by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 28 Apr 2014 16:42:31 +0100 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 28 Apr 2014 16:42:30 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 7834E17D8067 for ; Mon, 28 Apr 2014 16:43:31 +0100 (BST) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s3SFgUnd1835280 for ; Mon, 28 Apr 2014 15:42:30 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s3SFgTVs012041 for ; Mon, 28 Apr 2014 09:42:29 -0600 Received: from sandifor-thinkpad.stglab.manchester.uk.ibm.com (sig-9-78-91-141.uk.ibm.com [9.78.91.141]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s3SFgTgE012028; Mon, 28 Apr 2014 09:42:29 -0600 From: Richard Sandiford To: Kyrill Tkachov Mail-Followup-To: Kyrill Tkachov , GCC Patches , "mikestump\@comcast.net" , "zadeck\@naturalbridge.com" , rsandifo@linux.vnet.ibm.com Cc: GCC Patches , "mikestump\@comcast.net" , "zadeck\@naturalbridge.com" Subject: Re: [PATCH][RFC][wide-int] Fix some build errors on arm in wide-int branch and report ICE References: <534D11EB.9020806@arm.com> <877g69vlnd.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com> <535E399C.4070503@arm.com> Date: Mon, 28 Apr 2014 16:42:28 +0100 In-Reply-To: <535E399C.4070503@arm.com> (Kyrill Tkachov's message of "Mon, 28 Apr 2014 12:21:00 +0100") Message-ID: <87mwf5sbob.fsf@sandifor-thinkpad.stglab.manchester.uk.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14042815-2966-0000-0000-00000B150F01 Kyrill Tkachov writes: > With that patch bootstrap now still fails at dwarf2out.c with the same > message. I'm attaching a gzipped dwarf2out.ii Thanks. This is a nice proof of why clz_zero and ctz_zero were as bogus as claimed. It meant that the behaviour of floor_log2 depended on the target and would return the wrong value if clz (0) was anything other than the precision. This patch makes the wide-int functions behave like the double_int ones and pushes the target dependency back to the callers that care, which is where it belongs. The "new" *_DEFINED_VALUE_AT_ZERO checks are really reinstating what's already on trunk. There are other tree uses of ctz that I think relied on the double_int behaviour. Tests still ongoing, but could you check what the arm results are like with this? Thanks, Richard Index: gcc/builtins.c =================================================================== --- gcc/builtins.c 2014-04-28 16:30:59.939239843 +0100 +++ gcc/builtins.c 2014-04-28 16:31:00.252238996 +0100 @@ -8080,6 +8080,7 @@ fold_builtin_bitop (tree fndecl, tree ar /* Optimize for constant argument. */ if (TREE_CODE (arg) == INTEGER_CST && !TREE_OVERFLOW (arg)) { + tree type = TREE_TYPE (arg); int result; switch (DECL_FUNCTION_CODE (fndecl)) @@ -8089,11 +8090,17 @@ fold_builtin_bitop (tree fndecl, tree ar break; CASE_INT_FN (BUILT_IN_CLZ): - result = wi::clz (arg); + if (wi::ne_p (arg, 0)) + result = wi::clz (arg); + else if (! CLZ_DEFINED_VALUE_AT_ZERO (TYPE_MODE (type), result)) + result = TYPE_PRECISION (type); break; CASE_INT_FN (BUILT_IN_CTZ): - result = wi::ctz (arg); + if (wi::ne_p (arg, 0)) + result = wi::ctz (arg); + else if (! CTZ_DEFINED_VALUE_AT_ZERO (TYPE_MODE (type), result)) + result = TYPE_PRECISION (type); break; CASE_INT_FN (BUILT_IN_CLRSB): Index: gcc/simplify-rtx.c =================================================================== --- gcc/simplify-rtx.c 2014-04-28 16:30:59.941239838 +0100 +++ gcc/simplify-rtx.c 2014-04-28 16:31:00.254238990 +0100 @@ -1656,6 +1656,7 @@ simplify_const_unary_operation (enum rtx wide_int result; enum machine_mode imode = op_mode == VOIDmode ? mode : op_mode; rtx_mode_t op0 = std::make_pair (op, imode); + int int_value; #if TARGET_SUPPORTS_WIDE_INT == 0 /* This assert keeps the simplification from producing a result @@ -1686,7 +1687,11 @@ simplify_const_unary_operation (enum rtx break; case CLZ: - result = wi::shwi (wi::clz (op0), mode); + if (wi::ne_p (op0, 0)) + int_value = wi::clz (op0); + else if (! CLZ_DEFINED_VALUE_AT_ZERO (mode, int_value)) + int_value = GET_MODE_PRECISION (mode); + result = wi::shwi (int_value, mode); break; case CLRSB: @@ -1694,7 +1699,11 @@ simplify_const_unary_operation (enum rtx break; case CTZ: - result = wi::shwi (wi::ctz (op0), mode); + if (wi::ne_p (op0, 0)) + int_value = wi::ctz (op0); + else if (! CTZ_DEFINED_VALUE_AT_ZERO (mode, int_value)) + int_value = GET_MODE_PRECISION (mode); + result = wi::shwi (int_value, mode); break; case POPCOUNT: Index: gcc/wide-int.cc =================================================================== --- gcc/wide-int.cc 2014-04-28 16:30:59.941239838 +0100 +++ gcc/wide-int.cc 2014-04-28 16:31:00.254238990 +0100 @@ -1137,46 +1137,6 @@ wi::add_large (HOST_WIDE_INT *val, const return canonize (val, len, prec); } -/* This is bogus. We should always return the precision and leave the - caller to handle target dependencies. */ -static int -clz_zero (unsigned int precision) -{ - unsigned int count; - - enum machine_mode mode = mode_for_size (precision, MODE_INT, 0); - if (mode == BLKmode) - mode_for_size (precision, MODE_PARTIAL_INT, 0); - - /* Even if the value at zero is undefined, we have to come up - with some replacement. Seems good enough. */ - if (mode == BLKmode) - count = precision; - else if (!CLZ_DEFINED_VALUE_AT_ZERO (mode, count)) - count = precision; - return count; -} - -/* This is bogus. We should always return the precision and leave the - caller to handle target dependencies. */ -static int -ctz_zero (unsigned int precision) -{ - unsigned int count; - - enum machine_mode mode = mode_for_size (precision, MODE_INT, 0); - if (mode == BLKmode) - mode_for_size (precision, MODE_PARTIAL_INT, 0); - - /* Even if the value at zero is undefined, we have to come up - with some replacement. Seems good enough. */ - if (mode == BLKmode) - count = precision; - else if (!CTZ_DEFINED_VALUE_AT_ZERO (mode, count)) - count = precision; - return count; -} - /* Subroutines of the multiplication and division operations. Unpack the first IN_LEN HOST_WIDE_INTs in INPUT into 2 * IN_LEN HOST_HALF_WIDE_INTs of RESULT. The rest of RESULT is filled by @@ -2002,10 +1962,6 @@ wi::clz (const wide_int_ref &x) /* The upper bit is set, so there are no leading zeros. */ return 0; - /* Check whether the value is zero. */ - if (high == 0 && x.len == 1) - return clz_zero (x.precision); - /* We don't need to look below HIGH. Either HIGH is nonzero, or the top bit of the block below is nonzero; clz_hwi is HOST_BITS_PER_WIDE_INT in the latter case. */ @@ -2047,7 +2003,7 @@ int wi::ctz (const wide_int_ref &x) { if (x.len == 1 && x.ulow () == 0) - return ctz_zero (x.precision); + return x.precision; /* Having dealt with the zero case, there must be a block with a nonzero bit. We don't care about the bits above the first 1. */