From patchwork Fri Nov 3 16:26:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Sandiford X-Patchwork-Id: 117947 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp3661301qgn; Fri, 3 Nov 2017 09:27:02 -0700 (PDT) X-Google-Smtp-Source: ABhQp+QJ3cvaM6TvdyV+qFubWdaz7+swuWbzTtrFeY+ehHQPmFGF6ufy7cyVsdzNbhrUkiUX7ZGr X-Received: by 10.98.210.129 with SMTP id c123mr8276803pfg.77.1509726422334; Fri, 03 Nov 2017 09:27:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509726422; cv=none; d=google.com; s=arc-20160816; b=cLGfsD9Jl+Zv3z6b/7UpVeRXXIaeyKHVVY3zR8i1LJXdZS5LW8sWrTeEh9ySVMG/Pt OMAKQHRqHMKQydF8YmxMI8pQAUziJ1bbkabrnC71pK8RpjDy8W3SP0AtWBheO2f9kTEh aPpO6MuqBhHRDk50DdaZIHQ18/us6KneUjsSiZAwbQrhIPFFJ6IZ9fC+QmRmWCpW789w Z4GGQn9IFLvbyVINPb5VZME0AJpIoGlHsGCQV3Ye5oPNG/0I73DN8uycht1fpYEjPXNp QdeYIiBbrII6u8+OSETaa4Y1ZxMhNL8dmX8Qc7FJPJIY9ezax0PmE5A1/4Q5mi6lpiFS pWOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:user-agent:message-id:date:subject:mail-followup-to:to :from:delivered-to:sender:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:mailing-list:dkim-signature :domainkey-signature:arc-authentication-results; bh=4/drZhOh9eYSAmY6JBEvBcrlF5iUJ7wctcRD9lMkepQ=; b=z+8rcLV1CmploOMerp5htg2uF5Do8MpIh9taj9zx95FVwvcpYU3+qIMugKWk+C06SZ fKZj7Fm5nTRru/1bLgQ1fj5SK4ZWzsC2Rs06eP2kUsc9pQB/553Hd0XBB8O2Z5bsUwm0 mHJNsewJouWcVEd5c3wz5F6dKrzMnrWZuhCTr+bC6/+vrYxvY2eQqwej6JsS/bKZTefj T6SiU0X51RL3lzdW9nOasw1AUFA1PP0HSfIKDvXXn8U4IiOs5IEfEOxI5tUqx9phuwie nQgsHdnQfZH0BoDCkpwe7jC9egvnOn+wzpyDSVHr/tUtmXAGbYpHO/CGRiaP9Iv3BvE/ 3XlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nTxdBGTX; spf=pass (google.com: domain of gcc-patches-return-465882-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465882-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id i8si6315241pgq.66.2017.11.03.09.27.02 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 03 Nov 2017 09:27:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-465882-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=nTxdBGTX; spf=pass (google.com: domain of gcc-patches-return-465882-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-465882-patch=linaro.org@gcc.gnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=yU+KZh2Rk6sWDiasLe6Hms5vIcfHpQTaQudBQCAswpRPa6P/oi1sv WXTQd3902GLNysRRtQvXaleCWoDEeQIOylxB2wGA9Jx5MtH7yOoEMo0x5TlF+HvZ HKXG8/h2VtOvonlmlZ+G87LUkqYpYUiMbuJ/7CIAA4p3MdOuXAiS/o= 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:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=utxNOqMHwyc045DOnDGl8qM/Rhk=; b=nTxdBGTXS0wa1c6BLqwY n0cYSY+UEmyEO2jBMUjqXwVHvy7+6CkuwiB5CGeQn2jGTfNr41FS2IeAQ8Dlp7Gm wfmp+O7CvwnEGAtfF9joAyyF0767puodFxNtgnlV3F73R1Fzx2bXnshXOHk3GCxi laoigLEl820gXdSTC6VzjtI= Received: (qmail 95250 invoked by alias); 3 Nov 2017 16:26:48 -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 94627 invoked by uid 89); 3 Nov 2017 16:26:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=isolation, sk:search_ X-HELO: mail-wr0-f178.google.com Received: from mail-wr0-f178.google.com (HELO mail-wr0-f178.google.com) (209.85.128.178) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 03 Nov 2017 16:26:46 +0000 Received: by mail-wr0-f178.google.com with SMTP id y9so2989284wrb.2 for ; Fri, 03 Nov 2017 09:26:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:mail-followup-to:subject:date:message-id :user-agent:mime-version; bh=4/drZhOh9eYSAmY6JBEvBcrlF5iUJ7wctcRD9lMkepQ=; b=SCaQ84jTPgTz1UNLlNcWYfZ0znqGL7/N5h9AVUHiJHPNiP3R1fr66MK1Kf33wwLFNv 6pto4QDTca6pFOZKGbpZm0F/nny69obAANJh0aIpriPAgnt4WcYKRWuyBATB8nfyn48Q CnOXMVsWBtHUqz+matjgGlXplv2TOWU9V2QJp8pCuwpzUVjTekOqg+S5I4SBhHWEcvpl RyZr2FpF+CVTpD2nE9HEO5kVl102mPt7+tqV1GOqjr2Rr3IoSH0gmmLpUlAwQ0VXOwtS 4/5HSLs2jp5F5wWVFWS//3hdYN9i6UmCJI14BK2TiX+Z7BXoVEKWtlq8aFp0K0LUWWYC /LHA== X-Gm-Message-State: AMCzsaVjj2XzLbkwKzMO559BcgzUEMf2Nxz18l0yJCLeTUyJnGMKc51/ ZIloL8rfVWWSYIYsFjpNRhvVPDVNL7A= X-Received: by 10.223.142.208 with SMTP id q74mr7151351wrb.172.1509726404505; Fri, 03 Nov 2017 09:26:44 -0700 (PDT) Received: from localhost (188.29.164.162.threembb.co.uk. [188.29.164.162]) by smtp.gmail.com with ESMTPSA id 71sm4412758wmg.0.2017.11.03.09.26.43 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 03 Nov 2017 09:26:43 -0700 (PDT) From: Richard Sandiford To: gcc-patches@gcc.gnu.org Mail-Followup-To: gcc-patches@gcc.gnu.org, richard.sandiford@linaro.org Subject: Improve vectorisation of COND_EXPR Date: Fri, 03 Nov 2017 16:26:41 +0000 Message-ID: <874lqbpbum.fsf@linaro.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) MIME-Version: 1.0 This patch allows us to recognise: ... = bool1 != bool2 ? x : y as equivalent to: bool tmp = bool1 ^ bool2; ... = tmp ? x : y For the latter we were already able to find the natural number of vector units for tmp based on the types that feed bool1 and bool2, whereas with the former we would simply treat bool1 and bool2 as vectorised 8-bit values, possibly requiring them to be packed and unpacked from their natural width. This is used by a later SVE patch. 2017-11-03 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree-vect-patterns.c (vect_recog_mask_conversion_pattern): When handling COND_EXPRs with boolean comparisons, try to find a better basis for the mask type than the boolean itself. Index: gcc/tree-vect-patterns.c =================================================================== --- gcc/tree-vect-patterns.c 2017-11-03 12:17:34.392744807 +0000 +++ gcc/tree-vect-patterns.c 2017-11-03 12:17:36.313554835 +0000 @@ -3968,15 +3968,43 @@ vect_recog_mask_conversion_pattern (vec< return NULL; } else if (COMPARISON_CLASS_P (rhs1)) - rhs1_type = TREE_TYPE (TREE_OPERAND (rhs1, 0)); + { + /* Check whether we're comparing scalar booleans and (if so) + whether a better mask type exists than the mask associated + with boolean-sized elements. This avoids unnecessary packs + and unpacks if the booleans are set from comparisons of + wider types. E.g. in: + + int x1, x2, x3, x4, y1, y1; + ... + bool b1 = (x1 == x2); + bool b2 = (x3 == x4); + ... = b1 == b2 ? y1 : y2; + + it is better for b1 and b2 to use the mask type associated + with int elements rather bool (byte) elements. */ + rhs1_type = search_type_for_mask (TREE_OPERAND (rhs1, 0), vinfo); + if (!rhs1_type) + rhs1_type = TREE_TYPE (TREE_OPERAND (rhs1, 0)); + } else return NULL; vectype2 = get_mask_type_for_scalar_type (rhs1_type); - if (!vectype1 || !vectype2 - || must_eq (TYPE_VECTOR_SUBPARTS (vectype1), - TYPE_VECTOR_SUBPARTS (vectype2))) + if (!vectype1 || !vectype2) + return NULL; + + /* Continue if a conversion is needed. Also continue if we have + a comparison whose vector type would normally be different from + VECTYPE2 when considered in isolation. In that case we'll + replace the comparison with an SSA name (so that we can record + its vector type) and behave as though the comparison was an SSA + name from the outset. */ + if (must_eq (TYPE_VECTOR_SUBPARTS (vectype1), + TYPE_VECTOR_SUBPARTS (vectype2)) + && (TREE_CODE (rhs1) == SSA_NAME + || rhs1_type == TREE_TYPE (TREE_OPERAND (rhs1, 0)))) return NULL; /* If rhs1 is a comparison we need to move it into a @@ -3993,7 +4021,11 @@ vect_recog_mask_conversion_pattern (vec< append_pattern_def_seq (stmt_vinfo, pattern_stmt); } - tmp = build_mask_conversion (rhs1, vectype1, stmt_vinfo, vinfo); + if (may_ne (TYPE_VECTOR_SUBPARTS (vectype1), + TYPE_VECTOR_SUBPARTS (vectype2))) + tmp = build_mask_conversion (rhs1, vectype1, stmt_vinfo, vinfo); + else + tmp = rhs1; lhs = vect_recog_temp_ssa_var (TREE_TYPE (lhs), NULL); pattern_stmt = gimple_build_assign (lhs, COND_EXPR, tmp,