From patchwork Fri Aug 17 17:05:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Earnshaw X-Patchwork-Id: 178283 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]) by ozlabs.org (Postfix) with SMTP id 601992C00A3 for ; Sat, 18 Aug 2012 03:05:34 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1345827936; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=guJ8qasWam/YHPm5AurT4ZRmvxM=; b=c2T/iabpDEtTYHH vHOWaBresMqEUXUMpnk+9haonZSf5ApU/ho9SqR3LmPMq0O27DnA/OAQCeePabLv JOXOd2M0K+TCwGTqOlevd2ShjRGtLWqhdojsAiQSntqgTuDwfd/iA/lXtBtVQh+p 9y9QQ/M867Kl92gb2n0uW8HFbdD0= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:X-MC-Unique:Content-Type:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=rmxHIGwV50E/XZcoGraTQasj9E0aaPc3aQR3/nD2BjMoLSmNWC1sz7IoeFIBXY UTLmfvFhubQfKtaGH0N6bPEkpkyHvbGu9l8NRUtzWNs12GrcZHkTpXVOuhKn5Gti uAG++WUWJngoblJLmtaIC++kkNm54D2fsGPxkbLmmg1Bk=; Received: (qmail 20287 invoked by alias); 17 Aug 2012 17:05:24 -0000 Received: (qmail 20259 invoked by uid 22791); 17 Aug 2012 17:05:20 -0000 X-SWARE-Spam-Status: No, hits=-1.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_LOW, TW_TM X-Spam-Check-By: sourceware.org Received: from service87.mimecast.com (HELO service87.mimecast.com) (91.220.42.44) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 17 Aug 2012 17:05:02 +0000 Received: from cam-owa2.Emea.Arm.com (fw-tnat.cambridge.arm.com [217.140.96.21]) by service87.mimecast.com; Fri, 17 Aug 2012 18:05:01 +0100 Received: from [10.1.69.67] ([10.1.255.212]) by cam-owa2.Emea.Arm.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 17 Aug 2012 18:06:46 +0100 Message-ID: <502E79BC.3080108@arm.com> Date: Fri, 17 Aug 2012 18:05:00 +0100 From: Richard Earnshaw User-Agent: Mozilla/5.0 (X11; Linux i686 on x86_64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1 MIME-Version: 1.0 To: Andrew Stubbs CC: "gcc-patches@gcc.gnu.org" , Richard Sandiford Subject: Re: [patch, tree-ssa] PR54295 Incorrect value extension in widening multiply-accumulate References: <502E4F54.9040309@arm.com> <502E53A7.406@codesourcery.com> <502E55CE.6020304@arm.com> <502E57A9.8050502@codesourcery.com> <502E598F.9010105@arm.com> <502E5DE6.8090806@codesourcery.com> <502E612E.60706@arm.com> In-Reply-To: <502E612E.60706@arm.com> X-MC-Unique: 112081718050100401 X-IsSubscribed: yes 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 On 17/08/12 16:20, Richard Earnshaw wrote: > Ok, in which case we have to give is_widening_mult_rhs_p enough smarts > to not strip > > (s32)u32 > > and return u32. > > I'll have another think about it. Take two. This version should address your concerns about handling (u32)u16 * (u32)u16 -> u64 We now look at each operand directly, but when doing so we check whether the operand is the same size as the result or not. When it is, we can strip any conversion; when it isn't the conversion must preserve signedness of the inner operand and mustn't be a narrowing conversion. * tree-ssa-math-opts.c (widening_mult_conversion_strippable_p): New function. (is_widening_mult_rhs_p): Use it. Testing underway (again) OK? R. --- tree-ssa-math-opts.c (revision 190502) +++ tree-ssa-math-opts.c (local) @@ -1958,6 +1958,43 @@ struct gimple_opt_pass pass_optimize_bsw } }; +/* Return true if stmt is a type conversion operation that can be stripped + when used in a widening multiply operation. */ +static bool +widening_mult_conversion_strippable_p (tree result_type, gimple stmt) +{ + enum tree_code rhs_code = gimple_assign_rhs_code (stmt); + + if (TREE_CODE (result_type) == INTEGER_TYPE) + { + tree op_type; + tree inner_op_type; + + if (!CONVERT_EXPR_CODE_P (rhs_code)) + return false; + + op_type = TREE_TYPE (gimple_assign_lhs (stmt)); + + /* If the type of OP has the same precision as the result, then + we can strip this conversion. The multiply operation will be + selected to create the correct extension as a by-product. */ + if (TYPE_PRECISION (result_type) == TYPE_PRECISION (op_type)) + return true; + + /* We can also strip a conversion if it preserves the signed-ness of + the operation and doesn't narrow the range. */ + inner_op_type = TREE_TYPE (gimple_assign_rhs1 (stmt)); + + if (TYPE_UNSIGNED (op_type) == TYPE_UNSIGNED (inner_op_type) + && TYPE_PRECISION (op_type) > TYPE_PRECISION (inner_op_type)) + return true; + + return false; + } + + return rhs_code == FIXED_CONVERT_EXPR; +} + /* Return true if RHS is a suitable operand for a widening multiplication, assuming a target type of TYPE. There are two cases: @@ -1982,9 +2019,7 @@ is_widening_mult_rhs_p (tree type, tree if (is_gimple_assign (stmt)) { rhs_code = gimple_assign_rhs_code (stmt); - if (TREE_CODE (type) == INTEGER_TYPE - ? !CONVERT_EXPR_CODE_P (rhs_code) - : rhs_code != FIXED_CONVERT_EXPR) + if (! widening_mult_conversion_strippable_p (type, stmt)) rhs1 = rhs; else {