From patchwork Mon Jun 26 08:11:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "juzhe.zhong@rivai.ai" X-Patchwork-Id: 112758 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp7319844vqr; Mon, 26 Jun 2023 01:12:50 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4/qwd/3urkuMsdWcLX7k/N5I1kHCEDu+pOgPKdoUGMBl6NtiNT/r6joUjiwtpf6u+UR0v7 X-Received: by 2002:aa7:cac3:0:b0:514:a565:6e28 with SMTP id l3-20020aa7cac3000000b00514a5656e28mr20524269edt.18.1687767170404; Mon, 26 Jun 2023 01:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687767170; cv=none; d=google.com; s=arc-20160816; b=sXln75IuOTCKqgCGg295d4uzG+eoqSeNHXz6YexLKgQZJcmmur0wcUwriPStQCMGp0 1tZU222ilh7cLnNVJUIYwGe1StnUW5DZJ1Jq8OWUvjFKabmUn6Z/kkTthZqW03zFQWeJ IhHktRPGl3LFQI7Pd7LVJCGwXsz6WE6bA9l7sSzW37u4Y5LWpxCaJkzSvW0MXOU939qN dCkB2mpB5wnGBxQuElMuaRgpD/+vxh1yg/Rw8RCP0wmjKcf8MsHzHEyds4q/p+7yWB65 XDRvQFT/58GwqCusK+CE2xtKNdeqIOtFO8pVE1JoSENtYuGMv5lW2Uzzj7/pfyOuY99p 1tDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:feedback-id :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:dmarc-filter:delivered-to; bh=nr6TkV2eAuLTOx4Fh81UV1Ez/pO05np16ApR7kKkQNg=; fh=h6UG6PIw2FD/e8JL+9n/VDDoO75bXx4B3jGj5okR2Rw=; b=uYBIrHaX/Xy5a0qdJVUKhHSQ1wZTKTIs/09K+chVlZ/1ACs0LqdazeSYeSZAIzraWD 2baL1By5QAkU5XdhFfADgYBvCMLgz0LMyxoP6mu98KNWEkNTPYCsnw6+bOwaRvHqa/jk D/aaComTjGCI/+X22Ee55P6hmWQtD1Eg/zmw+blYJk1BLtaN/RJNHyuMDxN3BNcRcsJM dB1jWWgU9KkfDCe751QKIdnQ/fLP9opQDNkKEAM59nNUndWQQoE5/xH3w21xW3VCIme7 jKbQbaJZVxqd1+bQoAfBaQARD21DQDY01vEhLL7xjVg6T4dQp/OT3XiGb67s4XSZ2mx3 fu+A== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id y6-20020a50eb06000000b0051bee6b4881si2365275edp.545.2023.06.26.01.12.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Jun 2023 01:12:50 -0700 (PDT) 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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9311B385734E for ; Mon, 26 Jun 2023 08:12:32 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgsg2.qq.com (smtpbgsg2.qq.com [54.254.200.128]) by sourceware.org (Postfix) with ESMTPS id CFFFB3858423 for ; Mon, 26 Jun 2023 08:12:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CFFFB3858423 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivai.ai Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivai.ai X-QQ-mid: bizesmtp69t1687767119temjmdjp Received: from rios-cad5.localdomain ( [58.60.1.11]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 26 Jun 2023 16:11:58 +0800 (CST) X-QQ-SSF: 01400000000000G0S000000A0001000 X-QQ-FEAT: OXH3MF60TyU43CzpiBonMD3n+MXYot+ay2eEE9+qjJ0JlCQCjD0oyRS9x44DL XoPywYKsHRtQpnhdQyQH06VzgOT9HyAjMIaH39g4bkGEO2A5jonwvBCyXhdFm6jI4oOHJip BlOFSAjO95uaWFlWezvgdXTnaluPYhnqCpEz2V91gulWb8fH3K51SJNdQroHP1bXSrro7Wy qc3lc3ptDLBZ3zZeJSEiENrFMsF4cXlzCerznZdq/kfPzM652HQ7ideEYXXHIoPyHBLosu2 PuvcJHHFPJzoYw1UQBZyDyb/Ulffu2alpCs5eZGTDFaK0KTTLU2nCvXbSyMbBJzGTOFNrSj +3OY5iAyeUuZnsepn8/E4QC5LT9fgYCrgnhCNxPkzLsXmL/OnwMKY+VLWvqA+cl8Yk4Iwiy E8rVLVNJUtc= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 11876098935574472170 From: juzhe.zhong@rivai.ai To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, rguenther@suse.de, Ju-Zhe Zhong Subject: [PATCH V2] GIMPLE_FOLD: Fix gimple fold for LEN_{MASK}_{LOAD,STORE} Date: Mon, 26 Jun 2023 16:11:55 +0800 Message-Id: <20230626081155.2865595-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.3 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, 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: , 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?1769752148544219428?= X-GMAIL-MSGID: =?utf-8?q?1769752148544219428?= From: Ju-Zhe Zhong Hi, previous I made a mistake on GIMPLE_FOLD of LEN_MASK_{LOAD,STORE}. We should fold LEN_MASK_{LOAD,STORE} (bias+len) == vf (nunits instead of bytesize) && mask = all trues mask into: MEM_REF [...]. This patch added testcase to test gimple fold of LEN_MASK_{LOAD,STORE}. Also, I fix LEN_LOAD/LEN_STORE, to make them have the same behavior. Ok for trunk ? gcc/ChangeLog: * gimple-fold.cc (gimple_fold_partial_load_store_mem_ref): Fix gimple fold of LOAD/STORE with length. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c: New test. --- gcc/gimple-fold.cc | 6 ++- .../riscv/rvv/autovec/partial/gimple_fold-1.c | 43 +++++++++++++++++++ 2 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 3d46b76edeb..6d167b116b9 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -5397,8 +5397,10 @@ gimple_fold_partial_load_store_mem_ref (gcall *call, tree vectype, bool mask_p) unsigned int nargs = gimple_call_num_args (call); tree bias = gimple_call_arg (call, nargs - 1); gcc_assert (TREE_CODE (bias) == INTEGER_CST); - if (maybe_ne (wi::to_poly_widest (basic_len) - wi::to_widest (bias), - GET_MODE_SIZE (TYPE_MODE (vectype)))) + /* For LEN_LOAD/LEN_STORE/LEN_MASK_LOAD/LEN_MASK_STORE, + we don't fold when (bias + len) != VF. */ + if (maybe_ne (wi::to_poly_widest (basic_len) + wi::to_widest (bias), + GET_MODE_NUNITS (TYPE_MODE (vectype)))) return NULL_TREE; /* For LEN_MASK_{LOAD,STORE}, we should also check whether diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c new file mode 100644 index 00000000000..23407a2d3f4 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/partial/gimple_fold-1.c @@ -0,0 +1,43 @@ +/* { dg-do compile } */ +/* { dg-options "-march=rv32gcv -mabi=ilp32d --param riscv-autovec-preference=fixed-vlmax --param riscv-autovec-lmul=m8 -O3 -fdump-tree-optimized-details" } */ + +#include + +#define SZ 255 + +#define DEF(TYPE) void fn_##TYPE (TYPE *__restrict a); + +#define RUN(TYPE) \ + TYPE a##TYPE[SZ]; \ + for (int i = 0; i < SZ; i++) \ + { \ + a##TYPE[i] = 127; \ + } \ + fn_##TYPE (a##TYPE); + +#define RUN_ALL() \ + RUN (int8_t) \ + RUN (int16_t) \ + RUN (int32_t) \ + RUN (int64_t) \ + RUN (uint8_t) \ + RUN (uint16_t) \ + RUN (uint32_t) \ + RUN (uint64_t) + +DEF (int8_t) +DEF (int16_t) +DEF (int32_t) +DEF (int64_t) +DEF (uint8_t) +DEF (uint16_t) +DEF (uint32_t) +DEF (uint64_t) + +int +main () +{ + RUN_ALL () +} + +/* { dg-final { scan-tree-dump-times "\.LEN_MASK_STORE" 6 "optimized" } } */