From patchwork Fri Sep 28 11:31:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 187772 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 EF4AD2C0082 for ; Fri, 28 Sep 2012 21:31:49 +1000 (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=1349436710; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Received:Received:Date:From:To:Subject:Message-ID:Reply-To: MIME-Version:Content-Type:Content-Disposition:User-Agent: Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:Sender:Delivered-To; bh=97fXH5bYa/r80QcJu106 bO/T2lk=; b=S6GKPF0646LNJN+n5I+YV1HLvYiefzL+JmZHL1xakd6svNg36pc2 AnLOr5bB1kW1IUwANFiNc3x3IwzT31vw5YkhDOR3ZEV7WoA0xdz87zWmmMNbT/de D+j5fEVHhX6eip7ELM/H6Gn8FACvvvFDHb0/ZioQre+xhP0LtIVP4so= 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:Received:Received:Date:From:To:Subject:Message-ID:Reply-To:MIME-Version:Content-Type:Content-Disposition:User-Agent:X-IsSubscribed:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=OpFvDDJfbVs+h9Kx7VQL+lb84cliDLWa/Y4EUKTRqvx1KYZJVfy39xHebH0sz7 /8Pf7IZP+hPRfyhPZuO9tCHI0r3wQnDqxq7zEhVSwdqViAg07na6n1l9qiV1EtTQ pUKOZMPGKQKSKWwpuoF5lYbMmaSztEsp7rMAhusjfyTfw=; Received: (qmail 20542 invoked by alias); 28 Sep 2012 11:31:45 -0000 Received: (qmail 20534 invoked by uid 22791); 28 Sep 2012 11:31:44 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 28 Sep 2012 11:31:37 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8SBVb1i015931 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 28 Sep 2012 07:31:37 -0400 Received: from zalov.redhat.com (vpn1-4-56.ams2.redhat.com [10.36.4.56]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8SBVWJK014536 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Fri, 28 Sep 2012 07:31:36 -0400 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id q8SBVSix029603 for ; Fri, 28 Sep 2012 13:31:28 +0200 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id q8SBVRJC029602 for gcc-patches@gcc.gnu.org; Fri, 28 Sep 2012 13:31:27 +0200 Date: Fri, 28 Sep 2012 13:31:26 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up vector CONSTRUCTOR handling (PR tree-optimization/54713) Message-ID: <20120928113126.GC1787@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! As discussed in the PR, tree-vect-generic.c sometimes creates CONSTRUCTORs with vector elements to build up larger vectors from vectors supported by HW. This patch teaches fold-const to bail up on those. Vector CONSTRUCTOR verification changes and assorted fixes have been separated from the patch and will be posted probably next week. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2012-09-28 Jakub Jelinek PR tree-optimization/54713 * fold-const.c (vec_cst_ctor_to_array): Give up if vector CONSTRUCTOR has vector elements. (fold_ternary_loc) : Likewise. * tree-vect-generic.c (vector_element): Don't rely on CONSTRUCTOR elts indexes. Use BIT_FIELD_REF if CONSTRUCTOR has vector elements. (lower_vec_perm): Use NULL_TREE CONSTRUCTOR indexes. * gcc.c-torture/compile/pr54713-1.c: New test. * gcc.c-torture/compile/pr54713-2.c: New test. * gcc.c-torture/compile/pr54713-3.c: New test. Jakub --- gcc/fold-const.c.jj 2012-09-25 11:59:43.000000000 +0200 +++ gcc/fold-const.c 2012-09-26 13:14:05.639000395 +0200 @@ -9559,7 +9559,7 @@ vec_cst_ctor_to_array (tree arg, tree *e constructor_elt *elt; FOR_EACH_VEC_ELT (constructor_elt, CONSTRUCTOR_ELTS (arg), i, elt) - if (i >= nelts) + if (i >= nelts || TREE_CODE (TREE_TYPE (elt->value)) == VECTOR_TYPE) return false; else elts[i] = elt->value; @@ -14030,22 +14030,35 @@ fold_ternary_loc (location_t loc, enum t unsigned i; if (CONSTRUCTOR_NELTS (arg0) == 0) return build_constructor (type, NULL); - vals = VEC_alloc (constructor_elt, gc, n); - for (i = 0; i < n && idx + i < CONSTRUCTOR_NELTS (arg0); - ++i) - CONSTRUCTOR_APPEND_ELT (vals, NULL_TREE, - CONSTRUCTOR_ELT - (arg0, idx + i)->value); - return build_constructor (type, vals); + if (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (arg0, + 0)->value)) + != VECTOR_TYPE) + { + vals = VEC_alloc (constructor_elt, gc, n); + for (i = 0; + i < n && idx + i < CONSTRUCTOR_NELTS (arg0); + ++i) + CONSTRUCTOR_APPEND_ELT (vals, NULL_TREE, + CONSTRUCTOR_ELT + (arg0, idx + i)->value); + return build_constructor (type, vals); + } } } else if (n == 1) { if (TREE_CODE (arg0) == VECTOR_CST) return VECTOR_CST_ELT (arg0, idx); - else if (idx < CONSTRUCTOR_NELTS (arg0)) - return CONSTRUCTOR_ELT (arg0, idx)->value; - return build_zero_cst (type); + else if (CONSTRUCTOR_NELTS (arg0) == 0) + return build_zero_cst (type); + else if (TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (arg0, + 0)->value)) + != VECTOR_TYPE) + { + if (idx < CONSTRUCTOR_NELTS (arg0)) + return CONSTRUCTOR_ELT (arg0, idx)->value; + return build_zero_cst (type); + } } } } --- gcc/tree-vect-generic.c.jj 2012-09-18 12:14:48.000000000 +0200 +++ gcc/tree-vect-generic.c 2012-09-26 14:23:40.742171292 +0200 @@ -1050,14 +1050,13 @@ vector_element (gimple_stmt_iterator *gs if (TREE_CODE (vect) == VECTOR_CST) return VECTOR_CST_ELT (vect, index); - else if (TREE_CODE (vect) == CONSTRUCTOR) + else if (TREE_CODE (vect) == CONSTRUCTOR + && (CONSTRUCTOR_NELTS (vect) == 0 + || TREE_CODE (TREE_TYPE (CONSTRUCTOR_ELT (vect, 0)->value)) + != VECTOR_TYPE)) { - unsigned i; - tree elt_i, elt_v; - - FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (vect), i, elt_i, elt_v) - if (operand_equal_p (elt_i, idx, 0)) - return elt_v; + if (index < CONSTRUCTOR_NELTS (vect)) + return CONSTRUCTOR_ELT (vect, index)->value; return build_zero_cst (vect_elt_type); } else @@ -1215,7 +1214,7 @@ lower_vec_perm (gimple_stmt_iterator *gs t = v0_val; } - CONSTRUCTOR_APPEND_ELT (v, si, t); + CONSTRUCTOR_APPEND_ELT (v, NULL_TREE, t); } constr = build_constructor (vect_type, v); --- gcc/testsuite/gcc.c-torture/compile/pr54713-1.c.jj 2012-09-26 14:25:00.560733901 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr54713-1.c 2012-09-26 12:10:09.000000000 +0200 @@ -0,0 +1,70 @@ +/* PR tree-optimization/54713 */ + +#ifndef N +#define N 8 +#define ONE 1, 1, 1, 1, 1, 1, 1, 1 +#define ONEU 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U +#endif + +typedef int V __attribute__((vector_size (N * sizeof (int)))); +typedef unsigned int W __attribute__((vector_size (N * sizeof (int)))); + +void +f1 (V *p) +{ + *p = (*p & ((V) { ONE })) ^ ((V) { ONE}); +} + +void +f2 (V *p) +{ + *p = (*p ^ ((V) { ONE })) & ((V) { ONE}); +} + +void +f3 (V *p) +{ + *p = (~*p) & ((V) { ONE }); +} + +void +f4 (V *p, V *q) +{ + *p = (*p ^ *q) == *q; +} + +void +f5 (V *p, V *q) +{ + *p = (*p ^ *q) == *p; +} + +void +f6 (V *p, V *q, V *r) +{ + *p = (*p & *r) == (*q & *r); +} + +void +f7 (V *p, V *q, V *r) +{ + *p = (*p & *r) == (*r & *q); +} + +void +f8 (V *p, V *q, V *r) +{ + *p = (*r & *p) == (*q & *r); +} + +void +f9 (V *p, V *q, V *r) +{ + *p = (*r & *p) == (*r & *q); +} + +void +f10 (W *p, W *q) +{ + *p = *p < (((const W) { ONEU }) << *q); +} --- gcc/testsuite/gcc.c-torture/compile/pr54713-2.c.jj 2012-09-26 14:25:03.273719043 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr54713-2.c 2012-09-26 12:11:40.000000000 +0200 @@ -0,0 +1,7 @@ +/* PR tree-optimization/54713 */ + +#define N 16 +#define ONE 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 +#define ONEU 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U + +#include "pr54713-1.c" --- gcc/testsuite/gcc.c-torture/compile/pr54713-3.c.jj 2012-09-26 14:25:06.202702978 +0200 +++ gcc/testsuite/gcc.c-torture/compile/pr54713-3.c 2012-09-26 12:11:31.000000000 +0200 @@ -0,0 +1,9 @@ +/* PR tree-optimization/54713 */ + +#define N 32 +#define ONE 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 +#define ONEU 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, \ + 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U, 1U + +#include "pr54713-1.c"