From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2078) id CC9373858C2D; Tue, 11 Oct 2022 06:12:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC9373858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665468748; bh=6s+iNvKGdVXfmkMInlsd3ybGgzElVIthx/HSlP+D9iY=; h=From:To:Subject:Date:From; b=vaP657718+iT8qeQ5dBhYGsWIM/qpThGJxzysEwHGA4u4evoCJ7/1DMWD1/TtX9Ea Z3i3dfXjGtuJW2yhjzxTBs+Xppdoys0gvOaZHdVDDGmyzrkERfZL7BiA2tLbuXiU27 qCnPA88KpgdL/YaBWZvElH6yatwGljJP+KKbHmZ0= 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-3212] Optimize nested permutation to single VEC_PERM_EXPR [PR54346] X-Act-Checkin: gcc X-Git-Author: Liwei Xu X-Git-Refname: refs/heads/master X-Git-Oldrev: db24bdc743cf23ea12d2dcf8254d86ab366bb46d X-Git-Newrev: b88adba751da635c6f0c353c5bc51bbe2ecf4c89 Message-Id: <20221011061228.CC9373858C2D@sourceware.org> Date: Tue, 11 Oct 2022 06:12:28 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b88adba751da635c6f0c353c5bc51bbe2ecf4c89 commit r13-3212-gb88adba751da635c6f0c353c5bc51bbe2ecf4c89 Author: Liwei Xu Date: Fri Sep 23 13:46:02 2022 +0800 Optimize nested permutation to single VEC_PERM_EXPR [PR54346] This patch implemented the optimization in PR 54346, which Merges c = VEC_PERM_EXPR ; d = VEC_PERM_EXPR ; to d = VEC_PERM_EXPR ; Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,} tree-ssa/forwprop-19.c fail to pass but I'm not sure whether it is ok to removed it. gcc/ChangeLog: PR tree-optimization/54346 * match.pd: Merge the index of VCST then generates the new vec_perm. gcc/testsuite/ChangeLog: * gcc.dg/pr54346.c: New test. Co-authored-by: liuhongt Diff: --- gcc/match.pd | 41 +++++++++++++++++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/pr54346.c | 13 +++++++++++++ 2 files changed, 54 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index 345bcb701a5..3550c16aaa6 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8086,6 +8086,47 @@ and, (minus (mult (vec_perm @1 @1 @3) @2) @4))) +/* Merge + c = VEC_PERM_EXPR ; + d = VEC_PERM_EXPR ; + to + d = VEC_PERM_EXPR ; */ + +(simplify + (vec_perm (vec_perm@0 @1 @2 VECTOR_CST@3) @0 VECTOR_CST@4) + (with + { + if (!TYPE_VECTOR_SUBPARTS (type).is_constant ()) + return NULL_TREE; + + tree op0; + machine_mode result_mode = TYPE_MODE (type); + machine_mode op_mode = TYPE_MODE (TREE_TYPE (@1)); + int nelts = TYPE_VECTOR_SUBPARTS (type).to_constant (); + vec_perm_builder builder0; + vec_perm_builder builder1; + vec_perm_builder builder2 (nelts, nelts, 1); + + if (!tree_to_vec_perm_builder (&builder0, @3) + || !tree_to_vec_perm_builder (&builder1, @4)) + return NULL_TREE; + + vec_perm_indices sel0 (builder0, 2, nelts); + vec_perm_indices sel1 (builder1, 1, nelts); + + for (int i = 0; i < nelts; i++) + builder2.quick_push (sel0[sel1[i].to_constant ()]); + + vec_perm_indices sel2 (builder2, 2, nelts); + + if (!can_vec_perm_const_p (result_mode, op_mode, sel2, false)) + return NULL_TREE; + + op0 = vec_perm_indices_to_tree (TREE_TYPE (@4), sel2); + } + (vec_perm @1 @2 { op0; }))) + + /* Match count trailing zeroes for simplify_count_trailing_zeroes in fwprop. The canonical form is array[((x & -x) * C) >> SHIFT] where C is a magic constant which when multiplied by a power of 2 contains a unique value diff --git a/gcc/testsuite/gcc.dg/pr54346.c b/gcc/testsuite/gcc.dg/pr54346.c new file mode 100755 index 00000000000..63611ab6c2f --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr54346.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-dse1" } */ + +typedef int veci __attribute__ ((vector_size (4 * sizeof (int)))); + +void fun (veci a, veci b, veci *i) +{ + veci c = __builtin_shuffle (a, b, __extension__ (veci) {1, 4, 2, 7}); + *i = __builtin_shuffle (c, __extension__ (veci) { 7, 2, 1, 5 }); +} + +/* { dg-final { scan-tree-dump "VEC_PERM_EXPR.*{ 3, 6, 0, 0 }" "dse1" } } */ +/* { dg-final { scan-tree-dump-times "VEC_PERM_EXPR" 1 "dse1" } } */