From patchwork Wed Apr 5 08:38:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prathamesh Kulkarni X-Patchwork-Id: 79504 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp144876vqo; Wed, 5 Apr 2023 01:40:02 -0700 (PDT) X-Google-Smtp-Source: AKy350Z0aZwXRGf9NX7n4/I2DSeXq7ZMy75w8Jl+QnIm2rOKxf/ph4BJmj1x5gv+hvSq83YA40uR X-Received: by 2002:a50:ff05:0:b0:500:58cb:3b05 with SMTP id a5-20020a50ff05000000b0050058cb3b05mr1091404edu.27.1680684002150; Wed, 05 Apr 2023 01:40:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680684002; cv=none; d=google.com; s=arc-20160816; b=k0maeROvIP51aSiamaqTcIsuW3ztrzCA341/AtB/+c7Vm/ZSMdaRKm6uL0y8HMWqA/ 7US//4Juk9pN9Fw7S7biL62N4zIIfpdOLusTnPngVubDISD81dgj11EYjrMxVmojz23F YWkfT30ki2a8kda9xE1lOGEJ7+AiEn1ekHAD2k9+UyejyE4Z4s+Sr7jFQ/jhdMJe9Pov gbbsubot/iKlmMCGLTvFtsRMIoYYdQmiKDOuUDGIjlBOORyrBhVgAsDj2XPdybUnRt7p dT/7LAoKeVPgWRye5HQ21f2MZAxJHOTfXL6IBG1e9NSyQ5lLfnO+SOnW9kSilJU57vdw 1jDw== 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=zznImpIIULUfd5CfOxYIKOMqJtgv5THI7tP7ydG2gKw=; b=jjaEOJ7AIFr9sizKXaqCZECkk+573XO9criepnapxkgur4wCRqLuKA4FNI+LNkgl0n T4lO6VuJRlq0AS+yA+IFXIbfSlQFxEx4YTBSad2G1LkE7x7MWD+06P3yRJdVVNDNFyhw P5zQSKSREMZkvrheWSgDxRO/LCXNxpoIyIMw6DxD1SqNo3HpD5bYi4hAOi0zR2/1ubSv 7oxWJdtRd7aXdz+fmSTRiTlFck61Vpu6WOLELWlVclgWxscALVTBxe75Seinvmp2Js9Z 6tClIi5CPLVexxp5Ldat73RiQnMWhkhdXSHowj9x3EbIqbnSHa2GrnNuDsR7+cvUdy9Z 9e4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Glv6D2mW; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id lj8-20020a170906f9c800b008b20e95d474si777579ejb.51.2023.04.05.01.40.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 01:40:02 -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=Glv6D2mW; 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 CC7CB3858C2B for ; Wed, 5 Apr 2023 08:40:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CC7CB3858C2B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680684000; bh=zznImpIIULUfd5CfOxYIKOMqJtgv5THI7tP7ydG2gKw=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=Glv6D2mWERQkXdRirkdpLXf5AOJZCknAIetaNO4AMkRqIWPz9AT2a+lSpauDrduUl 0X20w08IheNUMnTyNUxED2zHMNELsZPhEkj1Pht7tOuSz3Lt2xnSLFsSBnxGgUG5yD F7sjJox0FfnXmOWgmiC2E8wxXlaTvDg8FnSRkH6E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by sourceware.org (Postfix) with ESMTPS id 9D9663858CDA for ; Wed, 5 Apr 2023 08:39:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9D9663858CDA Received: by mail-wm1-x335.google.com with SMTP id j18-20020a05600c1c1200b003ee5157346cso23235665wms.1 for ; Wed, 05 Apr 2023 01:39:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680683942; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=zznImpIIULUfd5CfOxYIKOMqJtgv5THI7tP7ydG2gKw=; b=OwhfgXHwZdm0hrUSK/tC/BTue9foqm10tkrPVbAAdgnIWe/SDVoJvKJVKS6D3SEPpj atZMrs5YCikMTZSagJIKChP08gkjZpRfm/uSIyIt0KkUTI9uMvbOf4aTVZeZEDKujcmN LS7KZbLmDGTLsWwz4a8FMZM/QIfV8FbSE5kfzVTAsre4dzxhywzWlrXFMTMqv7wps1k5 6zBLDDBQBYg+VYC1Gs6K2rKgj7RG2A1SvU9ki9adoFG2CGcH/Io4xd/l6uLRaI8OBmNM UkQ+aw8vSh2y3Nv6Hq27hnL0KivTnkVE7of+hBQaA2KeggXf17ht9AdJ2s3BU2+PP9RU xNUQ== X-Gm-Message-State: AAQBX9cRFOfwAlOHwtHep3iY8pUmXb4h3KwUsmsM/VhZ4LLsgw0AwKpE MVw6bcQ6DatwuitfBhuNb2vqkJnNHm8Sf/vnNFMQV5Gk0VFLcl8H X-Received: by 2002:a7b:c5d5:0:b0:3f0:4428:94eb with SMTP id n21-20020a7bc5d5000000b003f0442894ebmr523028wmk.4.1680683942579; Wed, 05 Apr 2023 01:39:02 -0700 (PDT) MIME-Version: 1.0 Date: Wed, 5 Apr 2023 14:08:26 +0530 Message-ID: Subject: [match.pd] [SVE] Add pattern to transform svrev(svrev(v)) --> v To: gcc Patches , Richard Sandiford X-Spam-Status: No, score=-9.8 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?1762324907898610418?= X-GMAIL-MSGID: =?utf-8?q?1762324907898610418?= Hi, For the following test: svint32_t f(svint32_t v) { return svrev_s32 (svrev_s32 (v)); } We generate 2 rev instructions instead of nop: f: rev z0.s, z0.s rev z0.s, z0.s ret The attached patch tries to fix that by trying to recognize the following pattern in match.pd: v1 = VEC_PERM_EXPR (v0, v0, mask) v2 = VEC_PERM_EXPR (v1, v1, mask) --> v2 = v0 if mask is { nelts - 1, nelts - 2, nelts - 3, ... } Code-gen with patch: f: ret Bootstrap+test passes on aarch64-linux-gnu, and SVE bootstrap in progress. Does it look OK for stage-1 ? Thanks, Prathamesh gcc/ChangeLog: * match.pd: New pattern to simplify two successive VEC_PERM_EXPRs with single operand and same mask, where mask chooses elements in reverse order. gcc/testesuite/ChangeLog: * gcc.target/aarch64/sve/acle/general/rev-1.c: New test. diff --git a/gcc/match.pd b/gcc/match.pd index b8d3538b809..19dfc8f3722 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -8456,3 +8456,27 @@ and, } (if (full_perm_p) (vec_perm (op@3 @0 @1) @3 @2)))))) + +/* Transform: + v1 = VEC_PERM_EXPR (v0, v0, mask) + v2 = VEC_PERM_EXPR (v1, v1, mask) + --> + v2 = v0 + if mask is {nelts - 1, nelts - 2, ...} */ + +(simplify + (vec_perm (vec_perm@2 @0 @0 VECTOR_CST@1) @2 @1) + (with + { + vec_perm_builder builder; + bool rev_p = false; + if (tree_to_vec_perm_builder (&builder, @1)) + { + poly_uint64 nelts = TYPE_VECTOR_SUBPARTS (type); + vec_perm_indices sel (builder, 1, nelts); + if (sel.series_p (0, 1, nelts - 1, -1)) + rev_p = true; + } + } + (if (rev_p) + @0))) 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" } } */