From patchwork Thu Nov 1 15:44:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marc Glisse X-Patchwork-Id: 196258 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]) by ozlabs.org (Postfix) with SMTP id AFE092C034A for ; Fri, 2 Nov 2012 02:44:56 +1100 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1352389497; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Date:From:To:Subject:Message-ID:User-Agent:MIME-Version: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=P/HhF9/ qawNVDwIXG6t9U9qaJhI=; b=E88SaKNHh8G77A7KstcoQ7Wl8ET41q95lsHHzGb t7bGwiUHCh5nylxiMfDoe8e9bX6ITieuBdE+zYBm+bR1lDJlzpciwStiOA6aduTu aXvO3FeyIVIaLs1JBGI5ndUZqg82Y2wfhlelfXqxj1NoDwTxgaTxTZ3+MwD6qo7A BUcM= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Date:From:To:Subject:Message-ID:User-Agent:MIME-Version:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=cu94zSB4CCu5LzqX7DVyOBR/GhB3ew9VCcKjxjsWWz18TCuUKPVJHawkQr3teW LFWEbtZpjvNmBImJ6cA/xoWdpxuqwtEMjPllkKJBWZmwZjINGdqRki+SriuIoqMH E0Y2IIBrtIOooJ1O9nnWwnmlLCxELNFcGZU0Rb5/MlPnY=; Received: (qmail 28040 invoked by alias); 1 Nov 2012 15:44:49 -0000 Received: (qmail 28031 invoked by uid 22791); 1 Nov 2012 15:44:48 -0000 X-SWARE-Spam-Status: No, hits=-7.5 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, TW_AV, TW_TM X-Spam-Check-By: sourceware.org Received: from mail4-relais-sop.national.inria.fr (HELO mail4-relais-sop.national.inria.fr) (192.134.164.105) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 01 Nov 2012 15:44:40 +0000 Received: from stedding.saclay.inria.fr ([193.55.250.194]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES128-SHA; 01 Nov 2012 16:44:38 +0100 Received: from glisse (helo=localhost) by stedding.saclay.inria.fr with local-esmtp (Exim 4.80) (envelope-from ) id 1TTwwg-0002a9-Gf for gcc-patches@gcc.gnu.org; Thu, 01 Nov 2012 16:44:38 +0100 Date: Thu, 1 Nov 2012 16:44:38 +0100 (CET) From: Marc Glisse To: gcc-patches@gcc.gnu.org Subject: Lower unsupported VEC_COND_EXPR Message-ID: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 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 Hello, this patch adds support for VEC_COND_EXPR to tree-vect-generic.c. It doesn't try to use vectors of smaller size and jumps straight to elementwise operations, so there is margin for improvements, but it seemed better to have something asap that at least compiles. For the testsuite: the restrictions in vector19.C were useless, they dated from a version that didn't test for errors. The new testcase is for my previous patch, but needed this one. I noticed 2 things while working on this patch: * there is no dead code elimination after the last forwprop pass * constant propagation doesn't really work for vectors bootstrap+testsuite on x86_64-linux, some manual tests with -m32 -march=i486. 2012-11-01 Marc Glisse PR middle-end/55001 gcc/ tree-vect-generic.c (expand_vector_condition): New function. (expand_vector_operations_1): Call it. testsuite/ g++.dg/ext/vector19.C: Remove target restrictions. gcc.dg/fold-compare-7.c: New testcase. Index: gcc/testsuite/gcc.dg/fold-compare-7.c =================================================================== --- gcc/testsuite/gcc.dg/fold-compare-7.c (revision 0) +++ gcc/testsuite/gcc.dg/fold-compare-7.c (revision 0) @@ -0,0 +1,8 @@ +/* { dg-do compile } */ +/* { dg-options "-O2" } */ + +typedef float vecf __attribute__((vector_size(8*sizeof(float)))); + +long f(vecf *f1, vecf *f2){ + return ((*f1 == *f2) < 0)[2]; +} Property changes on: gcc/testsuite/gcc.dg/fold-compare-7.c ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision URL Added: svn:eol-style + native Index: gcc/testsuite/g++.dg/ext/vector19.C =================================================================== --- gcc/testsuite/g++.dg/ext/vector19.C (revision 193060) +++ gcc/testsuite/g++.dg/ext/vector19.C (working copy) @@ -1,15 +1,12 @@ -/* { dg-do compile { target i?86-*-* x86_64-*-* } } */ -/* { dg-options "-std=c++11 -mavx2" } */ - -// The target restrictions and the -mavx2 flag are meant to disappear -// once vector lowering is in place. +/* { dg-do compile } */ +/* { dg-options "-std=c++11" } */ typedef double vec __attribute__((vector_size(2*sizeof(double)))); typedef signed char vec2 __attribute__((vector_size(16))); typedef unsigned char vec2u __attribute__((vector_size(16))); void f (vec *x, vec *y, vec *z) { *x = (*y < *z) ? *x : *y; } Index: gcc/tree-vect-generic.c =================================================================== --- gcc/tree-vect-generic.c (revision 193060) +++ gcc/tree-vect-generic.c (working copy) @@ -861,20 +861,86 @@ expand_vector_divmod (gimple_stmt_iterat || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing) return NULL_TREE; tem = gimplify_build2 (gsi, MULT_EXPR, type, cur_op, op1); op = optab_for_tree_code (MINUS_EXPR, type, optab_default); if (op == unknown_optab || optab_handler (op, TYPE_MODE (type)) == CODE_FOR_nothing) return NULL_TREE; return gimplify_build2 (gsi, MINUS_EXPR, type, op0, tem); } +/* Expand a vector condition to scalars, by using many conditions + on the vector's elements. */ +static void +expand_vector_condition (gimple_stmt_iterator *gsi) +{ + gimple stmt = gsi_stmt (*gsi); + tree type = gimple_expr_type (stmt); + tree a = gimple_assign_rhs1 (stmt); + tree a1 = a; + tree a2; + bool a_is_comparison = false; + tree b = gimple_assign_rhs2 (stmt); + tree c = gimple_assign_rhs3 (stmt); + VEC(constructor_elt,gc) *v; + tree constr; + tree inner_type = TREE_TYPE (type); + tree cond_type = TREE_TYPE (TREE_TYPE (a)); + tree comp_inner_type = cond_type; + tree width = TYPE_SIZE (inner_type); + tree index = bitsize_int (0); + int nunits = TYPE_VECTOR_SUBPARTS (type); + int i; + location_t loc = gimple_location (gsi_stmt (*gsi)); + + if (TREE_CODE (a) != SSA_NAME) + { + gcc_assert (COMPARISON_CLASS_P (a)); + a_is_comparison = true; + a1 = TREE_OPERAND (a, 0); + a2 = TREE_OPERAND (a, 1); + comp_inner_type = TREE_TYPE (TREE_TYPE (a1)); + } + + if (expand_vec_cond_expr_p (type, TREE_TYPE (a1))) + return; + + /* TODO: try and find a smaller vector type. */ + + warning_at (loc, OPT_Wvector_operation_performance, + "vector condition will be expanded piecewise"); + + v = VEC_alloc(constructor_elt, gc, nunits); + for (i = 0; i < nunits; + i++, index = int_const_binop (PLUS_EXPR, index, width)) + { + tree aa, result; + tree bb = tree_vec_extract (gsi, inner_type, b, width, index); + tree cc = tree_vec_extract (gsi, inner_type, c, width, index); + if (a_is_comparison) + { + tree aa1 = tree_vec_extract (gsi, comp_inner_type, a1, width, index); + tree aa2 = tree_vec_extract (gsi, comp_inner_type, a2, width, index); + aa = build2 (TREE_CODE (a), cond_type, aa1, aa2); + } + else + aa = tree_vec_extract (gsi, cond_type, a, width, index); + result = gimplify_build3 (gsi, COND_EXPR, inner_type, aa, bb, cc); + constructor_elt ce = {NULL_TREE, result}; + VEC_quick_push (constructor_elt, v, ce); + } + + constr = build_constructor (type, v); + gimple_assign_set_rhs_from_tree (gsi, constr); + update_stmt (gsi_stmt (*gsi)); +} + static tree expand_vector_operation (gimple_stmt_iterator *gsi, tree type, tree compute_type, gimple assign, enum tree_code code) { enum machine_mode compute_mode = TYPE_MODE (compute_type); /* If the compute mode is not a vector mode (hence we are not decomposing a BLKmode vector to smaller, hardware-supported vectors), we may want to expand the operations in parallel. */ if (GET_MODE_CLASS (compute_mode) != MODE_VECTOR_INT @@ -1241,20 +1307,25 @@ expand_vector_operations_1 (gimple_stmt_ code = gimple_assign_rhs_code (stmt); rhs_class = get_gimple_rhs_class (code); lhs = gimple_assign_lhs (stmt); if (code == VEC_PERM_EXPR) { lower_vec_perm (gsi); return; } + if (code == VEC_COND_EXPR) + { + expand_vector_condition (gsi); + return; + } if (rhs_class != GIMPLE_UNARY_RHS && rhs_class != GIMPLE_BINARY_RHS) return; rhs1 = gimple_assign_rhs1 (stmt); type = gimple_expr_type (stmt); if (rhs_class == GIMPLE_BINARY_RHS) rhs2 = gimple_assign_rhs2 (stmt); if (TREE_CODE (type) != VECTOR_TYPE) return;