From patchwork Tue Nov 29 14:39:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 27281 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp378452wrr; Tue, 29 Nov 2022 06:40:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf4X2ct5ib9uVflCrhgJ/g+fFqF+5D3fVbOHdXDQXAMFRtLOuW21JK519Nl3dmR546/Icd5H X-Received: by 2002:a05:6402:1f09:b0:462:6a0c:cfa with SMTP id b9-20020a0564021f0900b004626a0c0cfamr15092051edb.349.1669732832201; Tue, 29 Nov 2022 06:40:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669732832; cv=none; d=google.com; s=arc-20160816; b=r/EyuJxlyTeryXJB9kOOHGDu29kdHkaxAZKgSXjEpPB3k9rEnB2uvXuM3c7Pbg8Wqf iejyZHw8mvvaZkOD1DLtrj2SvLSrvuoUGf2aQoQJBYmsB+YZMp0vUXvHgv8ot3HbOKD1 51In89KwocyyFK9H+e1Ra59VlnaJHzYg5jwOsaXRKY6xMeV/5AGDJFyUqBGMk4OWePij N9NgAVKliDLVerIte3flM5oU+9O839OYeUohXEdzhkgisSZ9LnvD6UOV731Nskx7Or5Q qvo0reA3R0oifVwoyQJA1MDnmfn6RCROfWhuiEphp4CnFZWqC1Z8FWQtbRuPIYxc2/nf PlMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=f4CySLri3FxUmRccEGRLw6wSyBQfm6HI1uBSylEPPbU=; b=uEovzv5MGEsnFRqsX7N7sq3qmyykWK94oHpTlI60flDfQSSmSEejXM7G08hcMLICBu 1lgQno1YGvBp79a3ifr5tijUihLr93M2uPWhdLyRvGEJevcFpKHZiFUDYQ8iSxSf23cx IOMGPRe34/o70K0skxBao8PPy2AjRPc/8Nvq1RuT8m3FGUb9FCTEFtMkL0eMfYD3csZw wVBpP8Y0OTjBAeDFyvGTrexEPPPNJI9aap2ff3Qx/XcixQWbALZpIwPSA0+fqyFx6DHP MjHpS/veKHHByq8jnYH4bBUXVVMLiy3KX+f9lXh//S+p8SAT+semWxBa8ySAJpsX9fyh Hxpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rw007R6I; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id x2-20020a05640226c200b00458b42ff418si462658edd.221.2022.11.29.06.40.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Nov 2022 06:40:32 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Rw007R6I; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 49ACE385782B for ; Tue, 29 Nov 2022 14:40:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49ACE385782B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669732829; bh=f4CySLri3FxUmRccEGRLw6wSyBQfm6HI1uBSylEPPbU=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Rw007R6IXq9SM9wPiTw8QJdy9LzpVUS1YDpS4aG/HWGS7TZBXPBbN9a838CT61Isp wRM/9F11Gf7AfEAguLp9dq3YY7vH6p/jlpwMv6Zvl5Dui3YDmkVVLt9e2btk9RufOp Uxs7VUWx6MfOtwl5Gp18bQD+9NqzMaBZE4fsly6o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by sourceware.org (Postfix) with ESMTPS id 117D63858D1E for ; Tue, 29 Nov 2022 14:39:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 117D63858D1E Received: by mail-lf1-x12f.google.com with SMTP id g7so22367000lfv.5 for ; Tue, 29 Nov 2022 06:39:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=f4CySLri3FxUmRccEGRLw6wSyBQfm6HI1uBSylEPPbU=; b=BAtp7EAg+1MKYxegcCmgYL/a736c+XL1ARLc4Mr+9RV8fEZj7wJqH47hWonueZG3wn US/3AgkpVfTw9DN1eoRP9nBlfFeuNDsfgNg7zaCQ99MK7G20RHBWm2oICq4Itk8koiTm 3yKw2qAALvwmwAPo5Wno8uRhVtCIyaaHOPDNqVUhzobWW2Xzqut949Lo47i+Uk50JDlS qaoZ5oooyky4WkHZ4zVzZTl/QO30K5Ct6q3x292XKnVVqk8Fyg1zsrl7w9RGoyqFTBP4 DuWmQYOzu7cpIQLINpdijSyyuxAQu5BpunS3ifXPTyo3imsDQlrdAIXqGzPRMlPsa108 Acrg== X-Gm-Message-State: ANoB5pkMxGsOn5nwyv9bj9OHaqGMswFCh33o7jL8j7Wg9ehYFb5m2uYL DHajSF8a6SDzr5mlbFL9jx38sgawGXg8uTogF2OaOASsiv0= X-Received: by 2002:a05:6512:340a:b0:4ae:d9b4:bd31 with SMTP id i10-20020a056512340a00b004aed9b4bd31mr13904052lfr.645.1669732784091; Tue, 29 Nov 2022 06:39:44 -0800 (PST) MIME-Version: 1.0 Date: Tue, 29 Nov 2022 20:09:07 +0530 Message-ID: Subject: [aarch64] Use dup and zip1 for interleaving elements in initializing vector To: gcc Patches , Richard Sandiford X-Spam-Status: No, score=-8.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP 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: Prathamesh Kulkarni via Gcc-patches From: Prathamesh Kulkarni Reply-To: Prathamesh Kulkarni Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750841774017997892?= X-GMAIL-MSGID: =?utf-8?q?1750841774017997892?= Hi, For the following test-case: int16x8_t foo(int16_t x, int16_t y) { return (int16x8_t) { x, y, x, y, x, y, x, y }; } Code gen at -O3: foo: dup v0.8h, w0 ins v0.h[1], w1 ins v0.h[3], w1 ins v0.h[5], w1 ins v0.h[7], w1 ret For 16 elements, it results in 8 ins instructions which might not be optimal perhaps. I guess, the above code-gen would be equivalent to the following ? dup v0.8h, w0 dup v1.8h, w1 zip1 v0.8h, v0.8h, v1.8h I have attached patch to do the same, if number of elements >= 8, which should be possibly better compared to current code-gen ? Patch passes bootstrap+test on aarch64-linux-gnu. Does the patch look OK ? Thanks, Prathamesh diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc index c91df6f5006..e5dea70e363 100644 --- a/gcc/config/aarch64/aarch64.cc +++ b/gcc/config/aarch64/aarch64.cc @@ -22028,6 +22028,39 @@ aarch64_expand_vector_init (rtx target, rtx vals) return; } + /* Check for interleaving case. + For eg if initializer is (int16x8_t) {x, y, x, y, x, y, x, y}. + Generate following code: + dup v0.h, x + dup v1.h, y + zip1 v0.h, v0.h, v1.h + for "large enough" initializer. */ + + if (n_elts >= 8) + { + int i; + for (i = 2; i < n_elts; i++) + if (!rtx_equal_p (XVECEXP (vals, 0, i), XVECEXP (vals, 0, i % 2))) + break; + + if (i == n_elts) + { + machine_mode mode = GET_MODE (target); + rtx dest[2]; + + for (int i = 0; i < 2; i++) + { + rtx x = copy_to_mode_reg (GET_MODE_INNER (mode), XVECEXP (vals, 0, i)); + dest[i] = gen_reg_rtx (mode); + aarch64_emit_move (dest[i], gen_vec_duplicate (mode, x)); + } + + rtvec v = gen_rtvec (2, dest[0], dest[1]); + emit_set_insn (target, gen_rtx_UNSPEC (mode, v, UNSPEC_ZIP1)); + return; + } + } + enum insn_code icode = optab_handler (vec_set_optab, mode); gcc_assert (icode != CODE_FOR_nothing); diff --git a/gcc/testsuite/gcc.target/aarch64/interleave-init-1.c b/gcc/testsuite/gcc.target/aarch64/interleave-init-1.c new file mode 100644 index 00000000000..ee775048589 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/interleave-init-1.c @@ -0,0 +1,37 @@ +/* { dg-do compile } */ +/* { dg-options "-O3" } */ +/* { dg-final { check-function-bodies "**" "" "" } } */ + +#include + +/* +** foo: +** ... +** dup v[0-9]+\.8h, w[0-9]+ +** dup v[0-9]+\.8h, w[0-9]+ +** zip1 v[0-9]+\.8h, v[0-9]+\.8h, v[0-9]+\.8h +** ... +** ret +*/ + +int16x8_t foo(int16_t x, int y) +{ + int16x8_t v = (int16x8_t) {x, y, x, y, x, y, x, y}; + return v; +} + +/* +** foo2: +** ... +** dup v[0-9]+\.8h, w[0-9]+ +** movi v[0-9]+\.8h, 0x1 +** zip1 v[0-9]+\.8h, v[0-9]+\.8h, v[0-9]+\.8h +** ... +** ret +*/ + +int16x8_t foo2(int16_t x) +{ + int16x8_t v = (int16x8_t) {x, 1, x, 1, x, 1, x, 1}; + return v; +}