From patchwork Mon Jul 1 21:46:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1954948 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=Qn43cZly; 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 4WCfly5b5Gz1xqd for ; Tue, 2 Jul 2024 07:47:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F28D3810B43 for ; Mon, 1 Jul 2024 21:47:39 +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 43C7E385C6CF for ; Mon, 1 Jul 2024 21:47:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 43C7E385C6CF 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 43C7E385C6CF 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=1719870431; cv=none; b=Sm2su8vlfIN0IVTLQGn+/OEF30/cbVIgNKtfK+CPtBK7QpVYMw87UPV5QLCln2Nb9IByt302EujC6b38UPxxZn8P4r/EKSaKgR+r7q8fR4j4V5UDmDu6c7yoosaxjbh0P95L9GPoW/4wKN2tfuHtsDT347iZwr6d7kPksiWtsQM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1719870431; c=relaxed/simple; bh=6QWUkEmywCrfx0e7K1uVBHfOaSrHOyXXEhzihw2thOs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iLBySMJE1RoAUOn3oB41qVz1ji6EznD0Hfgcf8x/NkYwbdTRcsVcGkoU+tEpmkkYlWnuk8YwHRVPCC5F9voaYkOotDcdqmVSnA7dHvVqRhDeQZ55+VuPJCLr04mR+iKry/ir45S6swGK2sDnen5GToLZ1NV11DK7U8hCBllAS3c= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 461JA25d003317 for ; Mon, 1 Jul 2024 21:47:09 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= I73JKn6gcx+P3roVxTKuL+OY295EDxZ5T/bZwZe63B4=; b=Qn43cZlyOZh3TCbQ 09jUuKB3a2ZSxEwB03YkR+VuR9OdreObQMTu0+TlcjJ7RhByc5vfaBCwPcjqXQBV L9U9kP1TuYO3azTPG+A1JW7Y1DwHsF1ITyiV2sygM+NqGe1siRK5e5os2OU41wuX ydQ2Lq2rl8rRlPR5MGDDwv62jamYqw2qowEHM/qJwpSeZKHZQwfW8LhXBqZr2o47 zgr3+u9HhZrFSx7qRcajb6FWZl9qx4iItyV4uv9/LVgNA0iNALh/V7UK6MM50mD+ Vq0+0OwuuADYSkGAWeaeDb+K1s1J5NjiwyvMiQiflocxm/fXJ4khYlpOxq3MI7N8 GijdDw== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 4029uxdes6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 01 Jul 2024 21:47:09 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 461Ll8Mk015923 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 1 Jul 2024 21:47:08 GMT Received: from hu-apinski-lv.qualcomm.com (10.80.80.8) 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; Mon, 1 Jul 2024 14:47:08 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 1/4] Small optimization for complex addition, real/imag parts the same Date: Mon, 1 Jul 2024 14:46:54 -0700 Message-ID: <20240701214657.3163066-2-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240701214657.3163066-1-quic_apinski@quicinc.com> References: <20240701214657.3163066-1-quic_apinski@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) 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: JrJMGAtsN6lquqGWO-ra9GtVZiTV_CMF X-Proofpoint-ORIG-GUID: JrJMGAtsN6lquqGWO-ra9GtVZiTV_CMF X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-01_21,2024-07-01_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=507 priorityscore=1501 impostorscore=0 bulkscore=0 spamscore=0 mlxscore=0 clxscore=1015 phishscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2407010162 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, SPF_HELO_NONE, SPF_PASS, 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 This is just a small optimization for the case where the real and imag parts are the same when lowering complex addition/subtraction. We only need to do the addition once when the real and imag parts are the same (on both sides of the operator). This gets done later on by FRE/PRE/DOM but having it done soon allows the cabs lowering to remove the sqrt and just change it to a multiply by a constant. Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * tree-complex.cc (expand_complex_addition): If both operands have the same real and imag parts, only add the addition once. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/complex-8.c: New test. Signed-off-by: Andrew Pinski --- gcc/testsuite/gcc.dg/tree-ssa/complex-8.c | 12 ++++++++++++ gcc/tree-complex.cc | 7 ++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/complex-8.c diff --git a/gcc/testsuite/gcc.dg/tree-ssa/complex-8.c b/gcc/testsuite/gcc.dg/tree-ssa/complex-8.c new file mode 100644 index 00000000000..a9636ff9e9a --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/complex-8.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-O1 -fdump-tree-cplxlower1-raw" } */ + +_Complex double f(double a, double c) +{ + _Complex double d = __builtin_complex (a, a); + d+=__builtin_complex(c, c); + return d; +} + +/* There should only be one plus as (a+c) is still (a+c) */ +/* { dg-final { scan-tree-dump-times "plus_expr, " 1 "cplxlower1" } } */ diff --git a/gcc/tree-complex.cc b/gcc/tree-complex.cc index 8a879acffca..dfebec18ec3 100644 --- a/gcc/tree-complex.cc +++ b/gcc/tree-complex.cc @@ -984,7 +984,12 @@ expand_complex_addition (gimple_stmt_iterator *gsi, tree inner_type, case PAIR (VARYING, VARYING): general: rr = gimple_build (&stmts, loc, code, inner_type, ar, br); - ri = gimple_build (&stmts, loc, code, inner_type, ai, bi); + /* (a+ai) + (b+bi) -> (a+b)+(a+b)i + small optimization to remove one new statement. */ + if (operand_equal_p (ar, ai) && operand_equal_p (br, bi)) + ri = rr; + else + ri = gimple_build (&stmts, loc, code, inner_type, ai, bi); break; default: