From patchwork Tue Jan 19 10:46:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Enkovich X-Patchwork-Id: 569920 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.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 21B6D140B99 for ; Tue, 19 Jan 2016 21:47:27 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=QQr+GO3E; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=JPWZrZGTfVddSqL386hrl23R5lUJyuDEV10i4rHTUOaNutfNtfXxO zrgXpd4BTp2KbADQlNXE+2Fq0rQnsYnROEcPSamIiSOWQv4dV+9sDaPhhaj8TjG+ zfDLSLp5NIdIZ37e1QszNmj76NTnHeDVZJcJoas/CmoTljV7Jr3wec= 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:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=b/qIiiobTw2nCLYSRC+e9Ha67Co=; b=QQr+GO3EI/ZEwTcCiPB3 yonl5CkZwBIFp8+UqaA6QHic8C1gYOOpNL9W1QhCE/QO1y3lV7Q/4T1ThAzaxNDb 8NbZUfMxZ/29+oV0WC9HMD+sc5vxyotuJcudi2mWDNwNbeKFp+mVisRNcr3ZiQnb EM+k3uTkC5lf+elrpj3xSPs= Received: (qmail 77224 invoked by alias); 19 Jan 2016 10:47:20 -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 77214 invoked by uid 89); 19 Jan 2016 10:47:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=enkovich.gnu@gmail.com, enkovichgnugmailcom, Hx-languages-length:2203 X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 19 Jan 2016 10:47:15 +0000 Received: by mail-wm0-f51.google.com with SMTP id u188so137643483wmu.1 for ; Tue, 19 Jan 2016 02:47:14 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:subject:message-id:mime-version :content-type:content-disposition:user-agent; bh=Dhzwk2abc0NajNRFwNzFiBnCk5pIuYCSBTKX/TdYv3Y=; b=hcvEpB98e6JOHftz4ztndDOSbsMc3HcrqfERc4BN0U3UoN28Ly5PcpmlElG5oa/AI0 //vbATd5PyxDtwDPhVhQuAI2+9DEBqjRDn/VIGVTPy3ADUMy+S6FnvCtlKTY3Qu+rqVO bI7ELhCFUpCep1++B9DA2BjSwgiAiEjUNRbFcCs84Ey9rkcRMT99c4E13uYYau6X2s9o Iai0AVnVZOGmwb2jf6vSNyZHAksDAeiOYyesq2A1WA5o9OGwOJqhbeb0c8P5J2flU7GL Kib2qEAwe3dyKvYEV7TOvJo+Y0qwI/m6kWiTN6mkJsWDulLbraHfCv0AUuLSB3KqPrNv jIRA== X-Gm-Message-State: AG10YORzsH/BQiIhxiFQmUwRWxFgnoJiskU6RNOCbLh0prAwF9bWGbX4eWLsvQ2aHQldOA== X-Received: by 10.28.140.142 with SMTP id o136mr17031861wmd.45.1453200432181; Tue, 19 Jan 2016 02:47:12 -0800 (PST) Received: from msticlxl57.ims.intel.com (irdmzpr02-ext.ir.intel.com. [192.198.151.37]) by smtp.gmail.com with ESMTPSA id bg1sm23600376wjc.27.2016.01.19.02.47.11 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jan 2016 02:47:11 -0800 (PST) Date: Tue, 19 Jan 2016 13:46:37 +0300 From: Ilya Enkovich To: gcc-patches@gcc.gnu.org Subject: [PATCH, PR tree-optimization/69328] Fix vectorization of boolean vector comparision in COND_EXPR Message-ID: <20160119104637.GB15775@msticlxl57.ims.intel.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) X-IsSubscribed: yes Hi, Currently vectorizer incorrectly handles a case when COND_EXPR has boolean vector comparison. Firstly masked COND_EXPR is determined incorrectly. Also we don't check vector types of compared values are compatible. This patch fixes these problems. Bootstrapped and regtested for x86_64-pc-linux-gnu. OK for trunk? Thanks, Ilya --- gcc/ 2016-01-19 Ilya Enkovich Richard Biener PR tree-optimization/69328 * tree-vect-stmts.c (vect_is_simple_cond): Check compared vectors have same number of elements. (vectorizable_condition): Fix masked version recognition. gcc/testsuite/ 2016-01-19 Ilya Enkovich PR tree-optimization/69328 * gcc.dg/pr69328.c: New test. diff --git a/gcc/testsuite/gcc.dg/pr69328.c b/gcc/testsuite/gcc.dg/pr69328.c new file mode 100644 index 0000000..a495596 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr69328.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ + +int a, b; +void fn1() { + int c; + char *d; + for (; a; ++a) { + int e, f; + e = d[a]; + if (!e && f || !f && e) + ++c; + } + if (c) + b = .499; +} diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 635c797..9d4d286 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -7441,6 +7441,10 @@ vect_is_simple_cond (tree cond, vec_info *vinfo, tree *comp_vectype) && TREE_CODE (rhs) != FIXED_CST) return false; + if (vectype1 && vectype2 + && TYPE_VECTOR_SUBPARTS (vectype1) != TYPE_VECTOR_SUBPARTS (vectype2)) + return false; + *comp_vectype = vectype1 ? vectype1 : vectype2; return true; } @@ -7544,13 +7548,9 @@ vectorizable_condition (gimple *stmt, gimple_stmt_iterator *gsi, if (!vect_is_simple_use (else_clause, stmt_info->vinfo, &def_stmt, &dt)) return false; - if (VECTOR_BOOLEAN_TYPE_P (comp_vectype)) - { - vec_cmp_type = comp_vectype; - masked = true; - } - else - vec_cmp_type = build_same_sized_truth_vector_type (comp_vectype); + masked = !COMPARISON_CLASS_P (cond_expr); + vec_cmp_type = build_same_sized_truth_vector_type (comp_vectype); + if (vec_cmp_type == NULL_TREE) return false;