From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2078) id 3CECB3858D39; Wed, 19 Oct 2022 06:13:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3CECB3858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666159980; bh=eve2uhWJ4sej/4b1BX4mB05K4u6IPC1MmOtah5VTViA=; h=From:To:Subject:Date:From; b=yH0XzA3KiRRdYSWC9zFud7Y+xQmC9zJ/5PUFGmosAWP2Pin22M0L82nI2CnFtIciL GQ04lCfGIVKhMWMIFXJa3TA2/67BVA+4pXhP1uTgFgX4nNC7oROy4uKeZxlakWm/e6 uHp+sNUXF/2iPYywH6J3qJOn5h9lzctjqmwJ2sm8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: hongtao Liu To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3368] Canonicalize vec_perm index to make the first index come from the first vector. X-Act-Checkin: gcc X-Git-Author: liuhongt X-Git-Refname: refs/heads/master X-Git-Oldrev: 21de009f741923bc2dcfaa80877b3725e90ab96c X-Git-Newrev: 1442e2031e0bc2d0a5bf88ef3c92c5410e044bab Message-Id: <20221019061300.3CECB3858D39@sourceware.org> Date: Wed, 19 Oct 2022 06:13:00 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1442e2031e0bc2d0a5bf88ef3c92c5410e044bab commit r13-3368-g1442e2031e0bc2d0a5bf88ef3c92c5410e044bab Author: liuhongt Date: Tue Oct 18 16:58:52 2022 +0800 Canonicalize vec_perm index to make the first index come from the first vector. Fix unexpected non-canon form from gimple vector selector. gcc/ChangeLog: PR target/107271 * config/i386/i386-expand.cc (ix86_vec_perm_index_canon): New. (expand_vec_perm_shufps_shufps): Call ix86_vec_perm_index_canon gcc/testsuite/ChangeLog: * gcc.target/i386/pr107271.c: New test. Diff: --- gcc/config/i386/i386-expand.cc | 17 +++++++++++++++++ gcc/testsuite/gcc.target/i386/pr107271.c | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index a0f8a98986e..70fd82b27d4 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -19604,6 +19604,22 @@ expand_vec_perm_1 (struct expand_vec_perm_d *d) return false; } +/* Canonicalize vec_perm index to make the first index + always comes from the first vector. */ +static void +ix86_vec_perm_index_canon (struct expand_vec_perm_d *d) +{ + unsigned nelt = d->nelt; + if (d->perm[0] < nelt) + return; + + for (unsigned i = 0; i != nelt; i++) + d->perm[i] = (d->perm[i] + nelt) % (2 * nelt); + + std::swap (d->op0, d->op1); + return; +} + /* A subroutine of ix86_expand_vec_perm_const_1. Try to implement D in terms of a pair of shufps+ shufps/pshufd instructions. */ static bool @@ -19621,6 +19637,7 @@ expand_vec_perm_shufps_shufps (struct expand_vec_perm_d *d) if (d->testing_p) return true; + ix86_vec_perm_index_canon (d); for (i = 0; i < 4; ++i) count += d->perm[i] > 3 ? 1 : 0; diff --git a/gcc/testsuite/gcc.target/i386/pr107271.c b/gcc/testsuite/gcc.target/i386/pr107271.c new file mode 100644 index 00000000000..fe89c9a5bef --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr107271.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-O0" } */ + +typedef int __attribute__((__vector_size__ (16))) V; + +static inline __attribute__((__always_inline__)) V +bar (V v128u32_0) +{ + return __builtin_shuffle ((V){}, v128u32_0, v128u32_0); +} + +V +foo (void) +{ + return bar ((V){7, 4, 4}); +}