From patchwork Thu Aug 17 01:37:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 135839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp395619vqi; Wed, 16 Aug 2023 18:39:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG0imK3bw3ikr/EnHTumf0CnuDLtPthqYmoDwKGIYXPVglK+3Vd0lDRPi7/9UpTFPCDNjAL X-Received: by 2002:a05:6402:799:b0:522:1fd2:ca7a with SMTP id d25-20020a056402079900b005221fd2ca7amr2604986edy.29.1692236341542; Wed, 16 Aug 2023 18:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692236341; cv=none; d=google.com; s=arc-20160816; b=Hs96M5IRqN9XTqwF9W5BbrDFsFsdw4DWblT5Qe2y8HzV/hnIkD7JteFp8dV0eln4uy MoI3EVmXs3EYlJuh+9ZzYNr0v1PX5vIHDIWFNNeUZ9pNXAN4D+re4A/6Jyktqd8RRupS ztboaaDwtLmCnwR+w1ZdcGdjFmJgy8XMR58u2uz8tkqW2vtBrOn6Rk24/SA+dY13ACyN fqPkFtzebDwaQDFslz9Xq9F37BYhjFACRsIzh6vs356zCOI8fCT7Md/OLFWSlMLJ2IYC gxKoAC58/B6YEA9IRluM3rB18wtn1aPfxIQsM5207QzM9Pto59nX3OX/1quCauUTaiKV exLw== 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 :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=RzeLHjbEl8c4drPUBraZQ8A+koItfT1czsoD6NH5IDc=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=KOfbeeOWumw6F2OWkQs1zV5y6XKCgxzmkF5WrAaT0N3GJasWCt8ITApEjvoqW4qGCK /mZlTY+MrtqK6+njJG86YVDZCdsr0aQXrprWoF9+gsUBBIv1CrnU4YkaX3UTDDukdbiX b0n0FWH5Qa/QPfwiQyL/H/zZe6bi9fW1masXXsl1kvDbffxRbjGx3mJZhQM9FycJCmQ9 NFWVpoU0H3WfdNvrA5gWWSExgGAGobZbc9HvyQuHoRNFONGjXM/H6m0t14iXCLci7n46 7ec0XTzYOFIHmP+qkDaSC11AsWi5yzz4fPI+kqrJ+WmcK1TzItXPv7/of2qgYOupEMnU 7ORA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rpRKw4GY; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b10-20020a05640202ca00b005256af1219asi5124676edx.428.2023.08.16.18.39.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Aug 2023 18:39:01 -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; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=rpRKw4GY; 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 7CFA83858C2C for ; Thu, 17 Aug 2023 01:39:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7CFA83858C2C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692236340; bh=RzeLHjbEl8c4drPUBraZQ8A+koItfT1czsoD6NH5IDc=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=rpRKw4GY7dYIzrtwRLn44xU53F080H2FWG9Lnp/pS8/vNPCZKXy+uxzzPmw52qvTS Fmp3pyc3HvKRQ7W5N8cry11IOkIUiZMp0Z+wg5dPN8maR4Hf/38lb6A8oHZMRp+r3W PpOIUvW79tcbmlJnCJXnrhopVuyCv36i41355dqo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id 6F2BB3857C44 for ; Thu, 17 Aug 2023 01:37:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6F2BB3857C44 Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37GK0MNR003054 for ; Wed, 16 Aug 2023 18:37:51 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sgtwck6pp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Wed, 16 Aug 2023 18:37:51 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Wed, 16 Aug 2023 18:37:49 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Wed, 16 Aug 2023 18:37:49 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 75B863F7048; Wed, 16 Aug 2023 18:37:49 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Sink convert for vec_cond Date: Wed, 16 Aug 2023 18:37:33 -0700 Message-ID: <20230817013733.3093010-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: 1Te92SZJdGO3XV0CHPCvjFqMLEtYVTYo X-Proofpoint-ORIG-GUID: 1Te92SZJdGO3XV0CHPCvjFqMLEtYVTYo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.957,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-08-16_21,2023-08-15_02,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1774438413795355585 X-GMAIL-MSGID: 1774438413795355585 Convert be sinked into a vec_cond if both sides fold. Unlike other unary operations, we need to check that we still can handle this vec_cond's first operand is the same as the new truth type. I tried a few different versions of this patch: view_convert to the new truth_type but that does not work as we always support all vec_cond afterwards. using expand_vec_cond_expr_p; but that would allow too much. I also tried to see if view_convert can be handled here but we end up with: _3 = VEC_COND_EXPR <_2, { Nan(-1), Nan(-1), Nan(-1), Nan(-1) }, { 0.0, 0.0, 0.0, 0.0 }>; Which isel does not know how to handle as just being a view_convert from `vector(4) ` to `vector(4) float` and causes a regression with `g++.target/i386/pr88152.C` Note, in the case of the SVE testcase, we will sink negate after the convert and be able to remove a few extra instructions in the end. Also with this change gcc.target/aarch64/sve/cond_unary_5.c will now pass. OK? Bootstrapped and tested on x86_64-linux-gnu and aarch64-linux-gnu. gcc/ChangeLog: PR tree-optimization/111006 PR tree-optimization/110986 * match.pd: (op(vec_cond(a,b,c))): Handle convert for op. gcc/testsuite/ChangeLog: PR tree-optimization/111006 * gcc.target/aarch64/sve/cond_convert_7.c: New test. --- gcc/match.pd | 9 ++++++++ .../gcc.target/aarch64/sve/cond_convert_7.c | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c diff --git a/gcc/match.pd b/gcc/match.pd index acd2a964917..ca5ab6f289d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4704,6 +4704,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (op (vec_cond:s @0 @1 @2)) (vec_cond @0 (op! @1) (op! @2)))) +/* Sink unary conversions to branches, but only if we do fold both + and the target's truth type is the same as we already have. */ +(for op (convert) + (simplify + (op (vec_cond:s @0 @1 @2)) + (if (VECTOR_TYPE_P (type) + && types_match (TREE_TYPE (@0), truth_type_for (type))) + (vec_cond @0 (op! @1) (op! @2))))) + /* Sink binary operation to branches, but only if we can fold it. */ (for op (tcc_comparison plus minus mult bit_and bit_ior bit_xor lshift rshift rdiv trunc_div ceil_div floor_div round_div diff --git a/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c new file mode 100644 index 00000000000..4bb95b92195 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_7.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256 -fdump-tree-optimized" } */ + +/* This is a modified reduced version of cond_unary_5.c */ + +void __attribute__ ((noipa)) +f0 (unsigned short *__restrict r, + int *__restrict a, + int *__restrict pred) +{ + for (int i = 0; i < 1024; ++i) + { + int p = pred[i]?-1:0; + r[i] = p ; + } +} + +/* { dg-final { scan-assembler-times {\tmov\tz[0-9]+\.h, p[0-7]+/z, #-1} 1 } } */ +/* { dg-final { scan-assembler-not {\tmov\tz[0-9]+\.[hs], p[0-7]+/z, #1} } } */ + +/* { dg-final { scan-tree-dump-not "VIEW_CONVERT_EXPR " "optimized" } } */ +/* { dg-final { scan-tree-dump-not " = -" "optimized" } } */ +/* { dg-final { scan-tree-dump-not " = \\\(vector" "optimized" } } */