From patchwork Thu May 4 23:40:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 90263 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp21096vqo; Thu, 4 May 2023 16:41:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4og/bm4g8TJJ1eE4qRQbQJx0lbDqwaDK4kL2Xl091hj3dURV/ydqyndpNNtHKwuqaQIGdt X-Received: by 2002:aa7:d941:0:b0:50b:d83b:9c61 with SMTP id l1-20020aa7d941000000b0050bd83b9c61mr3105356eds.32.1683243704828; Thu, 04 May 2023 16:41:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683243704; cv=none; d=google.com; s=arc-20160816; b=gOK3+YZ6mqvdTVs8WKVCe4a39NFdtWUkwgqvyIJ2lBdV2pbir7W77zkfdHEAXpRtTJ NQH7II6x4KqCoJ0UeKzIDidB50yre1emajtFyX2sHMprTB6RkZ/vyvqAS/6NODXg4RWO bjEJ7EMXG72AcACQuutdtjea5e0yoYYpDER8Y/ovfh5sgM++SggfdnHe01nFoTdyRzLs O861lPu+I2H+WhhDw/i+Q9W2D+JgIJsizuI3a1pz/Cna3oHuq/vScsfWhwaqQwPcnigk wiedhWOXjLASoOpDKn4Ty2wDJ2UmDSxsd7qfqEGaWGv1CdB2W0fralWI9a42vGtl9gS3 AKHw== 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=bkPjgpPCQ34Cjmy3V/oX2A/TgzFktsQkY+pNyBRUU6w=; b=QNsKJKD4E3WW0wC14Dy9GMu3YiKU2qnG63pbkSZq8nMmuEIvxMwIZCaMzduoUItbUn +pM5otm8fJ5l5HFyg1JXE9k9dW7er3Za4OeYSicDsYG9LPdrKuPCpjPjhHYz1mHQBVMZ I79XqP10qMfCefbY3h6yFdNEDLwTiM9tERcJsCLkHUXn4pINFClmE5ewEgzeDq1lS1hx dwkxBk/N0jcSReJ48I4J4cwHPGS2TcSECwtXsl5OqpZOsdsKSkrhogxs7Y8Z1jIvEF09 joWSjk5A//Ne6QrHKArs2ZWxUFB1kh/1H61KqkduwT8Vw10yby0Q7XjN1Caw1+1OHpvQ XMVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=INEihJiB; 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 sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id c10-20020aa7d60a000000b005069701844asi3575717edr.408.2023.05.04.16.41.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 May 2023 16:41:44 -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=INEihJiB; 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 0BB32385B510 for ; Thu, 4 May 2023 23:41:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BB32385B510 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683243697; bh=bkPjgpPCQ34Cjmy3V/oX2A/TgzFktsQkY+pNyBRUU6w=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=INEihJiBlX48jzN/eY08eZ6H83SZoWObuRYYV0/F+OdsmoEzOslbBIOA4koVg9N63 HV30OWsvzLc/uIhbsAVctk/WWmdwCVWtxN22FrHHRQykXy8r3lycGiEQO83setwbHG a+lK7njz0Z/NnCMscjnhB0R3fadfQ6z3CZ3SBl9U= 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 0DC103858D35 for ; Thu, 4 May 2023 23:40:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0DC103858D35 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 344NNone014300 for ; Thu, 4 May 2023 16:40:52 -0700 Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0b-0016f401.pphosted.com (PPS) with ESMTPS id 3qc0nebrxc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Thu, 04 May 2023 16:40:52 -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; Thu, 4 May 2023 16:40:50 -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; Thu, 4 May 2023 16:40:50 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id E1E5A5B6929; Thu, 4 May 2023 16:40:49 -0700 (PDT) To: CC: Andrew Pinski Subject: [PATCH] MATCH: Add ABSU == 0 to a == 0 simplification Date: Thu, 4 May 2023 16:40:42 -0700 Message-ID: <20230504234042.992763-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Proofpoint-GUID: qunNNABUcGt9-A6bdaPr_TTDIy1d4wPI X-Proofpoint-ORIG-GUID: qunNNABUcGt9-A6bdaPr_TTDIy1d4wPI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-05-04_15,2023-05-04_01,2023-02-09_01 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_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765008950950929148?= X-GMAIL-MSGID: =?utf-8?q?1765008950950929148?= There is already an `ABS == 0` to `a == 0` pattern, this just extends that to ABSU too. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/109722 gcc/ChangeLog: * match.pd: Extend the `ABS == 0` pattern to cover `ABSU == 0` too. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/abs-1.c: New test. --- gcc/match.pd | 11 ++++++----- gcc/testsuite/gcc.dg/tree-ssa/abs-1.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/abs-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 08a4f8ebdc1..ceae1c34abc 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5807,11 +5807,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (tem && !TREE_OVERFLOW (tem)) (scmp @0 { tem; })))))) -/* Convert ABS_EXPR == 0 or ABS_EXPR != 0 to x == 0 or x != 0. */ -(for op (eq ne) - (simplify - (op (abs @0) zerop@1) - (op @0 @1))) +/* Convert ABS[U]_EXPR == 0 or ABS[U]_EXPR != 0 to x == 0 or x != 0. */ +(for op (abs absu) + (for eqne (eq ne) + (simplify + (eqne (op @0) zerop@1) + (eqne @0 { build_zero_cst (TREE_TYPE (@0)); })))) /* From fold_sign_changed_comparison and fold_widened_comparison. FIXME: the lack of symmetry is disturbing. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c b/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c new file mode 100644 index 00000000000..ce404111103 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/abs-1.c @@ -0,0 +1,12 @@ +/* PR tree-optimization/109722 */ +/* { dg-do compile } */ +/* { dg-options "-O -fdump-tree-gimple -fdump-tree-optimized" } */ + +int g(signed char x){ + x = x < 0 ? -x : x; + return x == 0; +} + +/* This should work even if int is 16bits. */ +/* { dg-final { scan-tree-dump "ABSU_EXPR" "gimple"} } */ +/* { dg-final { scan-tree-dump-not "ABSU_EXPR" "optimized"} } */