From patchwork Fri Nov 29 11:14:43 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 295267 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 2917B2C009F for ; Fri, 29 Nov 2013 22:15:04 +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=BpCUxf6S2XsDU94bpzUpKjKBH+hOzrTmzt9IKegWDzCvnk2Lhs unXFt4K9yN1hF+LwGKBj/OFMxRGYnT8IaOR8+0SaZHWCtB+N09di5dQ6cvX03gDf 3SSa/eMrhScEO3Hq1HHBP/KWY0IDps357Wsns3rEtUWFwHSHP49bpGwBY= 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=//yWD0oBY6/+vqzrn4DLKiISg5g=; b=m/omds3SnL2QwrU4/ueR tj5DUMkRBMukinYfSi8IVNB/kVE9jMC1mknuP2u8HjGbIE+1CUo/4Z6LwG4uZpsZ jz/4nl/YuNCVLPgsldOqZBlHEz7u/DELkEXAAisSmcTl2hsPJ36sMuS1fofXxwuP qDm2Tvhs8sb+JS2CZn/bV6o= Received: (qmail 12984 invoked by alias); 29 Nov 2013 11:14:55 -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 12974 invoked by uid 89); 29 Nov 2013 11:14:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=0.6 required=5.0 tests=AWL, BAYES_50, FREEMAIL_FROM, RDNS_NONE, SPF_PASS, URIBL_BLOCKED autolearn=no version=3.3.2 X-HELO: mail-we0-f171.google.com Received: from Unknown (HELO mail-we0-f171.google.com) (74.125.82.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 29 Nov 2013 11:14:53 +0000 Received: by mail-we0-f171.google.com with SMTP id q58so9315168wes.30 for ; Fri, 29 Nov 2013 03:14:44 -0800 (PST) X-Received: by 10.194.93.193 with SMTP id cw1mr9697627wjb.38.1385723684290; Fri, 29 Nov 2013 03:14:44 -0800 (PST) Received: from localhost ([2.28.235.51]) by mx.google.com with ESMTPSA id dn2sm90655377wid.1.2013.11.29.03.14.43 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Nov 2013 03:14:43 -0800 (PST) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, Kenneth Zadeck , Mike Stump , rdsandiford@googlemail.com Cc: Kenneth Zadeck , Mike Stump Subject: [wide-int] Add a fast path for multiplication by 0 Date: Fri, 29 Nov 2013 11:14:43 +0000 Message-ID: <877gbrtq70.fsf@talisman.default> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 In the fold-const.ii testcase, well over half of the mul_internal calls were for multiplication by 0 (106038 out of 169355). This patch adds an early-out for that. Tested on x86_64-linux-gnu. OK to install? Thanks, Richard Index: gcc/wide-int.cc =================================================================== --- gcc/wide-int.cc 2013-11-29 10:50:46.594705157 +0000 +++ gcc/wide-int.cc 2013-11-29 11:06:50.052557006 +0000 @@ -1289,6 +1289,13 @@ wi::mul_internal (HOST_WIDE_INT *val, co if (needs_overflow) *overflow = false; + /* This is a surprisingly common case, so do it first. */ + if ((op1len == 1 && op1[0] == 0) || (op2len == 1 && op2[0] == 0)) + { + val[0] = 0; + return 1; + } + /* If we need to check for overflow, we can only do half wide multiplies quickly because we need to look at the top bits to check for the overflow. */