From patchwork Sun Dec 10 19:56:49 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: 176399 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6673565vqy; Sun, 10 Dec 2023 11:57:38 -0800 (PST) X-Google-Smtp-Source: AGHT+IEdNFh0fyy5p/9dZ+3RdVCunJJjEzI6UwWZr1L1a4HdNNQM9C8MMS7zfWfTOkg+RtvtHCCK X-Received: by 2002:ac8:5a8d:0:b0:425:7f98:3867 with SMTP id c13-20020ac85a8d000000b004257f983867mr5738664qtc.112.1702238258258; Sun, 10 Dec 2023 11:57:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702238258; cv=pass; d=google.com; s=arc-20160816; b=b3+75RHzMn/UcbqWWcVq9CSsbPwIFdI/GJZgIqssOsZlFlWQjSyU9vz4OMb1AounKP emkdOiRsNBWvGTOigNSAdPrI646/TpCej7uF0hIJT9QAuFJvIl64Eg0GCJ5hD1dR9kgm DpVmZzXpshEW+Ejma2ZWk0PZftie7enmvqgPDov/hVrF/cYOHbakKlsZ4hGsh7uzLnRr /WgMaw0CTIVmdeGg9Y3skWJTprLbtP8OrG/YBbxC0qLAl/DSHqw/7FTBv2Jzwz8QW5Ij 0/9Jy4q69AGRG7gOvH03KO24Q4gjLW15s5GVajPntRBtmA2040gYqRMGflB2lJD+aiq4 eNzw== 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:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=txEAFAqEXjDPtiur+jatS4MpwGgS/t1NiGcTu9xoin8=; fh=gk9A5O7Gbglvz1MjrRQ4hZ2i3c68kYkpOZJg1emXh+g=; b=WojjTq1jrRdPOe7n2LmQ6oGe4J2u2MFIsmPK5fDA4AN6yKJ5/9Tlh2FCK6jLMftDyD nD2PSgg/ZG8Cgpuk6lVBtHpns8PJxxMsHJEiRZXNsfAnZxNOwIMQip7Y37s6vYCpLwNf tBymgmQoIVM/xJi1ISCVJ0Vka/5q1dwVq/Hgm5mpQA0FCUcQKY1FbXx+otLCFF5BPT15 jP7qJbGz42Pl1y/xKpJfm42sfAHwwl1srVQe5McNTZ9XSPAB8qqQLGjfbm89Ch7b8x6x +H678qtmlpT/ZPl+Ufy/1qYRm2TUiseiX826OyjU/laHWf3T4Ywcfh/QWTiIwcmgiIA5 g9IA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=M3nSErg3; 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 z1-20020ac87ca1000000b0042377f488b3si6452852qtv.181.2023.12.10.11.57.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 11:57:38 -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=M3nSErg3; 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 71DA2385AC3A for ; Sun, 10 Dec 2023 19:57:32 +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 AE7B5385829D for ; Sun, 10 Dec 2023 19:57:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE7B5385829D 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 AE7B5385829D 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=1702238224; cv=none; b=hZg1F3KVRvil3wAc7k/GIOFKrqj2zxfvgg6W2qLtArV1XFvCLXujoBBc8sZiQHt3APsr5DarPCgrVNDwdg/OnY+Atmo3TPWFq07TeYiwmswofjahXF9qQyyDYHXCjoWAaPUoTAQU8+6Mrr6L1wlBDIxEuopLxdC2z5d7Hb5AOSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702238224; c=relaxed/simple; bh=pcQjXJXxAktrUUZdMid1lR75kkj4yyjL3shlPPcTn5U=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=LiMCYpMsg1ZAYIo7iRZu9O14VA287I1TDk91EN3nSbaNuv2gNeZSqi1goDMrGtqeZQwm4iOTO/Xw6s4Hs9oi309clOX7tPh//VEPnieYsjDFEzEcP8DghE8V8eslM1euYlBqfHxjl65SV07m7N+U3cPv+JIfQC7qYcqVG4KLUbI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BAJhrIp002823 for ; Sun, 10 Dec 2023 19:57:01 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=txEAFAqEXjDPtiur+jatS4MpwGgS/t1NiGcTu9xoin8=; b=M3 nSErg3cAZwumL04e6NLuxXIQi0+goScde5esX5DFIfcAImuTbHu3oBSecG3KdmJD Ig0grhLd5sEHSoL5IWFTbQvDpwv/XabAelozrqtklg+ORf8mkRNiG0+73remhjMX fPpKgCVUlKbF8GyeKGJvU1VnPKE+09O/yis/tfj/e8/5F+wUu/0vi2HWAvHnIkUg at+/Y+EA/U0GpWg1R6w6VkldT734pLGT5IRMtIRMapR2aCfWDwxvYsCOcU0bqunV qpvUXEND5PIQT5tuCIHtOdJY9WQk+2Fbljnb8ql0PU6BoV461ouYKUz7twp4gYGl 0apDseCy3NGdntuJNwuA== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uwjyjr1x9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 10 Dec 2023 19:57:01 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BAJv0dJ013508 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 10 Dec 2023 19:57:00 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, 10 Dec 2023 11:57:00 -0800 From: Andrew Pinski To: Subject: [PATCH 1/2] analyzer: Remove check of unsigned_char in maybe_undo_optimize_bit_field_compare. Date: Sun, 10 Dec 2023 11:56:49 -0800 Message-ID: <20231210195650.1772459-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231210195650.1772459-1-quic_apinski@quicinc.com> References: <20231210195650.1772459-1-quic_apinski@quicinc.com> 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: 72YBhQWuhdCi5vxSLZEDaryAf4vR7lAE X-Proofpoint-ORIG-GUID: 72YBhQWuhdCi5vxSLZEDaryAf4vR7lAE 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 mlxscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 adultscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=715 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312100175 X-Spam-Status: No, score=-13.4 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, 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: 1784926184111907104 X-GMAIL-MSGID: 1784926184111907104 From: Andrew Pinski The check for the type seems unnecessary and gets in the way sometimes. Also with a patch I am working on for match.pd, it causes a failure to happen. Before my patch the IR was: _1 = BIT_FIELD_REF ; _2 = _1 & 1; _3 = _2 != 0; _4 = (int) _3; __analyzer_eval (_4); Where _2 was an unsigned char type. And After my patch we have: _1 = BIT_FIELD_REF ; _2 = (int) _1; _3 = _2 & 1; __analyzer_eval (_3); But in this case, the BIT_AND_EXPR is in an int type. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/analyzer/ChangeLog: * region-model-manager.cc (maybe_undo_optimize_bit_field_compare): Remove the check for type being unsigned_char_type_node. --- gcc/analyzer/region-model-manager.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc index b631bcb04d0..26c34e38875 100644 --- a/gcc/analyzer/region-model-manager.cc +++ b/gcc/analyzer/region-model-manager.cc @@ -596,9 +596,6 @@ maybe_undo_optimize_bit_field_compare (tree type, tree cst, const svalue *arg1) { - if (type != unsigned_char_type_node) - return NULL; - const binding_map &map = compound_sval->get_map (); unsigned HOST_WIDE_INT mask = TREE_INT_CST_LOW (cst); /* If "mask" is a contiguous range of set bits, see if the From patchwork Sun Dec 10 19:56:50 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: 176398 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp6673551vqy; Sun, 10 Dec 2023 11:57:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFO3KqNI0TvqTli4NLbHMvSeSacUbwqgvemEwGhk4nRCGAqRhY6DA+KP7daiifJ8LCQAocB X-Received: by 2002:ac8:7e88:0:b0:423:94f8:13b9 with SMTP id w8-20020ac87e88000000b0042394f813b9mr5591277qtj.68.1702238254796; Sun, 10 Dec 2023 11:57:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1702238254; cv=pass; d=google.com; s=arc-20160816; b=Ym6t9wGl0phUKAegDIhX0ARxMELtaQm1pnHMZ0t4sN19YDYJkP2drdFUnSgnzA8oKL h/c8rkQMd9oRREcFXJY5esrhPs5VobTuUM3p3efPhTFcJ1+u9YQVEzYz76vC4e1+usYW J7ThnbXEVkIum+56a2Vmd2wjR4kqmHlLUZU/caLxIywkQT6gO+lapF8HSt8CeO3BBlrk 0EzbYJc67T6dDOoYDPq90nvlZQ3aQOed2Ct00WLjmzdQMgcmIWwV7RVBwXZiKSKOWOpW Y7G0LdiSqPjT71NvvqICi0kAdKrTFRFlTXjcCz0xzCJKhjn0fozCZoerqGsAtS2zJSTs Mw8w== 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:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=tNILkyt1YZ96JE0zxZaVSnwFe324KeB+2oDoE7qqjRA=; fh=gk9A5O7Gbglvz1MjrRQ4hZ2i3c68kYkpOZJg1emXh+g=; b=Eh5fiMfybDw3fNBsWifGvC1kjpLhfynQVoECtiCcpNryqRclXLlRsB2u40DGR/h5y+ C+rJvIx292mQfNNVqU4cLEuQkYsV49sdGLrhPc3TlxOr6GBm3hCzJCSk1A3dMRYP7ZId vD6sUbawETP9L5etzXS4LFjfl1KSs0QKF6DYF2mfpd7JFk6e2Up/sdnUCQnxQTrns++F heYfxiHvSv6/aJMbDSbDfw4AbChAJ9ONbrwPnUuaMog81Jkylqv+FyTge6UzXAOHHHb5 k4GA1OoDANAKqGvirY8INV0wvML06l8xT6bihNTwz4NmmoT0WeLZGKTRvsXUemS/dLMr Ge7A== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=epPhEwzM; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ki11-20020a05622a770b00b0041cc2ac0f45si6131021qtb.72.2023.12.10.11.57.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 11:57:34 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=epPhEwzM; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 47FB23857C44 for ; Sun, 10 Dec 2023 19:57:29 +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 A43F53858291 for ; Sun, 10 Dec 2023 19:57:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A43F53858291 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 A43F53858291 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=1702238224; cv=none; b=NKOX5nEfP91/8MygRZhbavGuHKckfwjMpCAaB+cUOOkIvwVPMCPGauiKUQmjpzKGdhWH39k/zhkoftlVqYZBPfuQhqOIj56Tm+luperO3RPOce7opr+1JLBjDPYN8cSW8Zhw+I9GDxRkFQAQS5307JBaiet/CChYor19MTWETmk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702238224; c=relaxed/simple; bh=kku+KsQGwqUhzHGCzBaIiGUVa9QXnXAG/CUd8GQJwiQ=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PClScptnssxL6UfcmHAr+NS7FPz847+SqDYIvsUvuAE1XuQ8z2kfw54aN3Q2By1xpLzkRoZGW84CgVgzOyy0Q2qAG9e7VjDY1uABupYikygK/nN0EKfh0giddE15XO8/UAW/BkNrn/7JiKXqzuzCrUJsqtxvvQAFOB0gUhOqHt0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BAJqvnX021074 for ; Sun, 10 Dec 2023 19:57:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding:content-type; s= qcppdkim1; bh=tNILkyt1YZ96JE0zxZaVSnwFe324KeB+2oDoE7qqjRA=; b=ep PhEwzMBsjXVAO0jPmvdP4+fZxVv1Hh8y/BMenRBRkBBfwGp2PNstoiDFC1zbH3VU ov0blvabh/jL4GP27zlCwqasUr1op0XFNvniNEueMTw9vh29edCqBln5QXrg5JmC GMEGeVMulZNnb8tS6D7SgtT7Q4hjMC3y0ioNYiI4ll9+dTNoAYj1fmRNx6xYxyoG R+Nz0gnJaOmT53G7mqvQ7fnbmLlSt5j9Tn8/M5kJmteiHQVKyi6z9lXB+Q5ZkZ7j IKfNIX/jtktJ6gMq2u0qh4z4btizVKEsZxOxPgT/ZrmGOIAeKb/uX2PYgOqezfe3 sC2eS65kS3SLoBQ6TrVg== Received: from nasanppmta05.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uvp309nyb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 10 Dec 2023 19:57:02 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BAJv1Sv020942 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 10 Dec 2023 19:57:01 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, 10 Dec 2023 11:57:00 -0800 From: Andrew Pinski To: Subject: [PATCHv2 2/2] MATCH: (convert)(zero_one !=/== 0/1) for outer type and zero_one type are the same Date: Sun, 10 Dec 2023 11:56:50 -0800 Message-ID: <20231210195650.1772459-3-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231210195650.1772459-1-quic_apinski@quicinc.com> References: <20231210195650.1772459-1-quic_apinski@quicinc.com> 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-ORIG-GUID: BiL_r04amifvvAwvherRqMfv2r9vh1nK X-Proofpoint-GUID: BiL_r04amifvvAwvherRqMfv2r9vh1nK 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 impostorscore=0 malwarescore=0 phishscore=0 mlxlogscore=941 lowpriorityscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 adultscore=0 spamscore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312100175 X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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: 1784926180266194899 X-GMAIL-MSGID: 1784926180266194899 When I moved two_value to match.pd, I removed the check for the {0,+-1} as I had placed it after the {0,+-1} case for cond in match.pd. In the case of {0,+-1} and non boolean, before we would optmize those case to just `(convert)a` but after we would get `(convert)(a != 0)` which was not handled anyways to just `(convert)a`. So this adds a pattern to match `(convert)(zeroone != 0)` and simplify to `(convert)zeroone`. Also this optimizes (convert)(zeroone == 0) into (zeroone^1) if the type match. Removing the opposite transformation from fold. The opposite transformation was added with https://gcc.gnu.org/pipermail/gcc-patches/2006-February/190514.html It is no longer considered the canonicalization either, even VRP will transform it back into `(~a) & 1` so removing it is a good idea. Note the testcase pr69270.c needed a slight update due to not matching exactly a scan pattern, this update makes it more robust and will match before and afterwards and if there are other changes in this area too. Note the testcase gcc.target/i386/pr110790-2.c needs a slight update for better code generation in LP64 bit mode. Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/111972 PR tree-optimization/110637 * match.pd (`(convert)(zeroone !=/== CST)`): Match and simplify to ((convert)zeroone){,^1}. * fold-const.cc (fold_binary_loc): Remove transformation of `(~a) & 1` and `(a ^ 1) & 1)` into `(convert)(a == 0)`. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/pr110637-1.c: New test. * gcc.dg/tree-ssa/pr110637-2.c: New test. * gcc.dg/tree-ssa/pr110637-3.c: New test. * gcc.dg/tree-ssa/pr111972-1.c: New test. * gcc.dg/tree-ssa/pr69270.c: Update testcase. * gcc.target/i386/pr110790-2.c: Update testcase. * gcc.dg/fold-even-1.c: Removed. Signed-off-by: Andrew Pinski --- gcc/fold-const.cc | 27 ----------------- gcc/match.pd | 16 ++++++++++ gcc/testsuite/gcc.dg/fold-even-1.c | 32 -------------------- gcc/testsuite/gcc.dg/tree-ssa/pr110637-1.c | 10 +++++++ gcc/testsuite/gcc.dg/tree-ssa/pr110637-2.c | 13 +++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr110637-3.c | 14 +++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr111972-1.c | 34 ++++++++++++++++++++++ gcc/testsuite/gcc.dg/tree-ssa/pr69270.c | 4 +-- gcc/testsuite/gcc.target/i386/pr110790-2.c | 16 ++++++++-- 9 files changed, 103 insertions(+), 63 deletions(-) delete mode 100644 gcc/testsuite/gcc.dg/fold-even-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr110637-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr110637-2.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr110637-3.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr111972-1.c diff --git a/gcc/fold-const.cc b/gcc/fold-const.cc index 2692b98ceac..f5d68ac323a 100644 --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -12077,33 +12077,6 @@ fold_binary_loc (location_t loc, enum tree_code code, tree type, goto bit_rotate; case BIT_AND_EXPR: - /* Fold (X ^ 1) & 1 as (X & 1) == 0. */ - if (TREE_CODE (arg0) == BIT_XOR_EXPR - && INTEGRAL_TYPE_P (type) - && integer_onep (TREE_OPERAND (arg0, 1)) - && integer_onep (arg1)) - { - tree tem2; - tem = TREE_OPERAND (arg0, 0); - tem2 = fold_convert_loc (loc, TREE_TYPE (tem), arg1); - tem2 = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (tem), - tem, tem2); - return fold_build2_loc (loc, EQ_EXPR, type, tem2, - build_zero_cst (TREE_TYPE (tem))); - } - /* Fold ~X & 1 as (X & 1) == 0. */ - if (TREE_CODE (arg0) == BIT_NOT_EXPR - && INTEGRAL_TYPE_P (type) - && integer_onep (arg1)) - { - tree tem2; - tem = TREE_OPERAND (arg0, 0); - tem2 = fold_convert_loc (loc, TREE_TYPE (tem), arg1); - tem2 = fold_build2_loc (loc, BIT_AND_EXPR, TREE_TYPE (tem), - tem, tem2); - return fold_build2_loc (loc, EQ_EXPR, type, tem2, - build_zero_cst (TREE_TYPE (tem))); - } /* Fold !X & 1 as X == 0. */ if (TREE_CODE (arg0) == TRUTH_NOT_EXPR && integer_onep (arg1)) diff --git a/gcc/match.pd b/gcc/match.pd index 4d554ba4721..e242eac92f5 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3332,6 +3332,22 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (if (INTEGRAL_TYPE_P (TREE_TYPE (@0)) || POINTER_TYPE_P (TREE_TYPE (@0))) (rcmp @0 @1)))) +/* (type)([0,1]@a != 0) -> (type)a + (type)([0,1]@a == 1) -> (type)a + (type)([0,1]@a == 0) -> a ^ 1 + (type)([0,1]@a != 1) -> a ^ 1. */ +(for eqne (eq ne) + (simplify + (convert (eqne zero_one_valued_p@0 INTEGER_CST@1)) + (if ((integer_zerop (@1) || integer_onep (@1))) + (if ((eqne == EQ_EXPR) ^ integer_zerop (@1)) + (convert @0) + /* Only do this if the types match as (type)(a == 0) is + canonical form normally, while `a ^ 1` is canonical when + there is no type change. */ + (if (types_match (type, TREE_TYPE (@0))) + (bit_xor @0 { build_one_cst (type); } )))))) + /* We can't reassociate at all for saturating types. */ (if (!TYPE_SATURATING (type)) diff --git a/gcc/testsuite/gcc.dg/fold-even-1.c b/gcc/testsuite/gcc.dg/fold-even-1.c deleted file mode 100644 index 94711ab1499..00000000000 --- a/gcc/testsuite/gcc.dg/fold-even-1.c +++ /dev/null @@ -1,32 +0,0 @@ -/* { dg-do compile } */ -/* { dg-options "-O2 -fdump-tree-original" } */ -int test1(int a) -{ - return !(a & 1); -} - -int test2(int b) -{ - return (b & 1) == 0; -} - -int test3(int c) -{ - return (c & 1) ^ 1; -} - -int test4(int d) -{ - return (d ^ 1) & 1; -} - -int test5(int e) -{ - return ~e & 1; -} - -/* { dg-final { scan-tree-dump-times "\\(a \& 1\\) == 0" 1 "original" } } */ -/* { dg-final { scan-tree-dump-times "\\(b \& 1\\) == 0" 1 "original" } } */ -/* { dg-final { scan-tree-dump-times "\\(c \& 1\\) == 0" 1 "original" } } */ -/* { dg-final { scan-tree-dump-times "\\(d \& 1\\) == 0" 1 "original" } } */ -/* { dg-final { scan-tree-dump-times "\\(e \& 1\\) == 0" 1 "original" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr110637-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr110637-1.c new file mode 100644 index 00000000000..3d03b0992a4 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr110637-1.c @@ -0,0 +1,10 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ +int f(int a) +{ + int b = (a & 1)!=0; + return b; +} + +/* This should be optimized to just return (a & 1); */ +/* { dg-final { scan-tree-dump-not " == " "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr110637-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr110637-2.c new file mode 100644 index 00000000000..f1c5b90353a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr110637-2.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ +int f(int a) +{ + int b = a & 1; + int c = b == 0; + return c; +} + +/* This should be optimized to just return `(a&1) ^ 1` or `(~a) & 1`. */ +/* { dg-final { scan-tree-dump-not " == " "optimized"} } */ +/* { dg-final { scan-tree-dump-times "~a" 1 "optimized"} } */ +/* { dg-final { scan-tree-dump-times " & 1" 1 "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr110637-3.c b/gcc/testsuite/gcc.dg/tree-ssa/pr110637-3.c new file mode 100644 index 00000000000..ce80146d9df --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr110637-3.c @@ -0,0 +1,14 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-optimized" } */ +int f(int a) +{ + int b = a & 1; + int c = b == 0; + int d = ~a; + int e = d & 1; + return c == e; +} + +/* This should be optimized to just `return 1` */ +/* { dg-final { scan-tree-dump-not " == " "optimized"} } */ +/* { dg-final { scan-tree-dump-times "return 1" 1 "optimized"} } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr111972-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr111972-1.c new file mode 100644 index 00000000000..0611808ed50 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr111972-1.c @@ -0,0 +1,34 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-phiopt" } */ +double +foo() { + long n3 = 3450000, xtra = 7270; + long i,ix; + long j; + double Check; + + /* Section 3, Conditional jumps */ + j = 0; + { + for (ix=0; ix2) j = 0; + else j = 1; + if(j<1) j = 1; + else j = 0; + } + } + } + Check = Check + (double)j; + return Check; +} + +/* the above if statements in loop should be optimized to just `j ^ 1` + and should not be (type)(j != 1). */ +/* { dg-final { scan-tree-dump-not " != 1" "phiopt2"} } */ +/* { dg-final { scan-tree-dump-times " \\^ 1" 1 "phiopt2"} } */ + diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr69270.c b/gcc/testsuite/gcc.dg/tree-ssa/pr69270.c index 0d66cc4383f..b08ec9d6ddb 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/pr69270.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr69270.c @@ -7,8 +7,8 @@ /* { dg-final { scan-tree-dump-times "Replaced .bufferstep_\[0-9\]+. with constant .1." 1 "dom3"} } */ /* And some assignments ought to fold down to constants. */ -/* { dg-final { scan-tree-dump-times "Folded to: _\[0-9\]+ = 1;" 1 "dom3"} } */ -/* { dg-final { scan-tree-dump-times "Folded to: _\[0-9\]+ = 0;" 1 "dom3"} } */ +/* { dg-final { scan-tree-dump-times "Folded to: (?:bufferstep)?_\[0-9\]+ = 1;" 1 "dom3"} } */ +/* { dg-final { scan-tree-dump-times "Folded to: (?:bufferstep)?_\[0-9\]+ = 0;" 1 "dom3"} } */ /* The XOR operations should have been optimized to constants. */ /* { dg-final { scan-tree-dump-not "bit_xor" "dom3"} } */ diff --git a/gcc/testsuite/gcc.target/i386/pr110790-2.c b/gcc/testsuite/gcc.target/i386/pr110790-2.c index 8b9d650c6e9..16c73cb7465 100644 --- a/gcc/testsuite/gcc.target/i386/pr110790-2.c +++ b/gcc/testsuite/gcc.target/i386/pr110790-2.c @@ -9,5 +9,17 @@ refmpn_tstbit_bad (mp_srcptr ptr, unsigned long bit) return (((ptr)[(bit)/(32 - 0)] & (((mp_limb_t) 1L) << ((bit)%(32 - 0)))) != 0); } -/* { dg-final { scan-assembler "bt\[ql\]" } } */ -/* { dg-final { scan-assembler "setc" } } */ +/* 32bit produces: + btl %eax, %edx + setc %al + movzbl %al, %eax + */ +/* { dg-final { scan-assembler "bt\[ql\]" { target { ! lp64 } } } } */ +/* { dg-final { scan-assembler "setc" { target { ! lp64 } } } } */ + +/* 64bit produces: + shrq %cl, %rax + andl $1, %eax + */ +/* { dg-final { scan-assembler-times "shrq" 2 { target { lp64 } } } } */ +/* { dg-final { scan-assembler-times "andl" 2 { target { lp64 } } } } */