From patchwork Mon Aug 7 09:38:46 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: 131769 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp1331300vqr; Mon, 7 Aug 2023 02:39:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFxflH1Y2uigPwnFgDafTIi5GBF6HJK2hzAThSUZ02ohA5kPLXO8ugJlens9JUGV1eRb6Vl X-Received: by 2002:a05:6512:3281:b0:4fd:cc8c:54e5 with SMTP id p1-20020a056512328100b004fdcc8c54e5mr4560417lfe.41.1691401176300; Mon, 07 Aug 2023 02:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691401176; cv=none; d=google.com; s=arc-20160816; b=NixgewAo3Gtca8+E0M/UD+3F4EIL2IVQsjN1TfUPbgOMFLwjQmtjoiZWgi5wYIkEyV ElyqbIiH2E9K/C2OvB+2bPFZw1m15qkWdrmLXdXBMcYqb3rHS6C6f1VkBsirycx1EnQC 7HULQ97SW5h96B3ElvEj1I/+zLBOt+qfKX7uYUBDpNlsNe/mwff6+8b7Dnnxpj84CQGN +Vz3YD2sugxDXKvOXTOlUkU1UUYONF4B5wyeUKo9wQOnTZWVHo3g8GyKD7x2EYYQLZ6I +S/ml2Io/w499Dwe4uJNcdn6ibGEdd4f+kMIchrJN0qKsA9A3l+MpP9x5D8o5dfCpmhg DIwg== 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=tsE56QTHW8Z48HEcybLGHSbKpL+YsSAUnaKiyDcIODY=; fh=bFGt8bvBdss4RDVNwtoG4vql1cbNszblsxOGwrQqCdA=; b=RCSrc+ohspgxdOtB6Y1M9UNKARdYHAn07EFCLn4LX0eOwV1XHzAzV2HK1LMJExarYG 3QOWFXDap7lKDZqOIbkUlcc4VtTvlygkGhoV0qKE0lOvrl3rdr1aTamwljEBN63frGUi R3GawvvdRrEe01jr1q22faspFuUv27HoBxkmKeyN0prgZdMTl9O5HYleKNDdRYXQlEGF Qww06u6KbB2SjcqllVyce5iLDlYOuVOL/ey7qURUGGJ6YwiaoagFAFP37NnSd53fCzGf jyTgR19MF9Ax99UVFDma8m5Jhj3YUIE7N1CR2ag0QWA2FFB5hs/wsqJOczudNPJDRwp5 WEvA== ARC-Authentication-Results: i=1; mx.google.com; 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" Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id i15-20020a170906a28f00b0099bce5d5f77si4897420ejz.502.2023.08.07.02.39.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Aug 2023 02:39:36 -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; 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" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 01B9F3857C41 for ; Mon, 7 Aug 2023 09:39:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) by sourceware.org (Postfix) with ESMTPS id A2F5F3857006 for ; Mon, 7 Aug 2023 09:38:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A2F5F3857006 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: bizesmtp82t1691401130tz6mdm88 Received: from server1.localdomain ( [58.60.1.10]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 07 Aug 2023 17:38:49 +0800 (CST) X-QQ-SSF: 01400000000000G0V000000A0000000 X-QQ-FEAT: 3M0okmaRx3gWbAZsppbqFdDw30vNJoGA5Pbog7DF3z6ehjAevNVnZ1mZx0b8Y /hYvU+4DP3GsUrmgoZvsZHZBDkkBnvXS9xxaOEYBAKwU9y1DL6GS+JkwVjzjEw7gux52mJm eSzmxCWWq4WfLYKH1F5/M0u3WkT5+yA0KMmaYB2u+jGSASvOYPdyaMenIke+vhTguLp66Fo 3FDaZmeVSR/VuRZ3lQCdCeafi9eUj2aCoubHqs1RTwxyJKlKdnudj2ygNdGX2KEd4tk5RHa cY2B3jw5gw7JxgPXXuHCQqc+eP5jqNHS7AR8Ha+W3kHNhqx1EqRCr86y+KIJEjPIIeh2V3P Qku96gd66tu0HbWF9UK5ZHYxBVhGXJc+0OqVnJhZRBt4WDX3dyLw5D6NmBVVzEUUE9JrTNs yhHALvu7R0q2bpqTfCsl2Q== X-QQ-GoodBg: 2 X-BIZMAIL-ID: 17994729937296449276 From: Juzhe-Zhong To: gcc-patches@gcc.gnu.org Cc: richard.sandiford@arm.com, rguenther@suse.de, Juzhe-Zhong Subject: [PATCH] tree-optimization/110897 - Fix missed vectorization of shift on both RISC-V and aarch64 Date: Mon, 7 Aug 2023 17:38:46 +0800 Message-Id: <20230807093846.150132-1-juzhe.zhong@rivai.ai> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:rivai.ai:qybglogicsvrgz:qybglogicsvrgz7a-one-0 X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_NUMSUBJECT, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_PASS, TXREP, T_SPF_HELO_TEMPERROR 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: INBOX X-GMAIL-THRID: 1773562680027363289 X-GMAIL-MSGID: 1773562680027363289 Consider this following case: #include #define TEST2_TYPE(TYPE) \ __attribute__((noipa)) \ void vshiftr_##TYPE (TYPE *__restrict dst, TYPE *__restrict a, TYPE *__restrict b, int n) \ { \ for (int i = 0; i < n; i++) \ dst[i] = (a[i]) >> b[i]; \ } #define TEST_ALL() \ TEST2_TYPE(uint8_t) \ TEST2_TYPE(uint16_t) \ TEST2_TYPE(uint32_t) \ TEST2_TYPE(uint64_t) \ TEST_ALL() Both RISC-V and aarch64 of trunk GCC failed vectorize uint8_t/uint16_t with following missed report: :17:1: missed: couldn't vectorize loop :17:1: missed: not vectorized: relevant stmt not supported: patt_46 = MIN_EXPR <_6, 7>; :17:1: missed: couldn't vectorize loop :17:1: missed: not vectorized: relevant stmt not supported: patt_47 = MIN_EXPR <_7, 15>; Compiler returned: 0 Both GCC 13.1 can vectorize, see: https://godbolt.org/z/6vaMK5M1o Bootstrap and regression on X86 passed. Ok for trunk ? gcc/ChangeLog: * tree-vect-patterns.cc (vect_recog_over_widening_pattern): Add op vectype. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/binop/narrow-1.c: Adapt testcase. --- gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c | 4 ++-- gcc/tree-vect-patterns.cc | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c index 3de8d85b52d..b12cb6355c8 100644 --- a/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c +++ b/gcc/testsuite/gcc.target/riscv/rvv/autovec/binop/narrow-1.c @@ -27,5 +27,5 @@ TEST_ALL () -/* { dg-final { scan-assembler-times {\tvnsra\.wv} 6 } } */ -/* { dg-final { scan-assembler-times {\tvnsrl\.wv} 5 } } */ +/* { dg-final { scan-assembler-times {\tvnsra\.wv} 4 } } */ +/* { dg-final { scan-assembler-times {\tvnsrl\.wv} 4 } } */ diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index 2cedf238450..cda27fed95b 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -3133,7 +3133,8 @@ vect_recog_over_widening_pattern (vec_info *vinfo, return NULL; } else - append_pattern_def_seq (vinfo, last_stmt_info, pattern_stmt); + append_pattern_def_seq (vinfo, last_stmt_info, pattern_stmt, + op_vectype); ops[1] = new_var; } }