From patchwork Sun Oct 20 17:00:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1999620 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=dts/nFws; 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 4XWl8165xfz1xwK for ; Mon, 21 Oct 2024 04:01:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BD2CF3858401 for ; Sun, 20 Oct 2024 17:01:03 +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 D18C43858D20 for ; Sun, 20 Oct 2024 17:00:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D18C43858D20 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 D18C43858D20 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=1729443645; cv=none; b=Hem7qFQvXqnOGrnnPfh3tjkfhGnEC5bUU0iD1rk6FjsqtBjINCR1gi7/xnHUWincAJHtg4gZoIMeMGohYFESfdDq30mXfm4NzNw1mdS4HHJDKh89Jed917BB+Pzkt971WHt8U87omAska+h76HTYKTBdNZwVnE1It3CWZILVpgM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1729443645; c=relaxed/simple; bh=CJnsQUysikWAdPl2IZntuUdCHiYy42Q1hXuyBVTn3qo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=GItyy7Gp3+O2znJk3mq001a7ZetnvCGKjwt3TiFMKVU9dMRgOO12gZvS+jNOzSTr341INXecQjO21vpeo8Ifo1FjoT2SbbNWd+KcAj8E9QwAT3n/FEb+CwBf1vInR3yHPV8se5YccVzzR7J/nqoMKII+oREJ0POd8ADkLVDEF0s= 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.18.1.2/8.18.1.2) with ESMTP id 49KGPloa018993 for ; Sun, 20 Oct 2024 17:00:43 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=qqe3W48f4U9173QgUO5NxK 1dE08fRtSFqklAEpvb464=; b=dts/nFws0HAFb8th84KEw8Pti2QH8hoSIYoUvY SCbKbv3mTZIsHfOxFD3nGuQSkyUv86M3IArbXA942peNMiantOBt/Uz9MNtkTK2n kqQV4NBy5JlGvBUKG16St0CKDSJZrNbX1FAC7WTI4DJvOUn+5r81xZlC1nqdLI6U wbnNxEkNC2R9ruJanJmpapz5jNabMAnix70VMitRc1KU3RUoTw/kERjgpSoirFLc cVswxH2sXBeumfyCfso/CILOa6HDvxGp0nTXGjimrIFMjvS3K2E7fLkqOPCEpNMB jbbeOmc2O4LxrWcv1tOqXekG1KC3AjHgTwwzWGHKKjiG/m1Q== Received: from nasanppmta04.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42c6rj2bt8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 20 Oct 2024 17:00:42 +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 49KH0fve030566 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Sun, 20 Oct 2024 17:00:41 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; Sun, 20 Oct 2024 10:00:40 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] phiopt: factor could move a trapping statement across other trapping statements [PR117235] Date: Sun, 20 Oct 2024 10:00:25 -0700 Message-ID: <20241020170025.447681-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: o2325MRtKzlFbKYBVhL3qYIYTRrqTinC X-Proofpoint-ORIG-GUID: o2325MRtKzlFbKYBVhL3qYIYTRrqTinC 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 lowpriorityscore=0 phishscore=0 bulkscore=0 malwarescore=0 mlxscore=0 spamscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=836 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410200119 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 After r15-4503-g8d6d6d537fdc75, phiopt could move a trapping statement across another trapping statement causing the order to be incorrect (might happen with non-call exceptions). To prevent this, a trapping statement has to be at the end of the basic block to be allowed to be factored. This adds that check. Bootstrapped and tested on x86_64-linux-gnu. PR tree-optimization/117235 gcc/ChangeLog: * tree-ssa-phiopt.cc (is_factor_profitable): Return false when a trapping statement is not the last statement of the basic block. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/factor_op_phi-5.c: New test. Signed-off-by: Andrew Pinski --- .../gcc.dg/tree-ssa/factor_op_phi-5.c | 24 +++++++++++++++++++ gcc/tree-ssa-phiopt.cc | 6 +++++ 2 files changed, 30 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/factor_op_phi-5.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/factor_op_phi-5.c b/gcc/testsuite/gcc.dg/tree-ssa/factor_op_phi-5.c new file mode 100644 index 00000000000..ad4338f3c08 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/factor_op_phi-5.c @@ -0,0 +1,24 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -ftrapping-math -fdump-tree-phiopt1-details" } */ + +/* PR tree-optimization/117235 */ + +/* The convert between int to float should not be factored as the statement + could be moved across another trapping statement. */ +int f(int a, float b, float c, float d, int x, int y) +{ + float e; + float t; + if (a) + { + e = x; + t = c/d; + } else + { + e = y; + t = d/c; + } + return e + t; +} + +/* { dg-final { scan-tree-dump-not "changed to factor operation out from " "phiopt1" } } */ diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index 38cc8506d1f..6a89f57a41a 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -249,6 +249,12 @@ is_factor_profitable (gimple *def_stmt, basic_block merge, tree arg) if (gsi_end_p (gsi)) return true; + /* If the defining statement could trap, then it is never + profitable to factor out the statement if not at the end + of the bb. */ + if (gimple_could_trap_p (def_stmt)) + return false; + /* Check if the uses of arg is dominated by merge block, this is a quick and rough estimate if arg is still alive at the merge bb. */ /* FIXME: extend to a more complete live range detection. */