From patchwork Mon Dec 25 04:00:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andrew Pinski (QUIC)" X-Patchwork-Id: 183118 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp221047dyb; Sun, 24 Dec 2023 20:01:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrkQ3b5ViSTa38v6CWUbTvyZrCNntkG1v7OYzJEf3gAvMQtnVYrjEPvVFP/VeXI7rHYKCv X-Received: by 2002:a05:620a:4901:b0:77f:b145:8590 with SMTP id vy1-20020a05620a490100b0077fb1458590mr5844375qkn.125.1703476895706; Sun, 24 Dec 2023 20:01:35 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1703476895; cv=pass; d=google.com; s=arc-20160816; b=QwT67zylij3h2G2XJqBy4kpIjCbGXuXxeIkP+KRfE9Ktr9poyWT3GgNLFrSnO2qitV p8+N+KSM94CoA0AcjAkLV6Cb/6Gde0kA2lLZoWZmbXJRneIET/e/lIuchCYadJ1pCYxO VWchk4Zo21EIm5Srhy55E/UNCK9aIGuoSd9u89+OVj5NmtdtQp6/0jmeEK40A3of/O25 8qkmofnS/JmlkYQ3iAwf7ytIa1a8XuuJ19nOSBapnk3+0N092e4iDBaO/kefE1o8bR7E 5OYnDXHDKpMEdWK1/nnfzE9KLamNAWurDC61QCVbSEFBxd5+yUBWblW2nkv064HvdlQU esKQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=+FOutrD8SgDBVY4dlWgWPFSwBZGgueY0UuUmORtYang=; fh=o3CEdS3yGN/eIa89Zn0Kf01WYLxTE9IjKuSQGVPeOHI=; b=R81lXNfFHWTRovCs5LqCPv5rDosmOze/0P9cJc7TJIE7OSj5K9r7h8Hwtsh6XhM2ha z/yHFRqZnWCUoUA/vvgOcQ/Bzq4Sg5dpFWuOPMe3jMmAIbyHJkVg0qPONkqtCDxkhUgW rVgtAzbg/WsOXluc1ZsGm2SevWKtRAsr/hXPJFKp+2JgWl4BtL8bxDrRpgk0m0e1hhP3 1J4wOdvT2f2FPQu0/lL+oS7omi8+5uiaflqSHODi8FugiPOG2y4L2fjvxfxiA3QLFxiI +Jy1CGbkAbNnE8GeXFaE9sJNv/aPQUOG5kynx9IGrR2QWvf5A1SV/hnZ81lXhhj0O+wm KZgw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Qsmpq7HB; arc=pass (i=1); 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=quicinc.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d15-20020a05620a240f00b00780d98f5184si10006118qkn.521.2023.12.24.20.01.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Dec 2023 20:01:35 -0800 (PST) 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=@quicinc.com header.s=qcppdkim1 header.b=Qsmpq7HB; arc=pass (i=1); 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=quicinc.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 654113858C42 for ; Mon, 25 Dec 2023 04:01:35 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id 9ED723858C42 for ; Mon, 25 Dec 2023 04:00:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9ED723858C42 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=quicinc.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9ED723858C42 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703476852; cv=none; b=Ug9q2dKft3z9RVVe8SGamUhb7jPTYIDFEqWCblG/k7rw3nyVXmG6EszR6tJ8XhJi9ejeFa+lEe5uV+Dp6/sQfpe+/lXFp0+5HoXWShGZgBRBT4NMrLhBEwTAieAr2RLZGlkmPl55vrt4rxqHXXKp/U1TCmU5XdrmnOBkYiWpcg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1703476852; c=relaxed/simple; bh=LPQdhAQeEMjxjx8816TgzVlULjXb6WD0Xuezwd2cMGc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FSXXioVJMSSXij7lM8EczjcMIBf3QfIBxQ52xdxcsE9wJpw78aZ9V2bU6y7htW43sgdkXu7IYB5nP48zAOuQqY19MbKRiuwYgipkXMx3HzD3KULaVPbn/IEZQxnbQBJw7qv3teHK8yc9vXv4EH0w0J/8OTOUFCgkrFGx3YBuoyE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BP3nbBi016747 for ; Mon, 25 Dec 2023 04:00:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=qcppdkim1; bh=+FOutrD 8SgDBVY4dlWgWPFSwBZGgueY0UuUmORtYang=; b=Qsmpq7HBFJE+zvHarbXHJ9P RGCd1jtHhERrGmfDVi+7sQSuAF2VhjGP67IeMliQG52VfDPHWg2UzuNY8dYJsBWw nlCC6o+11HbpnQCZTjvpcWwHl7olx3jarV0W7twM7VyyB3DxcaVi4LWk/iGdTMI4 IOg1FZ2rkLlCPYN274E2OMHMAQZunUjjrra+8Bdoif4c8V8Ze0XcHzXxZCysSuwK WSkTtIe9c4tNM9Yt6kY27msUyqJB53gRyEOPU0lkd+hezpCHssbW+QxOtp+fKBKX pzhlR52MFNwU7ZZ62JdoFfYNtTTCGpHtoB4+UMssxucZsjNyqD2npoe8Ou/j2Uw= = Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3v5pjbjy2r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 25 Dec 2023 04:00:47 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BP40k6I027989 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 25 Dec 2023 04:00:46 GMT Received: from hu-apinski-lv.qualcomm.com (10.49.16.6) by nasanex01c.na.qualcomm.com (10.45.79.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Sun, 24 Dec 2023 20:00:46 -0800 From: Andrew Pinski To: CC: Andrew Pinski Subject: [COMMITTED] match: Improve `(a != b) ? (a + b) : (2 * a)` pattern [PR19832] Date: Sun, 24 Dec 2023 20:00:34 -0800 Message-ID: <20231225040034.251374-1-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) To nasanex01c.na.qualcomm.com (10.45.79.139) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-GUID: EOWVJMSL0Qf4gLqLPrLWlHdg34_fdZd6 X-Proofpoint-ORIG-GUID: EOWVJMSL0Qf4gLqLPrLWlHdg34_fdZd6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 impostorscore=0 adultscore=0 malwarescore=0 spamscore=0 bulkscore=0 mlxlogscore=890 mlxscore=0 phishscore=0 lowpriorityscore=0 clxscore=1011 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312250026 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, PLING_QUERY, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1786224989042612159 X-GMAIL-MSGID: 1786224989042612159 In the testcase provided, we would match f_plus but not g_plus due to a missing `:c` on the plus operator. This fixes the oversight there. Note this was noted in https://github.com/llvm/llvm-project/issues/76318 . Committed as obvious after bootstrap/test on x86_64-linux-gnu. PR tree-optimization/19832 gcc/ChangeLog: * match.pd (`(a != b) ? (a + b) : (2 * a)`): Add `:c` on the plus operator. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/phi-opt-same-2.c: New test. Signed-off-by: Andrew Pinski --- gcc/match.pd | 2 +- .../gcc.dg/tree-ssa/phi-opt-same-2.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/phi-opt-same-2.c diff --git a/gcc/match.pd b/gcc/match.pd index d57e29bfe1d..a980c4d7e94 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -5694,7 +5694,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) @2))) /* (a != b) ? (a + b) : (2 * a) -> (a + b) */ (simplify - (cnd (ne:c @0 @1) (plus@2 @0 @1) (mult @0 uniform_integer_cst_p@3)) + (cnd (ne:c @0 @1) (plus:c@2 @0 @1) (mult @0 uniform_integer_cst_p@3)) (if (wi::to_wide (uniform_integer_cst_p (@3)) == 2) @2)) ) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-same-2.c b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-same-2.c new file mode 100644 index 00000000000..94fb6a92cea --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/phi-opt-same-2.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-phiopt1 -fdump-tree-optimized" } */ +/* PR tree-optimization/19832 */ + +int f_plus(int a, int b) +{ + if (a != b) return a + b; + return a + a; +} + +int g_plus(int a, int b) +{ + if (b != a) return a + b; + return a + a; +} + +/* All of the above function's if should have been optimized away even in phiopt1. */ +/* { dg-final { scan-tree-dump-not "if " "phiopt1" } } */ +/* { dg-final { scan-tree-dump-not "if " "optimized" } } */