From patchwork Thu Aug 24 19:14:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 136866 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp1335868vqm; Thu, 24 Aug 2023 12:16:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGfL8i2MZMmZ+pm+SGF0RJMvtgbChWgmC2U68lFWMOT3wgJbF9nlz5GJMCg8pewwVXD95dx X-Received: by 2002:a05:6512:3d1a:b0:500:a60d:c677 with SMTP id d26-20020a0565123d1a00b00500a60dc677mr611522lfv.59.1692904617184; Thu, 24 Aug 2023 12:16:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692904617; cv=none; d=google.com; s=arc-20160816; b=RK5YT4cqdPJaRpE6X+8qrboLd0lZWlKmCGG20djcbRTU8h64RRiIlRIklFUcw031zn 8dZlX+8pTlXcYsrwVk1XMwVIhSOE/hdtf1AHh3vmeherKP2pPrWoBOWvdJhXUZIb15Uq 0N/6M70C3zANZKWmvthzh3sTlYbWHi2+h+XGQEfP5j7OeKlakHvmAdC4gMzglMP3LA33 ghicUOfEPYFjHxtahmH0tNOCAZCnH9MIxRJFz8W6LJxSVfKjfVYFDrA5wfymV3HJ4/gG CazZy7po/ysc4tnSLZmNuWU5gXc/3IRI0d6tCsDFOC7O6OVp6W1azb7Z+GHBxMf3UZcU nvaQ== 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=5qPbo+1pCMquMgFi2VlLdnKIjk+DRY5c6740cJF3Mn8=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=SOy8tjXX88qwtQUx9v/AFAV6ztWdG3ER+m6XCRInf0TzlVcu6U2bOzWSgaW98kxJPp yjZf+rasTI+o/uTJAXCkBaDXfRSsHX11oivvcCvjXNhjByaLyV10P9jlhdCjecwg3kn7 /RplpXVnsR20K0Kabh3CFM1rWaxdq56CZh/uRE8VSLdpb0atd1enonaKkRA6H9In+ezS mBWRTHNOh/ZEA+8ZccKTLOMIFa91iGxUZJTyLXVvrUzi92NDC2Cpz/EibxiieFt+F0UF 5JSCLUqW4ESWf7ZHeOZ44GGFcxnutwRtjafwoFL3lAfnOVzDRN3ddRpmttAVbcyVVNJd 0N3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Z8bm1NRq; 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 h10-20020aa7de0a000000b00522270f709csi118599edv.514.2023.08.24.12.16.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Aug 2023 12:16:57 -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=Z8bm1NRq; 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 E0E943853559 for ; Thu, 24 Aug 2023 19:15:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0E943853559 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692904557; bh=5qPbo+1pCMquMgFi2VlLdnKIjk+DRY5c6740cJF3Mn8=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=Z8bm1NRqF35IDSFRKhlrGwYyEtjjWj+YFDfjZpWnhh1OIV+JeFDXKJvwImO2CTngT 00xJccmhkk5we/yFcw1WK84ts0Le8uC74uxC2mGMduDWnnRlMo4Smkm4AVo8fEfc/x bEZAULTtkdN2UglQaRyOsu/9B9P1qaOD1MdushBQ= 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 1C6F3385842E for ; Thu, 24 Aug 2023 19:15:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1C6F3385842E 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 37OHwCo3001835 for ; Thu, 24 Aug 2023 12:15:07 -0700 Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3sn20d14tm-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 24 Aug 2023 12:15:06 -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; Thu, 24 Aug 2023 12:15:03 -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; Thu, 24 Aug 2023 12:15:03 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 712AF3F70AC; Thu, 24 Aug 2023 12:15:03 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH 1/3] MATCH: Move `a ? one_zero : one_zero` matching after min/max matching Date: Thu, 24 Aug 2023 12:14:53 -0700 Message-ID: <20230824191455.3547513-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: ah7aDjCfHQ_-rD3U826D_f_g54aHYeDe X-Proofpoint-ORIG-GUID: ah7aDjCfHQ_-rD3U826D_f_g54aHYeDe 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-24_15,2023-08-24_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, 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: 1775139152059308106 X-GMAIL-MSGID: 1775139152059308106 In PR 106677, I noticed that on the trunk we were producing: ``` _25 = SR.116_117 == 0; _27 = (unsigned char) _25; _32 = _27 | SR.116_117; ``` From `SR.115_117 != 0 ? SR.115_117 : 1` Rather than: ``` _119 = MAX_EXPR <1, SR.115_117>; ``` Or (rather) ``` _119 = SR.115_117 | 1; ``` Due to the order of the patterns. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * match.pd (`a ? one_zero : one_zero`): Move below detection of minmax. --- gcc/match.pd | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 890f050cbad..c87a0795667 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4950,24 +4950,6 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) ) ) -(simplify - (cond @0 zero_one_valued_p@1 zero_one_valued_p@2) - (switch - /* bool0 ? bool1 : 0 -> bool0 & bool1 */ - (if (integer_zerop (@2)) - (bit_and (convert @0) @1)) - /* bool0 ? 0 : bool2 -> (bool0^1) & bool2 */ - (if (integer_zerop (@1)) - (bit_and (bit_xor (convert @0) { build_one_cst (type); } ) @2)) - /* bool0 ? 1 : bool2 -> bool0 | bool2 */ - (if (integer_onep (@1)) - (bit_ior (convert @0) @2)) - /* bool0 ? bool1 : 1 -> (bool0^1) | bool1 */ - (if (integer_onep (@2)) - (bit_ior (bit_xor (convert @0) @2) @1)) - ) -) - /* Optimize # x_5 in range [cst1, cst2] where cst2 = cst1 + 1 x_5 ? cstN ? cst4 : cst3 @@ -5298,6 +5280,26 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && integer_nonzerop (fold_build2 (GE_EXPR, boolean_type_node, @3, @1))) (max @2 @4)))))) +#if GIMPLE +(simplify + (cond @0 zero_one_valued_p@1 zero_one_valued_p@2) + (switch + /* bool0 ? bool1 : 0 -> bool0 & bool1 */ + (if (integer_zerop (@2)) + (bit_and (convert @0) @1)) + /* bool0 ? 0 : bool2 -> (bool0^1) & bool2 */ + (if (integer_zerop (@1)) + (bit_and (bit_xor (convert @0) { build_one_cst (type); } ) @2)) + /* bool0 ? 1 : bool2 -> bool0 | bool2 */ + (if (integer_onep (@1)) + (bit_ior (convert @0) @2)) + /* bool0 ? bool1 : 1 -> (bool0^1) | bool1 */ + (if (integer_onep (@2)) + (bit_ior (bit_xor (convert @0) @2) @1)) + ) +) +#endif + /* X != C1 ? -X : C2 simplifies to -X when -C1 == C2. */ (simplify (cond (ne @0 INTEGER_CST@1) (negate@3 @0) INTEGER_CST@2)