From patchwork Thu Jan 11 04:23:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Andrew Pinski (QUIC)" X-Patchwork-Id: 187166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:2411:b0:101:2151:f287 with SMTP id m17csp1223027dyi; Wed, 10 Jan 2024 20:25:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IFHL771oJAQiMXRCso5jvR1FZyIAcELsVP1HH2pLqltl3BdAUitLQsXd/cdKe/+LVRTpk2x X-Received: by 2002:a0c:ef8a:0:b0:681:3775:ed4b with SMTP id w10-20020a0cef8a000000b006813775ed4bmr93783qvr.29.1704947100572; Wed, 10 Jan 2024 20:25:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704947100; cv=pass; d=google.com; s=arc-20160816; b=MebKDKlC4LZTgS5wPHEPablwGlIxUckNffsTASlJrGY4BsXX7cF2QqUINJBv6JBSpd ZkHv9xSgX0dBJGAHU2rOMftdYevFq00Krl5cEd3WaX30oFZFG0ypTSaXxRXBxu7bX9s8 LEuI3pcm0DLXIphCFHB2yrVVlTIUtqx/zobS71/oulXx66n6OgnaHjfIFoiX+gtnYE5F UeGK2zk89+BeRpVTPg4VXahvSN+ZPodpwB1pFCA2dTO3s1tGyaj0ltEhA5GL1J7LhCv/ m1pGj2GmkVZybo640snzNAOD0lJT4piWIYcdlbyZScDwyZfSoX8JsVgJ+oJym9jV4Egx Sxcg== 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=3z8Rm5c4H0Fb0fHYo0KomRHjkqgYNtv5zp8sP/1N0KI=; fh=o3CEdS3yGN/eIa89Zn0Kf01WYLxTE9IjKuSQGVPeOHI=; b=DPczlWeXusoYJOfvoIvNMHjYxV3fABtbyalMwt9qkttitoh5uMnu3ZlH0cTEQuyVHs sG581J/GOP/OeeOeRG4/u3j5iYOMdgqiS7FrbpPkU4hbZ6k0EXqltiGp3fnUxMAv3EGl bKWNRKwQyMKVfMTAT+r80neL3czp22qDeDxzyu33mdwFZdtf/LiqYOia+uDrW+7wwBui HXx9GcD0HB1Ln3qGf3aN3vyAe5BG6nJ1VmuGwYZ8anVc9UNje0BlsdSAV5PaY69POm04 0o7ecJCNeoO/nyhWOsQ2D2bGZZMsEcX5ASpq8uYgImdyAwLkQlYu6LK7X1iG463QE3L9 eI5w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=SVRDiymc; 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 v8-20020a0ce1c8000000b0067d37aee784si107972qvl.4.2024.01.10.20.25.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jan 2024 20:25:00 -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=SVRDiymc; 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 40D34385801E for ; Thu, 11 Jan 2024 04:25:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by sourceware.org (Postfix) with ESMTPS id 4B9BB3858D38 for ; Thu, 11 Jan 2024 04:24:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B9BB3858D38 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 4B9BB3858D38 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704947049; cv=none; b=HLjPhxFflZi0Y5ljyy61f14iFik9QnBznSkei6DrZ+tJbWSVscqXCu1/5HHJpHHnc6RGqSM8ec+JdXNLq0caMhtFk+ySHVFqWGwJbl8QTjePsrWQzP64bCIbCGFOzZUBzftm27waK2a9EYNCKyGwBXYhxuR9R86WH2/g4rYPtEk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704947049; c=relaxed/simple; bh=Bd9rTYVsqKH3gy35eRRvLiGeDyLN4Cq695R1KZTFaBg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=YEqcSewNI4g/qtyhbaOq/I/tgY4B8d/TLIMCjULCoYy4XvIJSmHB2/WwIrt7JAYUAMjkKimliMw+8zkSW1MgX5Ya49McGORjuNbJVOWdngnt0BI16Sz/EVdp/3eUpWJx9qCSG/SVBUqEcm/Ffry3Onfy4H04nKKBOjLCNADGRcU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 40B4KFpA009257 for ; Thu, 11 Jan 2024 04:24:05 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=3z8Rm5c 4H0Fb0fHYo0KomRHjkqgYNtv5zp8sP/1N0KI=; b=SVRDiymcQweSG65aHblpiN/ dN35s3cMVVo6op+pMvRQmL2nbkD0If8WmtMQB18NR/+WyReuvgvwKrglYuMWVGAM QLNyJQCuQS9uejbIk9RwsWOY+SHpxYUqW1kvaGrERQ59f70mgSa+iKZjybeJf9NC FU46bhJmO3cHBWylMnBCqp6fPAxLYdzRAAxmVZOC8aveUl2wRE07dD03BmZSsEx+ 2kY6FAdaZgHE6/xo7bso9rHP5QnjN+fpQd46tKP4KhTmImW+CDeVy3Bqmzp4ruuE +F2ImsPT9ar4yHpQ9GDdRvbmnzad/oz9Iomd12cCaspSnEGwhnpppnG58V0a5+Q= = Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vhvhp1mhr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 Jan 2024 04:24:04 +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 40B4O33Z026266 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 Jan 2024 04:24:03 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; Wed, 10 Jan 2024 20:24:03 -0800 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] match: Delay folding of 1/x into `(x+1u)<2u?x:0` until late [PR113301] Date: Wed, 10 Jan 2024 20:23:43 -0800 Message-ID: <20240111042343.1172849-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: nalasex01c.na.qualcomm.com (10.47.97.35) 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: 6K6TYKXofw_tlnU11faj_OBqlgiQNzaE X-Proofpoint-ORIG-GUID: 6K6TYKXofw_tlnU11faj_OBqlgiQNzaE 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_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 malwarescore=0 impostorscore=0 adultscore=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 spamscore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401110032 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, RCVD_IN_DNSWL_NONE, 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: 1787766610951355436 X-GMAIL-MSGID: 1787766610951355436 Since currently ranger does not work with the complexity of COND_EXPR in some cases so delaying the simplification of `1/x` for signed types help code generation. tree-ssa/divide-8.c is a new testcase where this can help. Bootstrapped and tested on x86_64-linux-gnu with no regressions. PR tree-optimization/113301 gcc/ChangeLog: * match.pd (`1/x`): Delay signed case until late. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/divide-8.c: New test. Signed-off-by: Andrew Pinski --- gcc/match.pd | 12 +++++++----- gcc/testsuite/gcc.dg/tree-ssa/divide-8.c | 13 +++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/divide-8.c diff --git a/gcc/match.pd b/gcc/match.pd index d75babd86c2..81a389057cf 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -560,7 +560,8 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) 1 / X -> X >= -1 && X <= 1 ? X : 0 for signed integer X. But not for 1 / 0 so that we can get proper warnings and errors, and not for 1-bit integers as they are edge cases better handled - elsewhere. */ + elsewhere. Delay the conversion of the signed division until late + because `1 / X` is simplier to handle than the resulting COND_EXPR. */ (simplify (trunc_div integer_onep@0 @1) (if (INTEGRAL_TYPE_P (type) @@ -569,10 +570,11 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) && (!flag_non_call_exceptions || tree_expr_nonzero_p (@1))) (if (TYPE_UNSIGNED (type)) (convert (eq:boolean_type_node @1 { build_one_cst (type); })) - (with { tree utype = unsigned_type_for (type); } - (cond (le (plus (convert:utype @1) { build_one_cst (utype); }) - { build_int_cst (utype, 2); }) - @1 { build_zero_cst (type); }))))) + (if (!canonicalize_math_p ()) + (with { tree utype = unsigned_type_for (type); } + (cond (le (plus (convert:utype @1) { build_one_cst (utype); }) + { build_int_cst (utype, 2); }) + @1 { build_zero_cst (type); })))))) /* Combine two successive divisions. Note that combining ceil_div and floor_div is trickier and combining round_div even more so. */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/divide-8.c b/gcc/testsuite/gcc.dg/tree-ssa/divide-8.c new file mode 100644 index 00000000000..b8149088177 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/divide-8.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ +/* PR tree-optimization/113301 */ +/* We should figure out that 1/(x+1) range is [-1,1] + and then /2 is always 0. */ + +void link_error(void); +void func(int x){ + int c=(1/(x+1))/2; + if (c != 0) + link_error(); +} +/* { dg-final { scan-tree-dump-not "link_error " "optimized" } } */