From patchwork Fri Sep 13 18:06:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Hou X-Patchwork-Id: 274835 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 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8D0AC2C00C8 for ; Sat, 14 Sep 2013 04:06:17 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; q=dns; s=default; b=bZvqCicAQkHIbK362u SRHIhNCi+hh2WHzrWdwCZy1BBp2Dz/9YCeVQygyab4kRgkwFAHcVoH7CAc/dtI5O 9N7fKZ0ZN+t3Yg5y9ElX+aySyfu3m/hbSixvgtEzBDRQU1DVxcWviFe/EL1pB3iD bVOvj5+Qonk0ez3fYxeVBQsgA= 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 :mime-version:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; s=default; bh=pIT+Q1soXXWVwQ0bub/j3Vy9 EuI=; b=rRlFTtAejcSH64WBuzw9+gZ1ysYCfU13z/G+RWI5WGu9HMVLb58osFki /adfEgxYy43/zrvcPM8sIbgqVcGPE4J7HfU6zrLHwTqLZYPszJzAKHv85Y90HLFV TxWgnAlL9hMfJxvpqAZgPqoFaYb4ExbzLdeqpdLbBp5eSVNSrHE= Received: (qmail 30505 invoked by alias); 13 Sep 2013 18:06:10 -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 30464 invoked by uid 89); 13 Sep 2013 18:06:09 -0000 Received: from mail-ie0-f178.google.com (HELO mail-ie0-f178.google.com) (209.85.223.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Fri, 13 Sep 2013 18:06:09 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, KHOP_THREADED, NO_RELAYS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f178.google.com Received: by mail-ie0-f178.google.com with SMTP id to1so3267028ieb.37 for ; Fri, 13 Sep 2013 11:06:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=qxWvP4xQ9hS9uoP15bspjs/pUBcKhhQL2nJbjuDgYGc=; b=HSUt2m+iEn/7uaIOBcaq0mecBncs/1qDPI1+Apoc500j6yOioGPU4BCp9aY0OcFIsS rS0jcwTzR3buBThvFPhlXiKGLkiLf7t4r/wvwJqG396/PBBYXzDdMTGo2kW3evLVQHYF sBjtEka1sBvbhTMm4elHa5eBb6e2e6pyuL+S7Wtbvq/xNq7UT4quxi2CiDlX2PgAa4LU uMvVmi5w1OMVhNObbKpFH87sw7iG5qsBzuBM4wIzPBF4+TJBFVHU26MdxmIUTalr07YK LdMfHbat0zp5dGYltwRK3eyTIm7oLUznVgNRtd15iQ0EUGNYGmbEGOQN+70hsXdFE7OX oCGA== X-Gm-Message-State: ALoCoQlhDGC83q01e63i0d1f3x919Yqnn0C85FagpyIrgIUX/02t/+DAsB9wbqnjlXLInpOUQNcaPxNdzxF9COJWEZuLrn4KBfc4JXKSFAeV9nTGBbX18OlyMhMIKH9/FQac6aTtsSdGO3ujDuyX0x/gRGcE+Xa58x6X2K/vRoXigcsPUx5fAisXpRlsg/6XgUSCJgppox1ykPjY6vONXymrfnKnXEmV3g== MIME-Version: 1.0 X-Received: by 10.42.250.201 with SMTP id mp9mr820318icb.0.1379095566906; Fri, 13 Sep 2013 11:06:06 -0700 (PDT) Received: by 10.64.236.37 with HTTP; Fri, 13 Sep 2013 11:06:06 -0700 (PDT) In-Reply-To: References: Date: Fri, 13 Sep 2013 11:06:06 -0700 Message-ID: Subject: Re: [PATCH] [vectorizer] Fixing a bug in tree-vect-patterns.c in GCC vectorizer. From: Cong Hou To: Xinliang David Li , Richard Biener Cc: GCC Patches A new test case is added to testsuite/gcc.dg/vect, which will fail without this patch and pass with it. Bootstrap also get passed. No additional test failure is introduced. The new test case includes a dot product on two arrays with short and int types. The loop will still be vectorized (using punpcklwd on array with short type), but should not be recognized as a dot-product pattern. thanks, Cong On Wed, Sep 11, 2013 at 6:55 PM, Xinliang David Li wrote: > Can you add a test case to the regression suite? > > When the type of arguments are unsigned short/unsigned int, GCC does > not vectorize the loop anymore -- this is worth a separate bug to > track. punpcklwd instruction can be used to do zero extension of the > short type. > > David > > On Wed, Sep 11, 2013 at 6:16 PM, Cong Hou wrote: >> Hi >> >> There is a bug in the function vect_recog_dot_prod_pattern() in >> tree-vect-patterns.c. This function checks if a loop is of dot >> production pattern. Specifically, according to the comment of this >> function: >> >> /* >> Try to find the following pattern: >> >> type x_t, y_t; >> TYPE1 prod; >> TYPE2 sum = init; >> loop: >> sum_0 = phi >> S1 x_t = ... >> S2 y_t = ... >> S3 x_T = (TYPE1) x_t; >> S4 y_T = (TYPE1) y_t; >> S5 prod = x_T * y_T; >> [S6 prod = (TYPE2) prod; #optional] >> S7 sum_1 = prod + sum_0; >> >> where 'TYPE1' is exactly double the size of type 'type', and >> 'TYPE2' is the same size of 'TYPE1' or bigger. This is a special case >> of a reduction computation. >> */ >> >> This function should check if x_t and y_t have the same type (type) >> which has the half size of TYPE1. The corresponding code is shown >> below: >> >> oprnd0 = gimple_assign_rhs1 (stmt); >> oprnd1 = gimple_assign_rhs2 (stmt); >> if (!types_compatible_p (TREE_TYPE (oprnd0), prod_type) || >> !types_compatible_p (TREE_TYPE (oprnd1), prod_type)) >> return NULL; >> if (!type_conversion_p (oprnd0, stmt, true, &half_type0, >> &def_stmt, &promotion) || !promotion) >> return NULL; >> oprnd00 = gimple_assign_rhs1 (def_stmt); >> >> /*======================V see here! */ >> if (!type_conversion_p (oprnd0, stmt, true, &half_type1, >> &def_stmt, &promotion) || !promotion) >> return NULL; >> oprnd01 = gimple_assign_rhs1 (def_stmt); >> if (!types_compatible_p (half_type0, half_type1)) >> return NULL; >> if (TYPE_PRECISION (prod_type) != TYPE_PRECISION (half_type0) * 2) >> return NULL; >> >> Here the function uses x_T (oprnd0) to check the type of y_t, which is >> incorrect. The fix is simple: just replace it by oprnd1. >> >> The failed test case for this bug is shown below: >> >> int foo(short *a, int *b, int n) { >> int sum = 0; >> for (int i = 0; i < n; ++i) >> sum += a[i] * b[i]; >> return sum; >> } >> >> >> thanks, >> Cong >> >> >> Index: gcc/tree-vect-patterns.c >> =================================================================== >> --- gcc/tree-vect-patterns.c (revision 200988) >> +++ gcc/tree-vect-patterns.c (working copy) >> @@ -397,7 +397,7 @@ vect_recog_dot_prod_pattern (vec >> || !promotion) >> return NULL; >> oprnd00 = gimple_assign_rhs1 (def_stmt); >> - if (!type_conversion_p (oprnd0, stmt, true, &half_type1, &def_stmt, >> + if (!type_conversion_p (oprnd1, stmt, true, &half_type1, &def_stmt, >> &promotion) >> || !promotion) >> return NULL; Index: gcc/tree-vect-patterns.c =================================================================== --- gcc/tree-vect-patterns.c (revision 202572) +++ gcc/tree-vect-patterns.c (working copy) @@ -397,7 +397,7 @@ vect_recog_dot_prod_pattern (vec || !promotion) return NULL; oprnd00 = gimple_assign_rhs1 (def_stmt); - if (!type_conversion_p (oprnd0, stmt, true, &half_type1, &def_stmt, + if (!type_conversion_p (oprnd1, stmt, true, &half_type1, &def_stmt, &promotion) || !promotion) return NULL; Index: gcc/ChangeLog =================================================================== --- gcc/ChangeLog (revision 202572) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2013-09-13 Cong Hou + + * tree-vect-patterns.c (vect_recog_dot_prod_pattern): Fix a bug + when checking the dot production pattern. The type of rhs operand + of multiply is now checked correctly. + 2013-09-13 Jan Hubicka PR middle-end/58094 Index: gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c =================================================================== --- gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c (revision 0) +++ gcc/testsuite/gcc.dg/vect/vect-reduc-dot-s16c.c (revision 0) @@ -0,0 +1,73 @@ +/* { dg-require-effective-target vect_int } */ + +#include +#include "tree-vect.h" + +#define N 64 +#define DOT 43680 + +signed short X[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))); +signed int Y[N] __attribute__ ((__aligned__(__BIGGEST_ALIGNMENT__))); + +/* (short, int)->int->int dot product. + Not detected as a dot-product pattern. */ + +__attribute__ ((noinline)) int +foo (int len) +{ + int i; + int result = 0; + + for (i = 0; i < len; i++) + { + result += (X[i] * Y[i]); + } + return result; +} + + +/* (int, short)->int->int dot product. + Not detected as a dot-product pattern. */ + +__attribute__ ((noinline)) int +bar (int len) +{ + int i; + int result = 0; + + for (i = 0; i < len; i++) + { + result += (Y[i] * X[i]); + } + return result; +} + +int +main (void) +{ + int i; + int dot; + + check_vect (); + + for (i = 0; i < N; i++) + { + X[i] = i; + Y[i] = N - i; + __asm__ volatile (""); + } + + dot = foo (N); + if (dot != DOT) + abort (); + + dot = bar (N); + if (dot != DOT) + abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 2 "vect" { target vect_unpack } } } */ +/* { dg-final { cleanup-tree-dump "vect" } } */ + Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 202572) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2013-09-13 Cong Hou + + * gcc.dg/vect/vect-reduc-dot-s16c.c: Add a test case with dot product + on two arrays with short and int types. This should not be recognized + as a dot product pattern. + 2013-09-13 Kai Tietz gcc.target/i386/pr57848.c: New file.