From patchwork Thu Jun 5 15:29:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Evgeny Stupachenko X-Patchwork-Id: 356509 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 976D0140093 for ; Fri, 6 Jun 2014 01:29:27 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:date:message-id:subject:from:to:content-type; q= dns; s=default; b=BqFZ96xpWVIKJvLeNCQTc/HnIbGqUde7Bk/YcYTWUL3cPu 5IWcEbWZeNP0fYLxiQ4rRJXeVGFeA1eJwSrqggiHZU/jV0GFBQeaqpFZui6nSAQx XLHdtj2RFW5dnHInEFnro5p0C2vNHg6o69ewt036bHafAks7aXEMpBhHQ31kE= 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 :mime-version:date:message-id:subject:from:to:content-type; s= default; bh=u1fM9iS79XdtPi9Z5j5mLA8lL4k=; b=uIhBwdPELxRhVVtIRZWr gLEtuZtTFPe80eIiBKEym+lLfAXVFTHNfnMfMp/w8z46DadP3bHiHp/bu15QCeex 7sVV0mPnjsLKCQMP+PM8eRQJ1mYJSOEmWWNedzqOcB4w3pkQ2CSakdM0z8zAZbZB UwvGUV711aUdvUE7F+nJyHM= Received: (qmail 11635 invoked by alias); 5 Jun 2014 15:29: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 11622 invoked by uid 89); 5 Jun 2014 15:29:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-ob0-f172.google.com Received: from mail-ob0-f172.google.com (HELO mail-ob0-f172.google.com) (209.85.214.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 05 Jun 2014 15:29:18 +0000 Received: by mail-ob0-f172.google.com with SMTP id wp18so1305453obc.3 for ; Thu, 05 Jun 2014 08:29:16 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.182.245.164 with SMTP id xp4mr32154382obc.23.1401982156611; Thu, 05 Jun 2014 08:29:16 -0700 (PDT) Received: by 10.76.18.209 with HTTP; Thu, 5 Jun 2014 08:29:16 -0700 (PDT) Date: Thu, 5 Jun 2014 19:29:16 +0400 Message-ID: Subject: [PATCH, x86] Improves x86 permutation expand From: Evgeny Stupachenko To: Richard Henderson , Uros Bizjak , GCC Patches X-IsSubscribed: yes Hi, The patch passed bootstrap and make check. No new fails. The patch gives ~10% to test in pr52252 and potentially in pr61403. Is it ok? Thanks, Evgeny ChangeLog: 2014-06-05 Evgeny Stupachenko * config/i386/i386.c (expand_vec_perm_pblendv): New. Permutation expand using pblendv. * config/i386/i386.c (ix86_expand_vec_perm_const_1): New scheme for permutation expand. Patch: expand_vec_perm_d *d) if (expand_vec_perm_vperm2f128 (d)) return true; + if (expand_vec_perm_pblendv (d)) + return true; + /* Try sequences of three instructions. */ if (expand_vec_perm_2vperm2f128_vshuf (d)) diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index 8827256..e1c8126 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -43185,6 +43185,76 @@ expand_vec_perm_palignr (struct expand_vec_perm_d *d) return ok; } +/* A subroutine of ix86_expand_vec_perm_const_1. Try to simplify + the permutation using the SSE4_1 pblendv instruction. Potentially + reduces permutaion from 2 pshufb and or to 1 pshufb and pblendv. */ + +static bool +expand_vec_perm_pblendv (struct expand_vec_perm_d *d) +{ + unsigned i, which, nelt = d->nelt; + struct expand_vec_perm_d dcopy, dcopy1; + + /* Figure out where permutation elements stay not in their + respective lanes. */ + for (i = 0, which = 0; i < nelt; ++i) + { + unsigned e = d->perm[i]; + if (e != i) + which |= (e < nelt ? 1 : 2); + } + /* We can pblend the part where elements stay not in their + respective lanes only when these elements are all in one + half of a permutation. + {0 1 8 3 4 5 9 7} is ok as 8, 9 are not at their respective + lanes, but both 8 and 9 >= 8 + {0 1 8 3 4 5 2 7} is not ok as 2 and 8 are not at their + respective lanes and 8 >= 8, but 2 not. */ + if (which != 1 && which != 2) + return false; + + /* First we apply one operand permutation to the part where + elements stay not in their respective lanes. */ + dcopy = *d; + if (which == 2) + dcopy.op0 = dcopy.op1 = d->op1; + else + dcopy.op0 = dcopy.op1 = d->op0; + dcopy.one_operand_p = true; + + for (i = 0; i < nelt; ++i) + { + unsigned e = d->perm[i]; + if (which == 2) + dcopy.perm[i] = ((e >= nelt) ? (e - nelt) : e); + } + + if (!expand_vec_perm_1 (&dcopy)) + return false; + + /* Next we put permuted elements into thier positions. */ + dcopy1 = *d; + if (which == 2) + dcopy1.op1 = dcopy.target; + else + dcopy1.op0 = dcopy.target; + + for (i = 0; i < nelt; ++i) + { + unsigned e = d->perm[i]; + if (which == 2) + dcopy1.perm[i] = ((e >= nelt) ? (nelt + i) : e); + else + dcopy1.perm[i] = ((e < nelt) ? i : e); + } + + if (!expand_vec_perm_blend (&dcopy1)) + return false; + + return true; +} + static bool expand_vec_perm_interleave3 (struct expand_vec_perm_d *d); /* A subroutine of ix86_expand_vec_perm_builtin_1. Try to simplify @@ -44557,6 +44627,9 @@ ix86_expand_vec_perm_const_1 (struct