From patchwork Tue Nov 22 14:30:56 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 127086 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 B64A61007D1 for ; Wed, 23 Nov 2011 01:31:18 +1100 (EST) Received: (qmail 22731 invoked by alias); 22 Nov 2011 14:31:16 -0000 Received: (qmail 22721 invoked by uid 22791); 22 Nov 2011 14:31:15 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM 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; Tue, 22 Nov 2011 14:30:59 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pAMEUxk5007265 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 22 Nov 2011 09:30:59 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pAMEUwYW007441 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 22 Nov 2011 09:30:59 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id pAMEUwSX013055; Tue, 22 Nov 2011 15:30:58 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id pAMEUuaf013053; Tue, 22 Nov 2011 15:30:56 +0100 Date: Tue, 22 Nov 2011 15:30:56 +0100 From: Jakub Jelinek To: Richard Henderson , Richard Guenther Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up VEC_INTERLEAVE_*_EXPR folding and expansion for big endian (PR tree-optimization/51074) Message-ID: <20111122143056.GR27242@tyan-ft48-01.lab.bos.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! VEC_INTERLEAVE_*_EXPR trees are unfortunately dependent on BYTES_BIG_ENDIAN, what is HIGH vs. LOW is different based on endianity. The only place that creates these in the IL is: if (BYTES_BIG_ENDIAN) { high_code = VEC_INTERLEAVE_HIGH_EXPR; low_code = VEC_INTERLEAVE_LOW_EXPR; } else { low_code = VEC_INTERLEAVE_HIGH_EXPR; high_code = VEC_INTERLEAVE_LOW_EXPR; } perm_stmt = gimple_build_assign_with_ops (high_code, perm_dest, vect1, vect2); ... so either folding (and expansion if only vec_perm* is supported) needs to be adjusted as done in the patch below, or we'd need to rename them to VEC_INTERLEAVE_{FIRST,SECOND}_EXPR or similar and adjust all the patterns etc. Bootstrapped/regtested on x86_64-linux and i686-linux, tested on the testcase using powerpc cross. Ok for trunk? 2011-11-22 Jakub Jelinek PR tree-optimization/51074 * fold-const.c (fold_binary_loc): Fix up VEC_INTERLEAVE_*_EXPR handling for BYTES_BIG_ENDIAN. * optabs.c (can_vec_perm_for_code_p): Likewise. * gcc.dg/vect/pr51074.c: New test. Jakub --- gcc/fold-const.c.jj 2011-11-21 16:22:02.000000000 +0100 +++ gcc/fold-const.c 2011-11-22 09:59:15.606739333 +0100 @@ -13483,10 +13483,12 @@ fold_binary_loc (location_t loc, sel[i] = i * 2 + 1; break; case VEC_INTERLEAVE_HIGH_EXPR: - sel[i] = (i + nelts) / 2 + ((i & 1) ? nelts : 0); + sel[i] = (i + (BYTES_BIG_ENDIAN ? 0 : nelts)) / 2 + + ((i & 1) ? nelts : 0); break; case VEC_INTERLEAVE_LOW_EXPR: - sel[i] = i / 2 + ((i & 1) ? nelts : 0); + sel[i] = (i + (BYTES_BIG_ENDIAN ? nelts : 0)) / 2 + + ((i & 1) ? nelts : 0); break; default: gcc_unreachable (); --- gcc/optabs.c.jj 2011-11-21 16:22:02.000000000 +0100 +++ gcc/optabs.c 2011-11-22 10:17:04.820399126 +0100 @@ -6932,9 +6932,9 @@ can_vec_perm_for_code_p (enum tree_code break; case VEC_INTERLEAVE_HIGH_EXPR: - alt = nelt / 2; - /* FALLTHRU */ case VEC_INTERLEAVE_LOW_EXPR: + if ((BYTES_BIG_ENDIAN != 0) ^ (code == VEC_INTERLEAVE_HIGH_EXPR)) + alt = nelt / 2; for (i = 0; i < nelt / 2; ++i) { data[i * 2] = i + alt; --- gcc/testsuite/gcc.dg/vect/pr51074.c.jj 2011-11-22 10:22:44.247377928 +0100 +++ gcc/testsuite/gcc.dg/vect/pr51074.c 2011-11-22 10:22:16.000000000 +0100 @@ -0,0 +1,24 @@ +/* PR tree-optimization/51074 */ + +#include "tree-vect.h" + +struct S { int a, b; } s[8]; + +int +main () +{ + int i; + check_vect (); + for (i = 0; i < 8; i++) + { + s[i].b = 0; + s[i].a = i; + } + asm volatile ("" : : : "memory"); + for (i = 0; i < 8; i++) + if (s[i].b != 0 || s[i].a != i) + abort (); + return 0; +} + +/* { dg-final { cleanup-tree-dump "vect" } } */