From patchwork Thu Sep 12 01:16:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Hou X-Patchwork-Id: 274400 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 26CA62C00EA for ; Thu, 12 Sep 2013 11:17:03 +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:date:message-id:subject:from:to:cc:content-type; q=dns; s=default; b=vgOPqPDQhrdjNALVZrGfshaPuXj5KBm2phiFCokb/cg psVaeFmSuAWhdl+yogM6OmToPw8Chv9c2e6YWcuSCYREEN5Q9O8KLr4RmMbq/OJ9 R5sQCOl3COSMXBkziKo+X5JUXnt8J639zIJ1i1/SbuDsVDpKfUftWwssHHirIbYo = 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:date:message-id:subject:from:to:cc:content-type; s=default; bh=1Ef5hxtSYEyYjfxbFZUpaUVUMqk=; b=dfb4+mISGzAUsSDzw Bz85BB4ukupTe/3Earyrm2Kq2OU4RVHUUPBkXbDE3YaViVlJyWniZJScXOOuJYTj q6qFGDLIlySPVrO7IrNl04/uVVcUf4WFPjXgoyMRM0kRdiF2yeXG+GrZaE3F5NEp 7DDvoYBQ0vce+AV0A5SooU2xXM= Received: (qmail 30940 invoked by alias); 12 Sep 2013 01:16:55 -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 30931 invoked by uid 89); 12 Sep 2013 01:16:55 -0000 Received: from mail-ie0-f175.google.com (HELO mail-ie0-f175.google.com) (209.85.223.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 12 Sep 2013 01:16:55 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.6 required=5.0 tests=AWL, BAYES_00, NO_RELAYS autolearn=ham version=3.3.2 X-HELO: mail-ie0-f175.google.com Received: by mail-ie0-f175.google.com with SMTP id 9so6345001iec.6 for ; Wed, 11 Sep 2013 18:16:53 -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:date:message-id:subject:from:to:cc :content-type; bh=3WNpjn3YZ7SIIVBXKtgDbm8HMwDvrFAatKWa9UYfpOQ=; b=OTDF5ADtvhXiFK37Avxch2PAKaofGTSZbb+U2yuOM6P/A6KkD9iXxYMC6NGYEgLIDI l5U2hARunMcNJSGRFI6+DzpKMX1elZsRpwP0plUrye5Robnc2Qs/9TQds013ajnr6bcq gU4g4Kg98jngY+1XI8AD1jqdh9m+XmtGAS+eeGvt135os/1xpoy1DRjtXBkiKYfZiGEh IjwdCKOzv6ehWW+FQ4QPdCrYeEehQjBlxbc2buIzlunhW6WtMGkrTbV7GM2DAq62aitY heAfbP4mC7kObB4UpvvfdL66YocfsY6a8PfywY0J/Zar4FXmCTOF9Z2JdlqY84pEvHWO cOIg== X-Gm-Message-State: ALoCoQnfrjc2VRR0aEUGZ03Hif1ttR4dQ0cCw5lZ3tph88+c6FOP2t214HCSFBUu0mh26dDJRCo5/06wG7gLVeGYy3fEWXVkVj6TUUz8N2Sb/kGO8ULJH/0ZhsJNknNmnGpIoBUJHAsjWUU04BKHug93v/QuR0T6AgbBmMCRQ1DD8wHNcLLRUaZF3xTBCbcW6iVkwBbFKPKb9tzvWPMXTVth0Ms39ELGVA== MIME-Version: 1.0 X-Received: by 10.42.208.211 with SMTP id gd19mr954453icb.15.1378948613196; Wed, 11 Sep 2013 18:16:53 -0700 (PDT) Received: by 10.64.236.37 with HTTP; Wed, 11 Sep 2013 18:16:53 -0700 (PDT) Date: Wed, 11 Sep 2013 18:16:53 -0700 Message-ID: Subject: [PATCH] [vectorizer] Fixing a bug in tree-vect-patterns.c in GCC vectorizer. From: Cong Hou To: GCC Patches Cc: David Li 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;