From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14709 invoked by alias); 1 Jul 2011 12:25:28 -0000 Received: (qmail 14692 invoked by uid 22791); 1 Jul 2011 12:25:26 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW X-Spam-Check-By: sourceware.org Received: from mail-ww0-f51.google.com (HELO mail-ww0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jul 2011 12:25:12 +0000 Received: by wwj26 with SMTP id 26so2990685wwj.8 for ; Fri, 01 Jul 2011 05:25:11 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.172.203 with SMTP id m11mr1453992wbz.65.1309523111687; Fri, 01 Jul 2011 05:25:11 -0700 (PDT) Received: by 10.227.36.212 with HTTP; Fri, 1 Jul 2011 05:25:11 -0700 (PDT) In-Reply-To: <1A77B5B39081C241A68E6CF16983025F0209071D@EU1-MAIL.mgc.mentorg.com> References: <4E034EF2.3070503@codesourcery.com> <4E03504B.9060305@codesourcery.com> <4E044559.5000105@linaro.org> <1A77B5B39081C241A68E6CF16983025F020906F6@EU1-MAIL.mgc.mentorg.com> <4E09B142.4020402@codesourcery.com> <4E09FDEA.3000004@gmail.com> <1A77B5B39081C241A68E6CF16983025F0209071D@EU1-MAIL.mgc.mentorg.com> Date: Fri, 01 Jul 2011 12:25:00 -0000 Message-ID: Subject: Re: [PATCH (3/7)] Widening multiply-and-accumulate pattern matching From: Richard Guenther To: "Stubbs, Andrew" Cc: Michael Matz , Andrew Stubbs , gcc-patches@gcc.gnu.org, patches@linaro.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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/msg00027.txt.bz2 On Fri, Jul 1, 2011 at 1:58 PM, Stubbs, Andrew w= rote: > On 28/06/11 17:37, Michael Matz wrote: >>> What I want (and I'm not totally clear on what this actually means) is >>> > =A0to be able to optimize all the cases where the end result will be = the >>> > =A0same as the compiler produces now (using multiple multiply, shift,= and >>> > =A0add operations). >> Okay, then you really want to look through value-preserving conversions. >> >>> > =A0Ok, so that's an obvious statement, but the point is that, right n= ow, >>> > =A0the compiler does nothing special when you cast from int -> =A0uns= igned >>> > =A0int, or vice-versa, and I want to capture that somehow. There are = some >>> > =A0exceptions, I'm sure, but what are they? >> Same-sized signed<-> =A0unsigned conversions aren't value preserving: >> =A0 =A0unsigned char c =3D 255; (signed char)c =3D=3D -1; 255 !=3D -1 >> unsigned -> =A0larger sized signed is value preserving >> =A0 =A0unsigned char c =3D 255; (signed short)c =3D=3D 255; >> signed -> =A0unsigned never is value preserving > > OK, so I've tried implementing this, and I find I hit against a problem: > > Given this test case: > > =A0 unsigned long long > =A0 foo (unsigned long long a, signed char *b, signed char *c) > =A0 { > =A0 =A0 return a + *b * *c; > =A0 } > > Those rules say that it should not be suitable for optimization because > there's an implicit cast from signed int to unsigned long long. > > Without any widening multiplications allowed, GCC gives this code (for AR= M): > > =A0 ldrsb =A0 r2, [r2, #0] > =A0 ldrsb =A0 r3, [r3, #0] > =A0 mul =A0 =A0 r2, r2, r3 > =A0 adds =A0 =A0r0, r0, r2 > =A0 adc =A0 =A0 r1, r1, r2, asr #31 > > This is exactly what a signed widening multiply-and-accumulate with > smlalbb would have done! > > OK, so the types in the testcase are a bit contrived, but my point is > that I want to be able to use the widening-mult instructions everywhere > that they would produce the same output and gcc would otherwise, and gcc > just doesn't seem that interested in signed<->unsigned conversions. > > So, I'm happy to put in checks to ensure that truncations are not > ignore, but I'm really not sure what's the right thing to do with the > extends and signedness switches. > > Any suggestions? Well - some operations work the same on both signedness if you just care about the twos-complement result. This includes multiplication (but not for example division). For this special case I suggest to not bother trying to invent a generic predicate but do something local in tree-ssa-math-opts.c. Richard. > Andrew >