From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20089 invoked by alias); 1 Jun 2011 09:42:35 -0000 Received: (qmail 20081 invoked by uid 22791); 1 Jun 2011 09:42:34 -0000 X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,RFC_ABUSE_POST X-Spam-Check-By: sourceware.org Received: from mail-wy0-f175.google.com (HELO mail-wy0-f175.google.com) (74.125.82.175) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 01 Jun 2011 09:42:20 +0000 Received: by wye20 with SMTP id 20so4661508wye.20 for ; Wed, 01 Jun 2011 02:42:19 -0700 (PDT) MIME-Version: 1.0 Received: by 10.227.167.129 with SMTP id q1mr7046657wby.101.1306921339233; Wed, 01 Jun 2011 02:42:19 -0700 (PDT) Received: by 10.227.37.152 with HTTP; Wed, 1 Jun 2011 02:42:19 -0700 (PDT) In-Reply-To: References: Date: Wed, 01 Jun 2011 09:42:00 -0000 Message-ID: Subject: Re: [patch] Improve detection of widening multiplication in the vectorizer From: Richard Guenther To: Ira Rosen Cc: gcc-patches@gcc.gnu.org, Patch Tracking 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-06/txt/msg00020.txt.bz2 On Wed, Jun 1, 2011 at 11:23 AM, Ira Rosen wrote: > Hi, > > The vectorizer expects widening multiplication pattern to be: > > =A0 =A0 type a_t, b_t; > =A0 =A0 TYPE a_T, b_T, prod_T; > > =A0 =A0 a_T =3D (TYPE) a_t; > =A0 =A0 b_T =3D (TYPE) b_t; > =A0 =A0 prod_T =3D a_T * b_T; > > where type 'TYPE' is double the size of type 'type'. This works fine > when the types are signed. For the unsigned types the code looks like: > > =A0 =A0 unsigned type a_t, b_t; > =A0 =A0 unsigned TYPE u_prod_T; > =A0 =A0 TYPE a_T, b_T, prod_T; > > =A0 =A0 =A0a_T =3D (TYPE) a_t; > =A0 =A0 =A0b_T =3D (TYPE) b_t; > =A0 =A0 =A0prod_T =3D a_T * b_T; > =A0 =A0 =A0u_prod_T =3D (unsigned TYPE) prod_T; > > i.e., the multiplication is done on signed, followed by a cast to unsigne= d. > This patch adds a support of such patterns and generates > WIDEN_MULT_EXPR for the unsigned type. > > Another unsupported case is multiplication by a constant (e.g., b_T is > a constant). This patch checks that the constant fits the smaller type > 'type' and recognizes such cases as widening multiplication. > > Bootstrapped and tested on powerpc64-suse-linux. Tested the > vectorization testsuite on arm-linux-gnueabi. > I'll commit the patch shortly if there are no comments/objections. Did you think about moving pass_optimize_widening_mul before loop optimizations? Does that pass catch the cases you are teaching the pattern recognizer? I think we should try to expose these more complicated instructions to loop optimizers. Thanks, Richard. > Ira > > ChangeLog: > > =A0 =A0 =A0 * tree-vectorizer.h (vect_recog_func_ptr): Make last argument= to be > =A0 =A0 =A0 a pointer. > =A0 =A0 =A0 * tree-vect-patterns.c (vect_recog_widen_sum_pattern, > =A0 =A0 =A0 vect_recog_widen_mult_pattern, vect_recog_dot_prod_pattern, > =A0 =A0 =A0 vect_recog_pow_pattern): Likewise. > =A0 =A0 =A0 (vect_pattern_recog_1): Remove declaration. > =A0 =A0 =A0 (widened_name_p): Remove declaration. =A0Add new argument to = specify > =A0 =A0 =A0 whether to check that both types are either signed or unsigne= d. > =A0 =A0 =A0 (vect_recog_widen_mult_pattern): Update documentation. =A0Han= dle > =A0 =A0 =A0 unsigned patterns and multiplication by constants. > =A0 =A0 =A0 (vect_pattern_recog_1): Update vect_recog_func references. = =A0Use > =A0 =A0 =A0 statement information from the statement returned from pattern > =A0 =A0 =A0 detection functions. > =A0 =A0 =A0 (vect_pattern_recog): Update vect_recog_func reference. > =A0 =A0 =A0 * tree-vect-stmts.c (vectorizable_type_promotion): For wideni= ng > =A0 =A0 =A0 multiplication by a constant use the type of the other operan= d. > > testsuite/ChangeLog: > > =A0 =A0 =A0 * lib/target-supports.exp > (check_effective_target_vect_widen_mult_qi_to_hi): > =A0 =A0 =A0 Add NEON as supporting target. > =A0 =A0 =A0 (check_effective_target_vect_widen_mult_hi_to_si): Likewise. > =A0 =A0 =A0 (check_effective_target_vect_widen_mult_qi_to_hi_pattern): Ne= w. > =A0 =A0 =A0 (check_effective_target_vect_widen_mult_hi_to_si_pattern): Ne= w. > =A0 =A0 =A0 * gcc.dg/vect/vect-widen-mult-u8.c: Expect to be vectorized > using widening > =A0 =A0 =A0 multiplication on targets that support it. > =A0 =A0 =A0 * gcc.dg/vect/vect-widen-mult-u16.c: Likewise. > =A0 =A0 =A0 * gcc.dg/vect/vect-widen-mult-const-s16.c: New test. > =A0 =A0 =A0 * gcc.dg/vect/vect-widen-mult-const-u16.c: New test. >