From patchwork Sat Nov 2 15:09:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 2005512 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=lED8xj/E; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xgh4F2VJ3z1xxy for ; Sun, 3 Nov 2024 02:10:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D2073385772E for ; Sat, 2 Nov 2024 15:10:17 +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 1ABB53858CDA for ; Sat, 2 Nov 2024 15:09:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1ABB53858CDA 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 1ABB53858CDA 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=1730560181; cv=none; b=kMHxOvRsHKChu67DgEckaU4IZUy4juz9OAxM3YrdCl+c8Ut46MjnkKyXcmqAaBbIqUxR6KHoTHjY0/RSLA8tRN1GdK7aK2R/XQRzKmhZ7PXuBAZwk5tV4BHepsiwDta+ntzD9bTF7/DiT5Z4ktPbCjY4gpiwb+SsRxCldtxlz4c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730560181; c=relaxed/simple; bh=ZbWyaR7uSmndOhs6RrUFoEr5xRhbZvhtG4CdVQ7tx4k=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=IgSeM76jquhg40BXf4xg2ImQ89I+A0nhorj0hia4euvcVTfment3+p65KfN1QRE70X1gttEabscEvdHs7RpGelM/GctPT8aTD7sde6Fx+I3SyQc80PFKEej1cCe1JbgzCVFakB3yAlBbqrW8JKVYUWzPxiohb4h36Q/glP40fL8= 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.18.1.2/8.18.1.2) with ESMTP id 4A2Almgl006291 for ; Sat, 2 Nov 2024 15:09:36 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=qcppdkim1; bh=a5WLI1tH3/Rj2p1JbML36C NGHxb69BPm9RO8G/hg8Ps=; b=lED8xj/E7eXhbUAgXVdqbN37goe9aMTnjJqwBF 9ENoG5uCNWkeHWPne+Vz5ZcsnMKXzRl4U2M2ZPJE0V/qQNYUEOfL0lsu6PGVuCKN t2k/8/ODCIVKwwgHdgFk96vi3UDSHo+aDT4DBGGZWOoLgJRLqrjva+7jxLTln7QM jEFTw53rbnz8iKctAcM/7xA9+dOCi/Bf9YTgWVEkoubnp7aK/t0sq00rA7gwhaSp CBroklOoUGR72FzRd5SPkJXLe2AS+EH8AOMYrveIc4u/kT4oeyRQdLHYcrIeosf1 ASLuo0UqVWwWna3US6Ofuvv83xv/gl8A8qREjQAuG6M8Sv3A== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42nd2r0udd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 02 Nov 2024 15:09:36 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A2F9al2021939 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 2 Nov 2024 15:09:36 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.1544.9; Sat, 2 Nov 2024 08:09:35 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 1/4] VN: Factor out inserting predicates for conditional Date: Sat, 2 Nov 2024 08:09:18 -0700 Message-ID: <20241102150921.3319089-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: nalasex01a.na.qualcomm.com (10.47.209.196) 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: sb3eMPmrKFlH2BbDKf6nHnyTfVUCzIUA X-Proofpoint-GUID: sb3eMPmrKFlH2BbDKf6nHnyTfVUCzIUA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=730 priorityscore=1501 malwarescore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 phishscore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411020134 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~incoming=patchwork.ozlabs.org@gcc.gnu.org To make it easier to add more predicates in some cases, factor out the code. Plus it makes the code slightly more readable since it is not indented as much. Bootstrapped and tested on x86_64. gcc/ChangeLog: * tree-ssa-sccvn.cc (insert_predicates_for_cond): New function, factored out from ... (process_bb): Here. Signed-off-by: Andrew Pinski --- gcc/tree-ssa-sccvn.cc | 70 +++++++++++++++++++++++-------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 1c8bc884f1f..a11bf968670 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -7895,6 +7895,42 @@ insert_related_predicates_on_edge (enum tree_code code, tree *ops, edge pred_e) } } +/* Insert on the TRUE_E true and FALSE_E false predicates + derived from LHS CODE RHS. */ +static void +insert_predicates_for_cond (tree_code code, tree lhs, tree rhs, + edge true_e, edge false_e) +{ + tree_code icode = invert_tree_comparison (code, HONOR_NANS (lhs)); + tree ops[2]; + ops[0] = lhs; + ops[1] = rhs; + if (true_e) + vn_nary_op_insert_pieces_predicated (2, code, boolean_type_node, ops, + boolean_true_node, 0, true_e); + if (false_e) + vn_nary_op_insert_pieces_predicated (2, code, boolean_type_node, ops, + boolean_false_node, 0, false_e); + if (icode != ERROR_MARK) + { + if (true_e) + vn_nary_op_insert_pieces_predicated (2, icode, boolean_type_node, ops, + boolean_false_node, 0, true_e); + if (false_e) + vn_nary_op_insert_pieces_predicated (2, icode, boolean_type_node, ops, + boolean_true_node, 0, false_e); + } + /* Relax for non-integers, inverted condition handled + above. */ + if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))) + { + if (true_e) + insert_related_predicates_on_edge (code, ops, true_e); + if (false_e) + insert_related_predicates_on_edge (icode, ops, false_e); + } +} + /* Main stmt worker for RPO VN, process BB. */ static unsigned @@ -8098,45 +8134,13 @@ process_bb (rpo_elim &avail, basic_block bb, edge true_e, false_e; extract_true_false_edges_from_block (bb, &true_e, &false_e); enum tree_code code = gimple_cond_code (last); - enum tree_code icode - = invert_tree_comparison (code, HONOR_NANS (lhs)); - tree ops[2]; - ops[0] = lhs; - ops[1] = rhs; if ((do_region && bitmap_bit_p (exit_bbs, true_e->dest->index)) || !can_track_predicate_on_edge (true_e)) true_e = NULL; if ((do_region && bitmap_bit_p (exit_bbs, false_e->dest->index)) || !can_track_predicate_on_edge (false_e)) false_e = NULL; - if (true_e) - vn_nary_op_insert_pieces_predicated - (2, code, boolean_type_node, ops, - boolean_true_node, 0, true_e); - if (false_e) - vn_nary_op_insert_pieces_predicated - (2, code, boolean_type_node, ops, - boolean_false_node, 0, false_e); - if (icode != ERROR_MARK) - { - if (true_e) - vn_nary_op_insert_pieces_predicated - (2, icode, boolean_type_node, ops, - boolean_false_node, 0, true_e); - if (false_e) - vn_nary_op_insert_pieces_predicated - (2, icode, boolean_type_node, ops, - boolean_true_node, 0, false_e); - } - /* Relax for non-integers, inverted condition handled - above. */ - if (INTEGRAL_TYPE_P (TREE_TYPE (lhs))) - { - if (true_e) - insert_related_predicates_on_edge (code, ops, true_e); - if (false_e) - insert_related_predicates_on_edge (icode, ops, false_e); - } + insert_predicates_for_cond (code, lhs, rhs, true_e, false_e); } break; } From patchwork Sat Nov 2 15:09:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 2005511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=OzydQ9FV; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xgh4F3QYCz1xy4 for ; Sun, 3 Nov 2024 02:10:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EB3EE3858283 for ; Sat, 2 Nov 2024 15:10:16 +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 1757B3858D33 for ; Sat, 2 Nov 2024 15:09:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1757B3858D33 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 1757B3858D33 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=1730560181; cv=none; b=uou/h9YfG/LTOE+ruhTQaBi10xP2XTMCUsOeUDv+keMsEAbj7OOKXp3qVHz1jiUGdcM6m89AmxioUUTSlhaX9CxiPm4RVrmYSQpoGt9KzZ1w84rL9BpeEBmqu6h4w85eoUU4Z2W3mT2vQ1tgTJMhavjYizt8wB61YLYTmE8A/lc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730560181; c=relaxed/simple; bh=3OmI/x6d69i1yfbdMBdfnJyjJ8mauv5HYim845O6ltg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tYjByg1NbfIvIEXqOrgem5ODS1BSC62Kf8KcPCdmts26UjRYmX865SmKndBR/9L/R4oBZq12w2ybyk95wUwBNapEWNvQ1QDxUBEw6oNQeRC+6O8pQ+wKXotVZ3F51JkhX2sJYvuDOxbw5880VGWnX+M5gZSVdi8oLWIjdbBZaiQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A2EHhXs012803 for ; Sat, 2 Nov 2024 15:09:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= udm+bytJtrMfy6YbYWR+aazmssNBZgY8koAqQUwHzAs=; b=OzydQ9FVyD7P8k/2 ecU5DfTDaUElKLyvla3iBr6HjQjea8kOii70gkLfSwM2tBcc+0uidDmJMRvaVQSR 3zPba1WXP3s27pnSocGAtJ3zeo03uSouX3Ko3c+llRDQgkEYvXQwepl6zneMamj5 i5Mi/6hHaFUdDgDRkDn6iNqtX5ScW+QuUmMoRsL0zCiBFhL+YJxVyxjI9cN5gpMm WOswXXHJMD/e+vDM9BhFWonTtIOMzE3b76BiNdGqSRYK8se9RwuPr2K6FKtj9QBv PzTYwZ1b7OeSy+6UVfS3bLkjSriVm076P8oNiPXb/qdx8BdkJplfHrAGSZno0ZCw +EJVxw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42nd5cgu19-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 02 Nov 2024 15:09:36 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A2F9a8O030303 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 2 Nov 2024 15:09:36 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.1544.9; Sat, 2 Nov 2024 08:09:36 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 2/4] VN: Handle `(a | b) !=/== 0` for predicates [PR117414] Date: Sat, 2 Nov 2024 08:09:19 -0700 Message-ID: <20241102150921.3319089-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241102150921.3319089-1-quic_apinski@quicinc.com> References: <20241102150921.3319089-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: hfosgRqAfxTFaEf4dJ9HvX8q58aMfeby X-Proofpoint-GUID: hfosgRqAfxTFaEf4dJ9HvX8q58aMfeby X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 adultscore=0 clxscore=1015 phishscore=0 malwarescore=0 mlxlogscore=780 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411020134 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~incoming=patchwork.ozlabs.org@gcc.gnu.org For `(a | b) == 0`, we can "assert" on the true edge that both `a == 0` and `b == 0` but nothing on the false edge. For `(a | b) != 0`, we can "assert" on the false edge that both `a == 0` and `b == 0` but nothing on the true edge. This adds that predicate and allows us to optimize f0, f1, and f2 in fre-predicated-[12].c. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/117414 gcc/ChangeLog: * tree-ssa-sccvn.cc (insert_predicates_for_cond): Handle `(a | b) !=/== 0` also. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/fre-predicated-1.c: New test. * gcc.dg/tree-ssa/fre-predicated-2.c: New test. Signed-off-by: Andrew Pinski --- .../gcc.dg/tree-ssa/fre-predicated-1.c | 53 +++++++++++++++++++ .../gcc.dg/tree-ssa/fre-predicated-2.c | 27 ++++++++++ gcc/tree-ssa-sccvn.cc | 26 +++++++++ 3 files changed, 106 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-1.c create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-2.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-1.c b/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-1.c new file mode 100644 index 00000000000..d56952f5f24 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-1.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* PR tree-optimization/117414 */ + +/* Fre1 should figure out that `*aaa != 0` + For f0, f1, and f2. */ + + +void foo(); +int f0(int *aaa, int j, int t) +{ + int b = *aaa; + int c = b != 0; + int d = t != 0; + if (d | c) + return 0; + for(int i = 0; i < j; i++) + { + if (*aaa) foo(); + } + return 0; +} + +int f1(int *aaa, int j, int t) +{ + int b = *aaa; + if (b != 0 || t != 0) + return 0; + for(int i = 0; i < j; i++) + { + if (*aaa) foo(); + } + return 0; +} + + +int f2(int *aaa, int j, int t) +{ + int b = *aaa; + if (b != 0) + return 0; + if (t != 0) + return 0; + for(int i = 0; i < j; i++) + { + if (*aaa) foo(); + } + return 0; +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */ +/* { dg-final { scan-tree-dump "return 0;" "optimized" } } */ diff --git a/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-2.c b/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-2.c new file mode 100644 index 00000000000..0123a5b54f7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-2.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* PR tree-optimization/117414 */ + +/* Fre1 should figure out that `*aaa != 0` + For f0, f1, and f2. */ + + +void foo(); +int f0(int *aaa, int j, int t) +{ + int b = *aaa; + int d = b | t; + if (d == 0) + ; + else + return 0; + for(int i = 0; i < j; i++) + { + if (*aaa) foo(); + } + return 0; +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */ +/* { dg-final { scan-tree-dump "return 0;" "optimized" } } */ diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index a11bf968670..b3e6cd09007 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -7901,6 +7901,9 @@ static void insert_predicates_for_cond (tree_code code, tree lhs, tree rhs, edge true_e, edge false_e) { + /* If both edges are null, then there is nothing to be done. */ + if (!true_e && !false_e) + return; tree_code icode = invert_tree_comparison (code, HONOR_NANS (lhs)); tree ops[2]; ops[0] = lhs; @@ -7929,6 +7932,29 @@ insert_predicates_for_cond (tree_code code, tree lhs, tree rhs, if (false_e) insert_related_predicates_on_edge (icode, ops, false_e); } + if (integer_zerop (rhs) + && (code == NE_EXPR || code == EQ_EXPR) + && TREE_CODE (lhs) == SSA_NAME) + { + gimple *def_stmt = SSA_NAME_DEF_STMT (lhs); + /* (a | b) == 0 -> + on true edge assert: a == 0 & b == 0. */ + /* (a | b) != 0 -> + on false edge assert: a == 0 & b == 0. */ + if (is_gimple_assign (def_stmt) + && gimple_assign_rhs_code (def_stmt) == BIT_IOR_EXPR) + { + edge e = code == EQ_EXPR ? true_e : false_e; + insert_predicates_for_cond (EQ_EXPR, + gimple_assign_rhs1 (def_stmt), + rhs, + e, nullptr); + insert_predicates_for_cond (EQ_EXPR, + gimple_assign_rhs2 (def_stmt), + rhs, + e, nullptr); + } + } } /* Main stmt worker for RPO VN, process BB. */ From patchwork Sat Nov 2 15:09:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 2005513 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=lqwKYYNf; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xgh4H5qMKz1xxy for ; Sun, 3 Nov 2024 02:10:20 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA8343858CDA for ; Sat, 2 Nov 2024 15:10:16 +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 139C43858D26 for ; Sat, 2 Nov 2024 15:09:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 139C43858D26 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 139C43858D26 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=1730560181; cv=none; b=V2xccGA5l4kqkM2Y4YkRpUIuOxw14cTZ08azEm7TqdwyGiSLQCfGUyv0cJDZa4JVjXcyb8ojZ89/pl3XRnQzjNpCUFOVhhplGTIv3R6cH31/OQKYbVlwKTojkscfwfufmcAQNVsx09OW1voTxp8PKJ55zONwpCjTzxpbdHpEDhA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730560181; c=relaxed/simple; bh=SQaIwZqjh3W6K9jIkNZYDhMMp+hLiasMjE5zjyQ1DgE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=RZDATJ+f14KPB0Bul6ddOeHz/i7WLqohJgIH6KIIg8WPnXHKyAiJlE+ZroUcfOSLUBDuIcjk2Ehc4YeZleGiKySWhrci5sOhFY1IB+0FAJriJqi7jh6DH0Ib5AbGDxup9vII1nK38myRzPvDwqq3PeESE9LGwUXM5fdT4kwjgos= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279865.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A24XFuf019714 for ; Sat, 2 Nov 2024 15:09:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= Pa39kqbvU1UP/Yux5wleywb9+4ggwM3rYp2LzGN31Ao=; b=lqwKYYNfvPLd5izW G/9d8B0PTQSRThzDW6MPnrIiBgYUwHDqIxFQdo+gLKs7/3IJdGMMTHksMKJYt4JP N+Unt8D6BVrOC5c76zvlHOFVgE74BGjCDENhAwxQvWqjFN9y3u0u0nvIJmaw0IJ5 0HLVgJ3dYX3I84/gEinmK2FqWa3MeliG7yKSeNVHcZYR+9m/1tW/d+2wFXFAY6lk kr+76B8pheDJ+nOzmZaxOvxG8moRw7JhE/K1i9omxRbZixMSw/q7YQiEFJCR+5Z6 t6n7al6OgoFl9tIXGG/HJlEwaS2jrYjFUaz+WgGxRgsCRQz/hJnCq+edgh1KnIcQ seY5+A== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42nd5cgu1a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 02 Nov 2024 15:09:37 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A2F9aoX002522 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 2 Nov 2024 15:09:36 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.1544.9; Sat, 2 Nov 2024 08:09:36 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 3/4] VN: Handle `(A CMP B) !=/== 0` for predicates [PR117414] Date: Sat, 2 Nov 2024 08:09:20 -0700 Message-ID: <20241102150921.3319089-3-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241102150921.3319089-1-quic_apinski@quicinc.com> References: <20241102150921.3319089-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: wz0A5kCDBA81DpU9w-Fie3j5rVHF709l X-Proofpoint-GUID: wz0A5kCDBA81DpU9w-Fie3j5rVHF709l X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 mlxscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 adultscore=0 clxscore=1015 phishscore=0 malwarescore=0 mlxlogscore=763 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411020134 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~incoming=patchwork.ozlabs.org@gcc.gnu.org After the last patch, we also want to record `(A CMP B) != 0` as `(A CMP B)` and `(A CMP B) == 0` as `(A CMP B)` with the true/false edges swapped. This is enough to fix the original issue in `gcc.dg/tree-ssa/pr111456-1.c` and make sure we don't regress it when enhancing ifcombine. This adds that predicate and allows us to optimize f in fre-predicated-3.c. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/117414 gcc/ChangeLog: * tree-ssa-sccvn.cc (insert_predicates_for_cond): gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/fre-predicated-3.c: New test. Signed-off-by: Andrew Pinski --- .../gcc.dg/tree-ssa/fre-predicated-3.c | 46 +++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 14 ++++++ 2 files changed, 60 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-3.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-3.c b/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-3.c new file mode 100644 index 00000000000..4a89372fd70 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-3.c @@ -0,0 +1,46 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* PR tree-optimization/117414 */ + +/* Fre1 should figure out that `*aaa != 0` + For f0, f1, and f2. */ + +void foo(); +int f(int *aaa, int j, int t) +{ + int b = *aaa; + int c = b == 0; + int d = t != 1; + if (c | d) + return 0; + + for(int i = 0; i < j; i++) + { + if (*aaa) + ; + else + foo(); + } + return 0; +} + +int f1(int *aaa, int j, int t) +{ + int b = *aaa; + if (b == 0) + return 0; + if (t != 1) + return 0; + for(int i = 0; i < j; i++) + { + if (*aaa) + ; + else + foo(); + } + return 0; +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */ +/* { dg-final { scan-tree-dump "return 0;" "optimized" } } */ diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index b3e6cd09007..190b7d24f1a 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -7937,6 +7937,20 @@ insert_predicates_for_cond (tree_code code, tree lhs, tree rhs, && TREE_CODE (lhs) == SSA_NAME) { gimple *def_stmt = SSA_NAME_DEF_STMT (lhs); + /* (A CMP B) != 0 is the same as (A CMP B). + (A CMP B) == 0 is just (A CMP B) with the edges swapped. */ + if (is_gimple_assign (def_stmt) + && TREE_CODE_CLASS (gimple_assign_rhs_code (def_stmt)) == tcc_comparison) + { + tree_code nc = gimple_assign_rhs_code (def_stmt); + tree nlhs = gimple_assign_rhs1 (def_stmt); + tree nrhs = gimple_assign_rhs2 (def_stmt); + edge nt = true_e; + edge nf = false_e; + if (code == EQ_EXPR) + std::swap (nt, nf); + insert_predicates_for_cond (nc, nlhs, nrhs, nt, nf); + } /* (a | b) == 0 -> on true edge assert: a == 0 & b == 0. */ /* (a | b) != 0 -> From patchwork Sat Nov 2 15:09:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 2005514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=quicinc.com header.i=@quicinc.com header.a=rsa-sha256 header.s=qcppdkim1 header.b=HB/UYpzc; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Xgh4K2ScWz1xxy for ; Sun, 3 Nov 2024 02:10:25 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 86959385737F for ; Sat, 2 Nov 2024 15:10:23 +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 1D77B3858C2B for ; Sat, 2 Nov 2024 15:09:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1D77B3858C2B 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 1D77B3858C2B 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=1730560183; cv=none; b=VUXx85hK+T3/w9Dt2LE3UhAiO5ySjdTJ5llzSKeuld8mL1bZZg1Kyejs/vi4C0pIR6vM7hLfZdrIV0FxoLJOhKLrM+UXVJCw0TdiDEOYbS8CetZ6A4/jYjIQ2CNx93uN+OUvUzWuqpHHcAq7gzKdllstivWB6PdzhjLs/tLK9+0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730560183; c=relaxed/simple; bh=/8L6IMYqVuvx0rFUve+qWs+aFbzs0jy6c0RLsXXq7yE=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QsAGJLpzPhLeCUGivEtK6Iydx8DX3cXek+1sDvvGOiNlj4tBqLZX8veOH6xg/cbEFeIR5E6nHto/EAfVEcLaiMRlTKpg03FycJwI1ejjn80YgcOl+gtaOtqm+7HeAAYJVAGOcIMmT7uzXWv/+YkmoDwsqaQe2bx1CpLFZ2iP/hk= 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.18.1.2/8.18.1.2) with ESMTP id 4A24SCwf027323 for ; Sat, 2 Nov 2024 15:09:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= RRZecpL18yOjIcNHuwr5CPdbP6Bb7xIiAVTcCUxe2oU=; b=HB/UYpzcQs/TCox2 JhvgrwCsYZNIP3+YdTtflxbhhYDaYmsRRcg0ueG+Z4VEM0FGZIVCxjYMNE9tqVtw 3bn4vQTQwFTyzUREhoycX3uSrcvA0eJ1cbjgADZRzkssxCb+HMLG0cBj0qo1aDlp GdshylNpgn66mAK9fc1bYjWqRMjL6cSBUYE6yMhywF7d+GsRTKAELf1af1qhrBka L57NpijcPy3tSQ51NKi/F4sIksyLgiJUffgrLpvaBBxPnts+GW8JM5g/dhZdcnw9 bWVoAWsyeWXZKJIoRYtQPmQtiN04ZFweMm/Q2xbuVRqn6TR6zR7HMwEcwoyXB4in Zh0Dgw== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42nd2r0ude-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 02 Nov 2024 15:09:37 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA04.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A2F9bHt030310 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 2 Nov 2024 15:09:37 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.1544.9; Sat, 2 Nov 2024 08:09:36 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 4/4] VN: Lookup `val != 0` if we got back val when looking up the predicate for GIMPLE_COND [PR117414] Date: Sat, 2 Nov 2024 08:09:21 -0700 Message-ID: <20241102150921.3319089-4-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241102150921.3319089-1-quic_apinski@quicinc.com> References: <20241102150921.3319089-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: D6xFrtGL-jgkwPnVdq0crsRccX_GFh3_ X-Proofpoint-GUID: D6xFrtGL-jgkwPnVdq0crsRccX_GFh3_ X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=825 priorityscore=1501 malwarescore=0 bulkscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 phishscore=0 spamscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411020134 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Sometimes we get back a full ssa name when looking up the comparison of the GIMPLE_COND rather than a predicate. We then want to lookup the `val != 0` for the predicate. Note this might happen with other boolean assignments and COND_EXPR but I am not sure if it is as important; I have not found a testcase yet. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/117414 gcc/ChangeLog: * tree-ssa-sccvn.cc (process_bb): Lookup `val != 0` if got back a ssa name when looking the comparison. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/fre-predicated-4.c: New test. Signed-off-by: Andrew Pinski --- .../gcc.dg/tree-ssa/fre-predicated-4.c | 38 +++++++++++++++++++ gcc/tree-ssa-sccvn.cc | 10 +++++ 2 files changed, 48 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-4.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-4.c b/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-4.c new file mode 100644 index 00000000000..fe9d2e2fb58 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/fre-predicated-4.c @@ -0,0 +1,38 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-optimized" } */ + +/* PR tree-optimization/117414 */ + +/* Fre1 should figure out that `*aaa != 0` + For f0 and f1. */ + + +void foo(); +int f0(int *aaa, int j, int t) +{ + int b = *aaa; + if (b == 0 || t == 1) + return 0; + for(int i = 0; i < j; i++) + { + if (!*aaa) foo(); + } + return 0; +} + +int f1(int *aaa, int j, int t) +{ + int b = *aaa; + if (b == 0) + return 0; + if (t == 1) + return 0; + for(int i = 0; i < j; i++) + { + if (!*aaa) foo(); + } + return 0; +} + +/* { dg-final { scan-tree-dump-not "foo " "optimized" } } */ +/* { dg-final { scan-tree-dump "return 0;" "optimized" } } */ diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc index 190b7d24f1a..c8d40697560 100644 --- a/gcc/tree-ssa-sccvn.cc +++ b/gcc/tree-ssa-sccvn.cc @@ -8149,6 +8149,16 @@ process_bb (rpo_elim &avail, basic_block bb, val = vn_nary_op_lookup_pieces (2, gimple_cond_code (last), boolean_type_node, ops, &vnresult); + /* Got back a ssa name, then try looking up `val != 0` + as it might have been recorded that way. */ + if (val && TREE_CODE (val) == SSA_NAME) + { + ops[0] = val; + ops[1] = build_zero_cst (TREE_TYPE (val)); + val = vn_nary_op_lookup_pieces (2, NE_EXPR, + boolean_type_node, ops, + &vnresult); + } /* Did we get a predicated value? */ if (! val && vnresult && vnresult->predicated_values) {