From patchwork Thu Nov 28 17:34:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 294984 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)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8AACE2C00A1 for ; Fri, 29 Nov 2013 04:34:35 +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:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=pnVXvfLp30tkZlSlWgexG8VFxZ7ItU9jCfRjqcViiSWlJjDwgZ jdnm6yVIYL/1sEkTv3I/R0VYKe0K4MVUXdsDUXZf4kip3rVudk4VCn+qmqVB4VRr O2KsnqUffcQi4kaAhTX5CNwLByiNQapcXiRlTssljBQYi2dl20McMJkqc= 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:date:message-id:mime-version:content-type; s= default; bh=kk+J2tmsQodbmi8ZhfbKRoQzXqs=; b=apR5hKBJzPf9dDh7aNy9 NlpkLQ84v/Fo1M1I02awBhAUpQzezdBf4qWa4pr9mVZ83mI5RZYHz27Xko8xOcuf S/rtXUs/eIZxKP2bCML++rXINoedeOKj/+kanIPS2ulaAvzkAjeLislGKObB3tXQ C4pyny+//My+cSNKNzqOLeo= Received: (qmail 5182 invoked by alias); 28 Nov 2013 17:34:25 -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 5170 invoked by uid 89); 28 Nov 2013 17:34:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.3 required=5.0 tests=AWL, BAYES_50, RDNS_NONE autolearn=no version=3.3.2 X-HELO: e06smtp16.uk.ibm.com Received: from Unknown (HELO e06smtp16.uk.ibm.com) (195.75.94.112) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Thu, 28 Nov 2013 17:34:24 +0000 Received: from /spool/local by e06smtp16.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 28 Nov 2013 17:34:14 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp16.uk.ibm.com (192.168.101.146) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 28 Nov 2013 17:34:13 -0000 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 CF46A17D8058 for ; Thu, 28 Nov 2013 17:34:01 +0000 (GMT) Received: from d06av07.portsmouth.uk.ibm.com (d06av07.portsmouth.uk.ibm.com [9.149.37.248]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id rASHY0nk37486664 for ; Thu, 28 Nov 2013 17:34:00 GMT Received: from d06av07.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id rASHYCBN009649 for ; Thu, 28 Nov 2013 12:34:12 -0500 Received: from sandifor-thinkpad.stglab.manchester.uk.ibm.com (sig-9-146-236-43.de.ibm.com [9.146.236.43]) by d06av07.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id rASHY7Ra009565 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NO); Thu, 28 Nov 2013 12:34:10 -0500 From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, Kenneth Zadeck , Mike Stump , rsandifo@linux.vnet.ibm.com Cc: Kenneth Zadeck , Mike Stump Subject: [wide-int] Handle more cmps and cmpu cases inline Date: Thu, 28 Nov 2013 17:34:06 +0000 Message-ID: <87r4a0ph0x.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: 13112817-3548-0000-0000-0000074D6B03 As Richi asked, this patch makes cmps use the same shortcuts as lts_p. It also makes cmpu use the shortcut that I justed added to ltu_p. On that same fold-const.ii testcase, this reduces the number of cmps_large calls from 66924 to 916. It reduces the number of cmpu_large calls from 3462 to 4. Tested on x86_64-linux-gnu. OK to install? Thanks, Richard Index: gcc/wide-int.h =================================================================== --- gcc/wide-int.h 2001-01-01 00:00:00.000000000 +0000 +++ gcc/wide-int.h 2013-11-28 16:08:22.527681077 +0000 @@ -1858,17 +1858,31 @@ wi::cmps (const T1 &x, const T2 &y) unsigned int precision = get_binary_precision (x, y); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); - if (precision <= HOST_BITS_PER_WIDE_INT) + if (wi::fits_shwi_p (yi)) { - HOST_WIDE_INT xl = xi.to_shwi (); - HOST_WIDE_INT yl = yi.to_shwi (); - if (xl < yl) + /* Special case for comparisons with 0. */ + if (STATIC_CONSTANT_P (yi.val[0] == 0)) + return neg_p (xi) ? -1 : !(xi.len == 1 && xi.val[0] == 0); + /* If x fits into a signed HWI, we can compare directly. */ + if (wi::fits_shwi_p (xi)) + { + HOST_WIDE_INT xl = xi.to_shwi (); + HOST_WIDE_INT yl = yi.to_shwi (); + return xl < yl ? -1 : xl > yl; + } + /* If x doesn't fit and is negative, then it must be more + negative than any signed HWI, and hence smaller than y. */ + if (neg_p (xi)) return -1; - else if (xl > yl) - return 1; - else - return 0; + /* If x is positive, then it must be larger than any signed HWI, + and hence greater than y. */ + return 1; } + /* Optimize the opposite case, if it can be detected at compile time. */ + if (STATIC_CONSTANT_P (xi.len == 1)) + /* If YI is negative it is lower than the least HWI. + If YI is positive it is greater than the greatest HWI. */ + return neg_p (yi) ? 1 : -1; return cmps_large (xi.val, xi.len, precision, yi.val, yi.len); } @@ -1881,16 +1895,35 @@ wi::cmpu (const T1 &x, const T2 &y) unsigned int precision = get_binary_precision (x, y); WIDE_INT_REF_FOR (T1) xi (x, precision); WIDE_INT_REF_FOR (T2) yi (y, precision); - if (precision <= HOST_BITS_PER_WIDE_INT) + /* Optimize comparisons with constants. */ + if (STATIC_CONSTANT_P (yi.len == 1 && yi.val[0] >= 0)) { + /* If XI doesn't fit in a HWI then it must be larger than YI. */ + if (xi.len != 1) + return 1; + /* Otherwise compare directly. */ unsigned HOST_WIDE_INT xl = xi.to_uhwi (); - unsigned HOST_WIDE_INT yl = yi.to_uhwi (); - if (xl < yl) + unsigned HOST_WIDE_INT yl = yi.val[0]; + return xl < yl ? -1 : xl > yl; + } + if (STATIC_CONSTANT_P (xi.len == 1 && xi.val[0] >= 0)) + { + /* If YI doesn't fit in a HWI then it must be larger than XI. */ + if (yi.len != 1) return -1; - else if (xl == yl) - return 0; - else - return 1; + /* Otherwise compare directly. */ + unsigned HOST_WIDE_INT xl = xi.val[0]; + unsigned HOST_WIDE_INT yl = yi.to_uhwi (); + return xl < yl ? -1 : xl > yl; + } + /* Optimize the case of two HWIs. The HWIs are implicitly sign-extended + for precisions greater than HOST_BITS_WIDE_INT, but sign-extending both + values does not change the result. */ + if (xi.len + yi.len == 2) + { + unsigned HOST_WIDE_INT xl = xi.to_uhwi (); + unsigned HOST_WIDE_INT yl = yi.to_uhwi (); + return xl < yl ? -1 : xl > yl; } return cmpu_large (xi.val, xi.len, precision, yi.val, yi.len); }