From patchwork Sat Oct 12 01:41:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1996322 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=hVX2DZ1M; 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 4XQR7L0ccpz1xtp for ; Sat, 12 Oct 2024 12:42:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC6AE385735B for ; Sat, 12 Oct 2024 01:42:00 +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 966D53858D26 for ; Sat, 12 Oct 2024 01:41:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 966D53858D26 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 966D53858D26 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=1728697297; cv=none; b=O52ULlL4b5NqdkUPycxJx7iVkaWHbBEm5uACT5DTwSGRhZ7PPpop6g3lGoUZWLSGoAx+CEkN5nslyBQ23gyF5FR5iBNXU8WLgAsLXybZCEGI1gZTB94u0NcHwXDsJ3qKH2dqIFaMM/vWTJU+gz0M5Sic0hOtHFhyMJesSXj61uo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728697297; c=relaxed/simple; bh=hUbd2YA9PDir/ZB6dbyXkR4GUeT/VZ1blJeEoJny7J4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=S9VQhNy0OdxblNGuPL/hz7d4huNI19cd63t2JlDD/MIWyV5RMT13SNS8+17x1f5MDd8p+yR3ADdCOeqsNySYsjf5frl5WP3lQ+vqQcfd1CBEtv1TPOuBFSrayBKMlQ+JhKjAc2EJxZ8AtvcHaW0WkGn46E0Qq9fYEHyYo2ssH6E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49BNrec8031580 for ; Sat, 12 Oct 2024 01:41:35 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=fc0BX07oG3/FTW+drgrES1 pgmn21M3Xvrar8JTVnok4=; b=hVX2DZ1MyRgDMAnvV41RARs76HvbkzU2Ev7LQX YpHzYiF77jBj0xMLYrfqiktMpth6dn9PFVrrm0yf6Xi8DLPmquZjmbT38w08G9RE yO3WQAVHcdrHMm9gs8onrBy7azCzPgLkZvrtyFGDVcUoTjZ9sML6rxUJA4Nb9XcS UJpsoX7NJU9D+mmpVh3ZBw8INgQ+C5xhGKnLhIJzekmbU7MtOvS8dmFOUMpPQiWA OwcwueflVPbs5lcgOyE3hJrcz3HPchQHYS68+jI19fBTXYOBavS+UlZ12m99uXrG 1tR9qH4TqZOAEzaSOFKaaZjXJq8lGX7UNAb9S5sNMhKBTSJw== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 426fj6vwwf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 12 Oct 2024 01:41:34 +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 49C1fXvc018429 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sat, 12 Oct 2024 01:41:33 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; Fri, 11 Oct 2024 18:41:33 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] phiopt: Clobbers can sometimes get in the way of phiopt [PR117096] Date: Fri, 11 Oct 2024 18:41:23 -0700 Message-ID: <20241012014123.4088037-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: kpop8fk429Bhb5DiFOoLD-Z3L50rAd6v X-Proofpoint-ORIG-GUID: kpop8fk429Bhb5DiFOoLD-Z3L50rAd6v 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 bulkscore=0 mlxlogscore=952 lowpriorityscore=0 spamscore=0 malwarescore=0 adultscore=0 suspectscore=0 clxscore=1015 mlxscore=0 impostorscore=0 priorityscore=1501 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410120009 X-Spam-Status: No, score=-14.0 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 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~incoming=patchwork.ozlabs.org@gcc.gnu.org Clobbers in a condition don't cause any improvements and are getting in the way of doing match and simplify with phiopt. Need to ignore/skip over them in when seeing if there is only one statement that can moved. Also since clobbers have vops, skipping over the vops phi node is needed to be done. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/117096 gcc/ChangeLog: * tree-ssa-phiopt.cc (single_non_singleton_phi_for_edges): Skip over vops rather than return false. (empty_bb_or_one_feeding_into_p): Skip over clobbers too. gcc/testsuite/ChangeLog: * g++.dg/tree-ssa/phiopt-2.C: New test. Signed-off-by: Andrew Pinski --- gcc/testsuite/g++.dg/tree-ssa/phiopt-2.C | 46 ++++++++++++++++++++++++ gcc/tree-ssa-phiopt.cc | 14 ++++---- 2 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/phiopt-2.C diff --git a/gcc/testsuite/g++.dg/tree-ssa/phiopt-2.C b/gcc/testsuite/g++.dg/tree-ssa/phiopt-2.C new file mode 100644 index 00000000000..9bc8fb6e8dc --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/phiopt-2.C @@ -0,0 +1,46 @@ +// { dg-do compile } +// { dg-options "-O1 -fdump-tree-phiopt1-details" } +// PR tree-optimization/117096 +// Clobbers should NOT make a difference +// when it comes to phiopt + +struct s1{ + unsigned b; + + // Declare as always inline just in some someone turns down the inlining limits + // we also want to inline early. + __attribute__((always_inline)) inline + s1() : b(0) {} +}; +void g(); +int f(signed a, int c) +{ + signed b = 0; + if (a < 0) + { + s1(); + b = a; + } + else { s1(); } + g(); + return b; +} + + +int f1(signed a, int c) +{ + signed b = 0; + if (a < 0) + { + s1 t; + b = a; + } + else { s1 t; } + g(); + return b; +} + +/* both if should be converted into MIN_EXPR */ +/* { dg-final { scan-tree-dump-not "if " "phiopt1" } }*/ +/* { dg-final { scan-tree-dump-times "MIN_EXPR " 2 "phiopt1" } }*/ + diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index f3ee3a80c0f..b22086f4de8 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -72,9 +72,10 @@ single_non_singleton_phi_for_edges (gimple_seq seq, edge e0, edge e1) gimple_phi_arg_def (p, e1->dest_idx))) continue; - /* Punt on virtual phis with different arguments from the edges. */ + /* Skip virtual phis with different arguments + from the edges as clobbers might cause the vop to be different. */ if (virtual_operand_p (gimple_phi_result (p))) - return NULL; + continue; /* If we already have a PHI that has the two edge arguments are different, then return it is not a singleton for these PHIs. */ @@ -663,9 +664,10 @@ empty_bb_or_one_feeding_into_p (basic_block bb, { gimple *s = gsi_stmt (gsi); gsi_next_nondebug (&gsi); - /* Skip over Predict and nop statements. */ + /* Skip over Predict, clobber and nop statements. */ if (gimple_code (s) == GIMPLE_PREDICT - || gimple_code (s) == GIMPLE_NOP) + || gimple_code (s) == GIMPLE_NOP + || gimple_clobber_p (s)) continue; /* If there is more one statement return false. */ if (stmt_to_move) @@ -673,8 +675,8 @@ empty_bb_or_one_feeding_into_p (basic_block bb, stmt_to_move = s; } - /* The only statement here was a Predict or a nop statement - so return true. */ + /* The only statement here was a Predict, nop, + or a clobber statement so return true. */ if (!stmt_to_move) return true;