From patchwork Sun Aug 20 07:25:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 136234 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp2359854vqi; Sun, 20 Aug 2023 00:26:25 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEGSyCrp/ZRIe1FZLll1CXp90joQOTKTzk54HwGFTp16v4t3Z1SqqPih6zmLebdKuuf0gGl X-Received: by 2002:a17:906:4d2:b0:988:8be0:3077 with SMTP id g18-20020a17090604d200b009888be03077mr2356813eja.31.1692516385354; Sun, 20 Aug 2023 00:26:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692516385; cv=none; d=google.com; s=arc-20160816; b=ZU68IE0CiwRpc1lLWhR/HcPJg7bbH2vUAMX/oFkM2tX5uLt5dVuB5SICcb4sjpnQIL mPQNFNlLmGPDr0mtARJrUmsYlbWbs298thAt8pHd5plSzlau7P5ptfln4BCJBygkwgQf Fo2vu4/wCSPMsztQS0Vb7XXnDbB5nL2EEdEibXopWQk3+5C1kpAtRIXI+shPDRY26kCW K0UndjazWTuefLZDuJhE2TAx093pDUWN6x1mDTo5pJ5LVq70FFMxjZ9a2jwVpCzFpVsj AB5zwY/oYkZNwSfyKxRu/Dg7JkUDZqXdRKSNaUe4sbB4VU2IC9y1ytu2nJtLV3pX3lWt BUpg== 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=oB0bGXD7FFtdUwFeDZXtKtVIaXzS6s//TbkiAbDkld4=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=YMvnmvDNcNHVmsf60HotjsAcOxFvlOuotc+mfU0jl8fcdTKPM2MohdwNh32sBW5Fcp duX5oZ58vLrl29HrtN/t26SPUNwUn4LMv+0NRPG/saD0etrx7sCi23Vh4EsQca/GZx9f YjGxDFaqhQKSyozXXd2+okSj4yCG7ZeYiutG4AfrLUoxRXMxFAVcWtsNvTElErT/syBm 3zTCJWcdjI20wseXOam0LSTGWy0lBiamUT2B+4y5bLppNgV1ey2zJck413t4j/4Bl93P J1VAU96tgJh6JihUHhPfNRcCLXJc/rl649sAgjoPEDvkIpgoq/xf7eHFz6HPhR5kQ/nj +O1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=R6VF2HkY; 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id n6-20020a170906840600b00993664a9970si3941216ejx.873.2023.08.20.00.26.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 00:26:25 -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=R6VF2HkY; 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 101E23857004 for ; Sun, 20 Aug 2023 07:26:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 101E23857004 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692516384; bh=oB0bGXD7FFtdUwFeDZXtKtVIaXzS6s//TbkiAbDkld4=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=R6VF2HkYLMAFkGsYl68bZ8doVAW+DgreFTvuC5vJTMI+BqQ9EEiRWfNsjeUEZrg43 T2eiLyaZElE6MMhCSpGrjUsIGlj3VHq+Xf2mt55T9sTJYvUlKD1c3J2FUMvevd9By8 A9aBuENymsVXoaWhQyMy8/GkfVpORM1urMLXZ1cc= 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 0B2423858431 for ; Sun, 20 Aug 2023 07:25:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B2423858431 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 37K6hUrk009450 for ; Sun, 20 Aug 2023 00:25:39 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3sju3qhqms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 20 Aug 2023 00:25:39 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sun, 20 Aug 2023 00:25:37 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sun, 20 Aug 2023 00:25:37 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 5F4223F7081; Sun, 20 Aug 2023 00:25:37 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCHv2/COMMITTED] MATCH: Sink convert for vec_cond Date: Sun, 20 Aug 2023 00:25:26 -0700 Message-ID: <20230820072526.3283744-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: CrY_jmj-jm-YU9lmQT2W-MVT8aNILW1j X-Proofpoint-ORIG-GUID: CrY_jmj-jm-YU9lmQT2W-MVT8aNILW1j 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-19_27,2023-08-18_01,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: 1774732061243005975 X-GMAIL-MSGID: 1774732061243005975 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. Committed as approved after a 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 | 8 +++++++ .../gcc.target/aarch64/sve/cond_convert_7.c | 23 +++++++++++++++++++ 2 files changed, 31 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 6b2d3a11776..851f1af6eac 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4710,6 +4710,14 @@ 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. */ +(simplify + (convert (vec_cond:s @0 @1 @2)) + (if (VECTOR_TYPE_P (type) + && types_match (TREE_TYPE (@0), truth_type_for (type))) + (vec_cond @0 (convert! @1) (convert! @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" } } */