From patchwork Wed Jul 12 11:00:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 119077 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1063738vqm; Wed, 12 Jul 2023 04:01:35 -0700 (PDT) X-Google-Smtp-Source: APBJJlHXmAmlldv5uv45fF0p+YXWlfL3DwhSOsnNCWp1FP6+Nz3vh85Foval5LacNJEdQDykpt3b X-Received: by 2002:a2e:895a:0:b0:2b6:a19e:5153 with SMTP id b26-20020a2e895a000000b002b6a19e5153mr18624277ljk.15.1689159695205; Wed, 12 Jul 2023 04:01:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689159695; cv=none; d=google.com; s=arc-20160816; b=Kwjm8wWFB0o/Gs6SWoh0L9iE2ihc6FqxLT2reG54gxSnz24eEOCj9snduC1I+kcx9K D8vWcD/8Yu9Qh4GZRUONBzquiUmyB3w2Ry9TlN9AaWopf5BCJxCeMiFZ03Z7zY91UNlC zKSox5wNqEQyDc1nPIG/ElGE09gXByc8EOw6+MnzEJcew+fLkxPWcrgmjon+Go91fnU2 ZVx7qgZdo23BzqjPgGyvmSDLLUZW9n5WcXZOxybOabFeUcTIuxgEgi4FLGncQGhngGOQ 0OW8LazretGIKS477CAot1Zb6WH2CnNkuo9du5TGFQ03E3OXROcTyYNAGDE1i1+0W1cQ oJLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:sender:errors-to:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :mime-version:user-agent:subject:to:date:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=LNfW9liYrXZN+Vey6FnGLsvnWWRuvjpdis8WOA9v+gI=; fh=etb9MYHN7HLF/sff76ICVdPeKiI8ZsjoOL2bcdG0aog=; b=zfBu/u/qOCgwmaUgkE2trSqK5cQIhadxUWDQmnuuMtMtLmtunBqv6j1Iuzwbvynv4I /pQGx87x9so/s9YQu9XPBs11EBJa10dKFYeTfpRWVZ8gDdzqhWX3RENWz/hiix0au6Yp aEr2jQYnUoFIxL60PsSSdnys6Y1n+Tx7wFNjAd3kWfaAguSEvTf7bdmHLkwuOl89sg8C AJ30KAAGixqi+TtHd6GElhCup+rUTu3Y7/yy/nqLUrgM3yUq/C8Sjbx0KaDaQCNsAPx6 ZyMKL4mjilVBB3ywvk+B81oPWYMkUxew4hHPKfNSxFeMFNn2dWM0sPvTl4EmPT+jfTIW 5rrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ysjkrht+; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z22-20020a17090655d600b0098cfbd83b9asi4097258ejp.776.2023.07.12.04.01.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 04:01:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=ysjkrht+; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3B3AD3857726 for ; Wed, 12 Jul 2023 11:01:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B3AD3857726 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689159660; bh=LNfW9liYrXZN+Vey6FnGLsvnWWRuvjpdis8WOA9v+gI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ysjkrht+MGFJpRMWKO1+zbaaH9w1D7kYOqkhV7pBzsE7hqpMrm3SOUj3OWd9YYG2i sY5U+Q2c4IGAjpqykziweayFObzMLlqAiPVaJqsjnXIRkWv8OdMgRXzUW7V8Zd4No5 W5AMb2x/TRuqGmWhvXKh3PCLa132NwIwV+KfP1L8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id E2BA1385840B for ; Wed, 12 Jul 2023 11:00:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E2BA1385840B Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 1F65922506 for ; Wed, 12 Jul 2023 11:00:16 +0000 (UTC) Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 1348B2C142 for ; Wed, 12 Jul 2023 11:00:16 +0000 (UTC) Date: Wed, 12 Jul 2023 11:00:16 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/110630 - enhance SLP permute support User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Richard Biener via Gcc-patches From: Richard Biener Reply-To: Richard Biener Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" Message-Id: <20230712110100.3B3AD3857726@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771212316598291119 X-GMAIL-MSGID: 1771212316598291119 The following enhances the existing lowpart extraction support for SLP VEC_PERM nodes to cover all vector aligned extractions. This allows the existing bb-slp-pr95839.c testcase to be vectorized with mips -mpaired-single and the new bb-slp-pr95839-3.c testcase with SSE2. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/110630 * tree-vect-slp.cc (vect_add_slp_permutation): New offset parameter, honor that for the extract code generation. (vectorizable_slp_permutation_1): Handle offsetted identities. * gcc.dg/vect/bb-slp-pr95839.c: Make stricter. * gcc.dg/vect/bb-slp-pr95839-3.c: New variant testcase. --- gcc/testsuite/gcc.dg/vect/bb-slp-pr95839-3.c | 15 +++++++++++++++ gcc/testsuite/gcc.dg/vect/bb-slp-pr95839.c | 1 + gcc/tree-vect-slp.cc | 14 +++++++++----- 3 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/bb-slp-pr95839-3.c diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr95839-3.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr95839-3.c new file mode 100644 index 00000000000..aaee8febf37 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr95839-3.c @@ -0,0 +1,15 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_float } */ +/* { dg-additional-options "-w -Wno-psabi" } */ + +typedef float __attribute__((vector_size(32))) v8f32; + +v8f32 f(v8f32 a, v8f32 b) +{ + /* Check that we vectorize this CTOR without any loads. */ + return (v8f32){a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3], + a[4] + b[4], a[5] + b[5], a[6] + b[6], a[7] + b[7]}; +} + +/* { dg-final { scan-tree-dump-not "from scalars" "slp2" } } */ +/* { dg-final { scan-tree-dump "optimized: basic block" "slp2" } } */ diff --git a/gcc/testsuite/gcc.dg/vect/bb-slp-pr95839.c b/gcc/testsuite/gcc.dg/vect/bb-slp-pr95839.c index 931fd46aaaa..d87bbf125c0 100644 --- a/gcc/testsuite/gcc.dg/vect/bb-slp-pr95839.c +++ b/gcc/testsuite/gcc.dg/vect/bb-slp-pr95839.c @@ -10,4 +10,5 @@ v4f32 f(v4f32 a, v4f32 b) return (v4f32){a[0] + b[0], a[1] + b[1], a[2] + b[2], a[3] + b[3]}; } +/* { dg-final { scan-tree-dump-not "from scalars" "slp2" } } */ /* { dg-final { scan-tree-dump "optimized: basic block" "slp2" } } */ diff --git a/gcc/tree-vect-slp.cc b/gcc/tree-vect-slp.cc index 355d078d66e..693621ca990 100644 --- a/gcc/tree-vect-slp.cc +++ b/gcc/tree-vect-slp.cc @@ -8432,7 +8432,7 @@ vect_transform_slp_perm_load (vec_info *vinfo, static void vect_add_slp_permutation (vec_info *vinfo, gimple_stmt_iterator *gsi, slp_tree node, tree first_def, tree second_def, - tree mask_vec) + tree mask_vec, poly_uint64 identity_offset) { tree vectype = SLP_TREE_VECTYPE (node); @@ -8470,14 +8470,17 @@ vect_add_slp_permutation (vec_info *vinfo, gimple_stmt_iterator *gsi, else if (!types_compatible_p (TREE_TYPE (first_def), vectype)) { /* For identity permutes we still need to handle the case - of lowpart extracts or concats. */ + of offsetted extracts or concats. */ unsigned HOST_WIDE_INT c; auto first_def_nunits = TYPE_VECTOR_SUBPARTS (TREE_TYPE (first_def)); if (known_le (TYPE_VECTOR_SUBPARTS (vectype), first_def_nunits)) { + unsigned HOST_WIDE_INT elsz + = tree_to_uhwi (TYPE_SIZE (TREE_TYPE (TREE_TYPE (first_def)))); tree lowpart = build3 (BIT_FIELD_REF, vectype, first_def, - TYPE_SIZE (vectype), bitsize_zero_node); + TYPE_SIZE (vectype), + bitsize_int (identity_offset * elsz)); perm_stmt = gimple_build_assign (perm_dest, lowpart); } else if (constant_multiple_p (TYPE_VECTOR_SUBPARTS (vectype), @@ -8709,7 +8712,8 @@ vectorizable_slp_permutation_1 (vec_info *vinfo, gimple_stmt_iterator *gsi, { indices.new_vector (mask, second_vec.first == -1U ? 1 : 2, TYPE_VECTOR_SUBPARTS (op_vectype)); - bool identity_p = indices.series_p (0, 1, 0, 1); + bool identity_p = (indices.series_p (0, 1, mask[0], 1) + && constant_multiple_p (mask[0], nunits)); machine_mode vmode = TYPE_MODE (vectype); machine_mode op_vmode = TYPE_MODE (op_vectype); unsigned HOST_WIDE_INT c; @@ -8762,7 +8766,7 @@ vectorizable_slp_permutation_1 (vec_info *vinfo, gimple_stmt_iterator *gsi, = vect_get_slp_vect_def (second_node, second_vec.second + vi); vect_add_slp_permutation (vinfo, gsi, node, first_def, - second_def, mask_vec); + second_def, mask_vec, mask[0]); } }