From patchwork Tue Nov 29 07:02:24 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ira Rosen X-Patchwork-Id: 5338 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 2EE5624017 for ; Tue, 29 Nov 2011 07:02:29 +0000 (UTC) Received: from mail-lpp01m010-f52.google.com (mail-lpp01m010-f52.google.com [209.85.215.52]) by fiordland.canonical.com (Postfix) with ESMTP id 0CDE2A18040 for ; Tue, 29 Nov 2011 07:02:29 +0000 (UTC) Received: by laah2 with SMTP id h2so1175536laa.11 for ; Mon, 28 Nov 2011 23:02:28 -0800 (PST) Received: by 10.152.135.179 with SMTP id pt19mr30250914lab.47.1322550148703; Mon, 28 Nov 2011 23:02:28 -0800 (PST) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.152.41.198 with SMTP id h6cs26513lal; Mon, 28 Nov 2011 23:02:28 -0800 (PST) Received: by 10.236.181.164 with SMTP id l24mr69142035yhm.22.1322550145814; Mon, 28 Nov 2011 23:02:25 -0800 (PST) Received: from mail-yw0-f50.google.com (mail-yw0-f50.google.com [209.85.213.50]) by mx.google.com with ESMTPS id c48si827199yhm.133.2011.11.28.23.02.25 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 28 Nov 2011 23:02:25 -0800 (PST) Received-SPF: neutral (google.com: 209.85.213.50 is neither permitted nor denied by best guess record for domain of ira.rosen@linaro.org) client-ip=209.85.213.50; Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.213.50 is neither permitted nor denied by best guess record for domain of ira.rosen@linaro.org) smtp.mail=ira.rosen@linaro.org Received: by ywb26 with SMTP id 26so5756356ywb.37 for ; Mon, 28 Nov 2011 23:02:25 -0800 (PST) MIME-Version: 1.0 Received: by 10.68.56.73 with SMTP id y9mr61980147pbp.9.1322550144866; Mon, 28 Nov 2011 23:02:24 -0800 (PST) Received: by 10.142.69.4 with HTTP; Mon, 28 Nov 2011 23:02:24 -0800 (PST) Date: Tue, 29 Nov 2011 09:02:24 +0200 Message-ID: Subject: [patch] Fix PR tree-optimization/51301 From: Ira Rosen To: gcc-patches@gcc.gnu.org Cc: Patch Tracking Hi, In vectorizer's over-widening pattern recognition the last statement is expected to be a type demotion, but the check for that was incomplete. We now check that the resulting type is not bigger than the original type of the computation. Bootstrapped and tested on powerpc64-suse-linux, tested on arm-linux-gnueabi (cross). Committed. Ira ChangeLog: PR tree-optimization/51301 * tree-vect-patterns.c (vect_recog_over_widening_pattern): Check that the last statement doesn't convert to a bigger type than the original type of the computation. testsuite/ChangeLog: PR tree-optimization/51301 * gcc.dg/vect/pr51301.c: New test. Index: tree-vect-patterns.c =================================================================== --- tree-vect-patterns.c (revision 181796) +++ tree-vect-patterns.c (working copy) @@ -1088,6 +1088,7 @@ vect_recog_over_widening_pattern (VEC (gimple, hea tree var = NULL_TREE, new_type = NULL_TREE, tmp, new_oprnd; bool first; struct loop *loop = (gimple_bb (stmt))->loop_father; + tree type = NULL; first = true; while (1) @@ -1150,6 +1151,7 @@ vect_recog_over_widening_pattern (VEC (gimple, hea print_gimple_stmt (vect_dump, pattern_stmt, 0, TDF_SLIM); } + type = gimple_expr_type (stmt); prev_stmt = stmt; stmt = use_stmt; @@ -1165,9 +1167,11 @@ vect_recog_over_widening_pattern (VEC (gimple, hea { use_lhs = gimple_assign_lhs (use_stmt); use_type = TREE_TYPE (use_lhs); - /* Support only type promotion or signedess change. */ + /* Support only type promotion or signedess change. Check that USE_TYPE + is not bigger than the original type. */ if (!INTEGRAL_TYPE_P (use_type) - || TYPE_PRECISION (new_type) > TYPE_PRECISION (use_type)) + || TYPE_PRECISION (new_type) > TYPE_PRECISION (use_type) + || TYPE_PRECISION (type) < TYPE_PRECISION (use_type)) return NULL; if (TYPE_UNSIGNED (new_type) != TYPE_UNSIGNED (use_type) Index: testsuite/gcc.dg/vect/pr51301.c =================================================================== --- testsuite/gcc.dg/vect/pr51301.c (revision 0) +++ testsuite/gcc.dg/vect/pr51301.c (revision 0) @@ -0,0 +1,15 @@ +/* { dg-do compile } */ + +typedef signed char int8_t; +typedef signed long long int64_t; +int64_t +f0a (int8_t * __restrict__ arg1) +{ + int idx; + int64_t result = 0; + for (idx = 0; idx < 416; idx += 1) + result += arg1[idx] << (arg1[idx] == arg1[idx]); + return result; +} + +/* { dg-final { cleanup-tree-dump "vect" } } */