From patchwork Sun May 23 09:41:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 1482467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=pQQn3u+T; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FnwMp1VJZz9sPf for ; Sun, 23 May 2021 19:41:24 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80749384B821; Sun, 23 May 2021 09:41:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 80749384B821 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1621762872; bh=GUorm8Ngia4teP5fUMUVO7B0bpKd9SydtCXbDiJov1U=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=pQQn3u+TPU2CbDXRtRP36ChiJHMr2cdeDDlRt4h9lWzLdjJgsm54A3LxRBeIVXKzr P6Ulfqv8qIV2g8IB9OO2zU1ukSxVlJn/DP9x6y7lTrfpLYIqtVgIwhaX0soyidS1af /IMkL0/FOiAUd1dFUWNkCu0nctBOflkCVeexXQUs= 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 624363857804 for ; Sun, 23 May 2021 09:41:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 624363857804 Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14N9Pmfh011416 for ; Sun, 23 May 2021 02:41:09 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 38q1fnt92d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sun, 23 May 2021 02:41:08 -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.2; Sun, 23 May 2021 02:41:04 -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.2 via Frontend Transport; Sun, 23 May 2021 02:41:04 -0700 Received: from linux.wrightpinski.org.com (unknown [10.69.242.197]) by maili.marvell.com (Postfix) with ESMTP id A7C6F3F7048; Sun, 23 May 2021 02:41:06 -0700 (PDT) To: Subject: [PATCHv2] Add a couple of A?CST1:CST2 match and simplify optimizations Date: Sun, 23 May 2021 02:41:03 -0700 Message-ID: <1621762863-26665-1-git-send-email-apinski@marvell.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Proofpoint-GUID: Ys7NsIfvZSmT9aokWhIzWJhw-LZpQuyU X-Proofpoint-ORIG-GUID: Ys7NsIfvZSmT9aokWhIzWJhw-LZpQuyU X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-05-22_08:2021-05-20, 2021-05-22 signatures=0 X-Spam-Status: No, score=-13.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: apinski--- via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: apinski@marvell.com Cc: Andrew Pinski Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" From: Andrew Pinski Instead of some of the more manual optimizations inside phi-opt, it would be good idea to do a lot of the heavy lifting inside match and simplify instead. In the process, this moves the three simple A?CST1:CST2 (where CST1 or CST2 is zero) simplifications. OK? Boostrapped and tested on x86_64-linux-gnu with no regressions. Differences from V1: * Use bit_xor 1 instead of bit_not to fix the problem with boolean types which are not 1 bit precision. Thanks, Andrew Pinski gcc: * match.pd (A?CST1:CST2): Add simplifcations for A?0:+-1, A?+-1:0, A?POW2:0 and A?0:POW2. --- gcc/match.pd | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/gcc/match.pd b/gcc/match.pd index 1fc6b7b1557..ad6b057c56d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3711,6 +3711,47 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (integer_all_onesp (@1) && integer_zerop (@2)) @0)))) +/* A few simplifications of "a ? CST1 : CST2". */ +/* NOTE: Only do this on gimple as the if-chain-to-switch + optimization depends on the gimple to have if statements in it. */ +#if GIMPLE +(simplify + (cond @0 INTEGER_CST@1 INTEGER_CST@2) + (switch + (if (integer_zerop (@2)) + (switch + /* a ? 1 : 0 -> a if 0 and 1 are integral types. */ + (if (integer_onep (@1)) + (convert (convert:boolean_type_node @0))) + /* a ? -1 : 0 -> -a. */ + (if (integer_all_onesp (@1)) + (negate (convert (convert:boolean_type_node @0)))) + /* a ? powerof2cst : 0 -> a << (log2(powerof2cst)) */ + (if (!POINTER_TYPE_P (type) && integer_pow2p (@1)) + (with { + tree shift = build_int_cst (integer_type_node, tree_log2 (@1)); + } + (lshift (convert (convert:boolean_type_node @0)) { shift; }))))) + (if (integer_zerop (@1)) + (with { + tree booltrue = constant_boolean_node (true, boolean_type_node); + } + (switch + /* a ? 0 : 1 -> !a. */ + (if (integer_onep (@2)) + (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } ))) + /* a ? -1 : 0 -> -(!a). */ + (if (integer_all_onesp (@2)) + (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))) + /* a ? powerof2cst : 0 -> (!a) << (log2(powerof2cst)) */ + (if (!POINTER_TYPE_P (type) && integer_pow2p (@2)) + (with { + tree shift = build_int_cst (integer_type_node, tree_log2 (@2)); + } + (lshift (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )) + { shift; })))))))) +#endif + /* Simplification moved from fold_cond_expr_with_comparison. It may also be extended. */ /* This pattern implements two kinds simplification: