From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32748 invoked by alias); 21 Jul 2011 13:15:02 -0000 Received: (qmail 32686 invoked by uid 22791); 21 Jul 2011 13:15:01 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,TW_TM X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (38.113.113.100) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 21 Jul 2011 13:14:26 +0000 Received: (qmail 8582 invoked from network); 21 Jul 2011 13:14:26 -0000 Received: from unknown (HELO ?192.168.0.104?) (ams@127.0.0.2) by mail.codesourcery.com with ESMTPA; 21 Jul 2011 13:14:26 -0000 Message-ID: <4E28262F.4080503@codesourcery.com> Date: Thu, 21 Jul 2011 13:48:00 -0000 From: Andrew Stubbs User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:5.0) Gecko/20110627 Thunderbird/5.0 MIME-Version: 1.0 To: Richard Guenther CC: gcc-patches@gcc.gnu.org Subject: Re: [PATCH (8/7)] Fix a bug in multiply-and-accumulate References: <4E034EF2.3070503@codesourcery.com> <4E24319D.3040607@codesourcery.com> In-Reply-To: Content-Type: multipart/mixed; boundary="------------070304050205060302080903" Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2011-07/txt/msg01762.txt.bz2 This is a multi-part message in MIME format. --------------070304050205060302080903 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 540 On 18/07/11 15:46, Richard Guenther wrote: > Will signedness be always the same? Usually the canonical check to > use would be !useless_type_conversion_p (type, TREE_TYPE (add_rhs)). The signedness ought to be unimportant - any extend will be based on the source type, and the signedness should not affect the addition operation. That said, it really ought to remain correct or else bad things could happen in later optimizations .... Here is the patch I plan to commit, when patch 1 is approved, and my testing is complete. Andrew --------------070304050205060302080903 Content-Type: text/x-patch; name="widening-multiplies-8.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="widening-multiplies-8.patch" Content-length: 1118 2011-07-21 Andrew Stubbs gcc/ * tree-ssa-math-opts.c (convert_plusminus_to_widen): Convert add_rhs to the correct type. gcc/testsuite/ * gcc.target/arm/wmul-10.c: New file. --- /dev/null +++ b/gcc/testsuite/gcc.target/arm/wmul-10.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ +/* { dg-require-effective-target arm_dsp } */ + + +unsigned long long +foo (unsigned short a, unsigned short *b, unsigned short *c) +{ + return (unsigned)a + (unsigned long long)*b * (unsigned long long)*c; +} + +/* { dg-final { scan-assembler "umlal" } } */ --- a/gcc/tree-ssa-math-opts.c +++ b/gcc/tree-ssa-math-opts.c @@ -2375,6 +2375,10 @@ convert_plusminus_to_widen (gimple_stmt_iterator *gsi, gimple stmt, mult_rhs2 = build_and_insert_cast (gsi, loc, tmp, mult_rhs2); } + if (!useless_type_conversion_p (type, TREE_TYPE (add_rhs))) + add_rhs = build_and_insert_cast (gsi, loc, create_tmp_var (type, NULL), + add_rhs); + gimple_assign_set_rhs_with_ops_1 (gsi, wmult_code, mult_rhs1, mult_rhs2, add_rhs); update_stmt (gsi_stmt (*gsi)); --------------070304050205060302080903--