From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1922) id E8C423857341; Mon, 24 Apr 2023 19:46:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E8C423857341 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682365587; bh=53eEAeC9KRMjv02ybZltLGpc2G4pKgQ7PaxTWNyFRV0=; h=From:To:Subject:Date:From; b=mHbMonjymqWT5H7CNzqpTFHy1ZgEfAtGMgDYemOIylhC8n5XyN/hHKpCU5L8nJER8 ZyK6K94byLJ0AH2dTMCnFbUJ4U0f/q0+vEq8FNRl1G2yliH7nkJH/ndho3clh9HgqW gg3azfoeNHJnd6RFSpt1Lh+TPBkqTw9mlMtLmHqM= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Prathamesh Kulkarni To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-207] [SVE] Fold svrev(svrev(v)) to v. X-Act-Checkin: gcc X-Git-Author: Prathamesh Kulkarni X-Git-Refname: refs/heads/master X-Git-Oldrev: ad1816a8ab6c7baf7180e5e2644063db42f75a0f X-Git-Newrev: f0eabc52c9a2d3da0bfc201da7a5c1658b76e9a4 Message-Id: <20230424194627.E8C423857341@sourceware.org> Date: Mon, 24 Apr 2023 19:46:27 +0000 (GMT) List-Id: https://gcc.gnu.org/g:f0eabc52c9a2d3da0bfc201da7a5c1658b76e9a4 commit r14-207-gf0eabc52c9a2d3da0bfc201da7a5c1658b76e9a4 Author: Prathamesh Kulkarni Date: Tue Apr 25 01:12:28 2023 +0530 [SVE] Fold svrev(svrev(v)) to v. gcc/ChangeLog: * tree-ssa-forwprop.cc (is_combined_permutation_identity): Try to simplify two successive VEC_PERM_EXPRs with same VLA mask, where mask chooses elements in reverse order. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/acle/general/rev-1.c: New test. Diff: --- .../gcc.target/aarch64/sve/acle/general/rev-1.c | 12 ++++++++++++ gcc/tree-ssa-forwprop.cc | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/gcc/testsuite/gcc.target/aarch64/sve/acle/general/rev-1.c b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/rev-1.c new file mode 100644 index 00000000000..e57ee67d716 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/acle/general/rev-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-optimized" } */ + +#include + +svint32_t f(svint32_t v) +{ + return svrev_s32 (svrev_s32 (v)); +} + +/* { dg-final { scan-tree-dump "return v_1\\(D\\)" "optimized" } } */ +/* { dg-final { scan-tree-dump-not "VEC_PERM_EXPR" "optimized" } } */ diff --git a/gcc/tree-ssa-forwprop.cc b/gcc/tree-ssa-forwprop.cc index 9b567440ba4..9dc67b5309c 100644 --- a/gcc/tree-ssa-forwprop.cc +++ b/gcc/tree-ssa-forwprop.cc @@ -2541,6 +2541,27 @@ is_combined_permutation_identity (tree mask1, tree mask2) gcc_checking_assert (TREE_CODE (mask1) == VECTOR_CST && TREE_CODE (mask2) == VECTOR_CST); + + /* For VLA masks, check for the following pattern: + v1 = VEC_PERM_EXPR (v0, ..., mask1) + v2 = VEC_PERM_EXPR (v1, ..., mask2) + --> + v2 = v0 + if mask1 == mask2 == {nelts - 1, nelts - 2, ...}. */ + + if (operand_equal_p (mask1, mask2, 0) + && !VECTOR_CST_NELTS (mask1).is_constant ()) + { + vec_perm_builder builder; + if (tree_to_vec_perm_builder (&builder, mask1)) + { + poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (TREE_TYPE (mask1)); + vec_perm_indices sel (builder, 1, nelts); + if (sel.series_p (0, 1, nelts - 1, -1)) + return 1; + } + } + mask = fold_ternary (VEC_PERM_EXPR, TREE_TYPE (mask1), mask1, mask1, mask2); if (mask == NULL_TREE || TREE_CODE (mask) != VECTOR_CST) return 0;