From patchwork Mon Aug 21 03:21:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 136313 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b82d:0:b0:3f2:4152:657d with SMTP id z13csp2761539vqi; Sun, 20 Aug 2023 20:22:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEa9cQ1nEDk8Tukf6OEKJuRzGPrX1JKcW7ijPCTU39FV0obRsC1y4BYDoolFlGhSeM9qFVs X-Received: by 2002:a17:906:8a45:b0:99b:4bab:2841 with SMTP id gx5-20020a1709068a4500b0099b4bab2841mr5637259ejc.26.1692588143908; Sun, 20 Aug 2023 20:22:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692588143; cv=none; d=google.com; s=arc-20160816; b=N5L1AleIzUyVPtjGAZY7LKCNXUZRsKP32ZV/h5mujf/rxhLvW392nys/9s+/Mg1NN4 4tx9e6RoCGTyWXOmb3+MglagIeEaqspr5dfIWAG+6LMy/2hEUft0TBJExoZWeDw5W7FN 9ZR8nXaIAdWgJrqPm2fkdi6/8iLlnCJStLEJLDskNuGWIVQ/kTdPP0SDRSMl1posjnpa IrooNlsikikDK7zZi8BaOfR46222MGhCzMoTirhLRi1UdGNP2PAkY+231F0BZCA4Kvrb ZPMQ73uLDqGQ3WjZ86Q1yO5/zsrfae9FylanvP6MrphdfKfczgvFOfiRfwI1KekZzDQ6 Dd4Q== 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=o9e2IMf3R/AzZV56xy/eLX5do3Ag4Kl9bEusEWuhMGo=; fh=09okz+w4tVyhQmqNBttR063P0zKcIsLE1JRBioNPGC4=; b=INZnidpwaO0UklaGzkQApbXMQQnLuDN0T+um1QsN+9oDpCzCsZah/dpxEvFDsdcT39 IhdfV+OHR3USc6vRUSHG3dbEnIoQSobwMTCA8oEVipB4qTn65RG4xsD1LhBBNPPbbn26 uyWTj/9ywJNgfAnaNoLKXZTGmvwQdfa4DMpx/IptSBb5Ay0mz3DeA241S0EK4p2CQXyN aCzb8+L1kxganfk0SDO6KbL/8WLEC2xtP/7eJDjnexahRDdYfsoaPUiRNFRejY+Xa4Xb AuZKyvrlcD9G8BqiKjp84RojF5MfAikvUc4tqlM36Snso3Y98JV5hX71uqAQViUxZZqW rkCg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iiOLKGBA; 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 p21-20020a1709060dd500b0099233cac125si4915828eji.915.2023.08.20.20.22.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Aug 2023 20:22:23 -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=iiOLKGBA; 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 666083857716 for ; Mon, 21 Aug 2023 03:22:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 666083857716 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692588142; bh=o9e2IMf3R/AzZV56xy/eLX5do3Ag4Kl9bEusEWuhMGo=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=iiOLKGBAPVA50GMvd4/AazOdh0wu9DzzsCG1Tr9b7zEKhOmXwJe6qiznwItYFe/fo V3xPpGh/JBQOnY1L8Jo+ZftnH9lKN9tM7arldzPc04FDci6YZ2q/yw2Ul6Gjn7XMOQ sH27XsGk7XO8eC3Eu24Aa/bt32CuOfBgXaNgqO9A= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by sourceware.org (Postfix) with ESMTPS id BD255385770F for ; Mon, 21 Aug 2023 03:21:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BD255385770F Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37KKUN2e010965 for ; Sun, 20 Aug 2023 20:21:38 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3sjw8jbbb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 20 Aug 2023 20:21:37 -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 20:21:35 -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 20:21:35 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 891AE3F704D; Sun, 20 Aug 2023 20:21:35 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: [PR111002] Sink view_convert for vec_cond Date: Sun, 20 Aug 2023 20:21:23 -0700 Message-ID: <20230821032123.3332286-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 3i-oHFj-GlO2dejAdUwQ7HosVLZOqEiu X-Proofpoint-GUID: 3i-oHFj-GlO2dejAdUwQ7HosVLZOqEiu 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-20_15,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: 1774807305674172376 X-GMAIL-MSGID: 1774807305674172376 Like convert we can sink view_convert into vec_cond but we can only do it if the element types are nop_conversions. This is to allow conversion between signed and unsigned types only. Rather than between integer and float types which mess up the vec_cond so that isel does not understand `a?-1:0` is still that. OK? Bootstrapped and tested on x86_64-linux-gnu and aarch64-linux-gnu. PR tree-optimization/111002 gcc/ChangeLog: * match.pd (view_convert(vec_cond(a,b,c))): New pattern. gcc/testsuite/ChangeLog: * gcc.target/aarch64/sve/cond_convert_8.c: New test. --- gcc/match.pd | 9 ++++++++ .../gcc.target/aarch64/sve/cond_convert_8.c | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 gcc/testsuite/gcc.target/aarch64/sve/cond_convert_8.c diff --git a/gcc/match.pd b/gcc/match.pd index 851f1af6eac..81666f28465 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4718,6 +4718,15 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && types_match (TREE_TYPE (@0), truth_type_for (type))) (vec_cond @0 (convert! @1) (convert! @2)))) +/* Likewise for view_convert of nop_conversions. */ +(simplify + (view_convert (vec_cond:s @0 @1 @2)) + (if (VECTOR_TYPE_P (type) && VECTOR_TYPE_P (TREE_TYPE (@1)) + && known_eq (TYPE_VECTOR_SUBPARTS (type), + TYPE_VECTOR_SUBPARTS (TREE_TYPE (@1))) + && tree_nop_conversion_p (TREE_TYPE (type), TREE_TYPE (TREE_TYPE (@1)))) + (vec_cond @0 (view_convert! @1) (view_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_8.c b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_8.c new file mode 100644 index 00000000000..d8b96e5fcfb --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/sve/cond_convert_8.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -ftree-vectorize -moverride=sve_width=256 -fdump-tree-optimized" } */ +/* PR tree-optimization/111002 */ + +/* We should be able to remove the neg. */ + +void __attribute__ ((noipa)) +f (int *__restrict r, + int *__restrict a, + short *__restrict pred) +{ + for (int i = 0; i < 1024; ++i) + r[i] = pred[i] != 0 ? -1 : 0; +} + + +/* { 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" } } */