From patchwork Fri Jun 21 02:34:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 1950523 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=e1Gqy4HC; 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 4W51g03VPWz20X4 for ; Fri, 21 Jun 2024 12:35:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 682493895FF8 for ; Fri, 21 Jun 2024 02:35:19 +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 09B02389364E for ; Fri, 21 Jun 2024 02:34:54 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 09B02389364E 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 09B02389364E 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=1718937297; cv=none; b=fLXdti3zNQLcdJkcSOzGlwkx9EYegwdYMJHU5kIuC3wLXMGqz5jlMJW6qt+2n0VG705U2YTmpwGcLnAbLrYuOJ2H7th6PcSAdk9ES/5uTSLSeapyN4vdnjz/VS70I5zU2CEE9fRvivGTAFryRGSJFrQ8cNQUBeiuVaZGXW9drKs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718937297; c=relaxed/simple; bh=Y5nAWQNW/ZPxde+IPAO7YGLPbmJIKh9jWPg1XyAYtAU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=B/Q6NXmdI/QFzmLRv7Nq3WicE8OqBOh7dppKMSjgjEg5BFobMd1WxnpnqhBXy3Rzw3+hPIZIKTEsCJ66ioUx+Er3L98j/+mmoX/p+K6H8WB6IHz16WBczl/T2d4I0Q/PzatVA4/SZAe5Wjd9XbgcXu7pJuX8cP0v28X4/lz47ss= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 45KHBEt4026019 for ; Fri, 21 Jun 2024 02:34:53 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=Ovj07YP/CDnvQIcmStFCyB /Pyb+aByPCIVucQxNljcQ=; b=e1Gqy4HCL+OEOeHUtbEt9HZRtyIHSJ8Zn4+cKk keEKBi8F8Bep2XHe19tZrmdhr82owFo0TX3B2ZKwUt/Cl79aeSjQl/n+e87N1tig lfUiCA1FoZ2zls791IGLm5V/earLKILqosEPgwFPwuUwOmkxtXyaZ8dY7oJsBUMv RgOZQtLKtOk8oQl3PJcenZaql+fwuy9XUeTj4xrVcthOvVgQ5u8n1agxr8P7qzzP 2bV72s1x7M4GNIuUxtRCxfln7JYA8pQiFm48Br2tlNuWaGjU4Q6Qpc6unI/oU+JX W0+6YW+71KjTf8uVkkRXfEBmizeKZdQbmWn4awEc8jJcCAxA== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3yvrkr16cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jun 2024 02:34:53 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA03.qualcomm.com (8.17.1.19/8.17.1.19) with ESMTPS id 45L2YqNm019932 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 21 Jun 2024 02:34:52 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; Thu, 20 Jun 2024 19:34:52 -0700 From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH] complex-lowering: Better handling of PAREN_EXPR [PR68855] Date: Thu, 20 Jun 2024 19:34:39 -0700 Message-ID: <20240621023439.1645017-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: nalasex01b.na.qualcomm.com (10.47.209.197) 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: k-Z3l1Taqc-4hmlz41yFiq14DUZIFKKA X-Proofpoint-GUID: k-Z3l1Taqc-4hmlz41yFiq14DUZIFKKA 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-06-20_12,2024-06-20_04,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 mlxscore=0 clxscore=1015 phishscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 spamscore=0 adultscore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2406140001 definitions=main-2406210016 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, 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+incoming=patchwork.ozlabs.org@gcc.gnu.org When PAREN_EXPR tree code was added in r0-85884-gdedd42d511b6e4, a simplified handling was added to complex lowering. Which means we would get: ``` _9 = COMPLEX_EXPR <_15, _14>; _11 = ((_9)); _19 = REALPART_EXPR <_11>; _20 = IMAGPART_EXPR <_11>; ``` In many cases instead of just simply: ``` _19 = ((_15)); _20 = ((_14)); ``` So this adds full support for PAREN_EXPR to complex lowering. It is handled very similar as NEGATE_EXPR; except creating PAREN_EXPR instead of NEGATE_EXPR for the real/imag parts. This allows for more optimizations including vectorization, especially with -ffast-math. gfortran.dg/vect/pr68855.f90 is an example where this could show up. It also shows up in SPEC CPU 2006's 465.tonto; though I have not done any benchmarking there. Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: PR tree-optimization/68855 * tree-complex.cc (init_dont_simulate_again): Handle PAREN_EXPR like NEGATE_EXPR. (complex_propagate::visit_stmt): Likewise. (expand_complex_move): Don't handle PAREN_EXPR. (expand_complex_paren): New function. (expand_complex_operations_1): Handle PAREN_EXPR like NEGATE_EXPR. And call expand_complex_paren for PAREN_EXPR. gcc/testsuite/ChangeLog: * gcc.dg/vect/pr68855.c: New test. * gfortran.dg/vect/pr68855.f90: New test. Signed-off-by: Andrew Pinski --- gcc/testsuite/gcc.dg/vect/pr68855.c | 17 +++++++++++++ gcc/testsuite/gfortran.dg/vect/pr68855.f90 | 16 ++++++++++++ gcc/tree-complex.cc | 29 ++++++++++++++++++++-- 3 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/vect/pr68855.c create mode 100644 gcc/testsuite/gfortran.dg/vect/pr68855.f90 diff --git a/gcc/testsuite/gcc.dg/vect/pr68855.c b/gcc/testsuite/gcc.dg/vect/pr68855.c new file mode 100644 index 00000000000..68a3a1cee36 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr68855.c @@ -0,0 +1,17 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target vect_float } */ + +/* { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } */ + +/* PAREN_EXPR should not cause the vectorization of complex float add to be missed. */ +void foo(_Complex float *a, int n) +{ + for(int i = 0; i < n; i++) + { + _Complex float t; + t = a[i]; + t += 6.0; + t = __builtin_assoc_barrier(t); + a[i] = t; + } +} diff --git a/gcc/testsuite/gfortran.dg/vect/pr68855.f90 b/gcc/testsuite/gfortran.dg/vect/pr68855.f90 new file mode 100644 index 00000000000..90d444c86bf --- /dev/null +++ b/gcc/testsuite/gfortran.dg/vect/pr68855.f90 @@ -0,0 +1,16 @@ +! { dg-do compile } +! { dg-require-effective-target vect_float } + +! { dg-final { scan-tree-dump "LOOP VECTORIZED" "vect" } } +! PAREN_EXPR should not cause the vectorization of complex float add to be missed. + +subroutine foo(a,n) + + complex (kind(1.0)) :: a(*) + integer :: i,n + + do i=1,n + a(i)=(a(i)+(6.0,1.0)) + enddo + +end subroutine foo diff --git a/gcc/tree-complex.cc b/gcc/tree-complex.cc index 877913972bd..8a879acffca 100644 --- a/gcc/tree-complex.cc +++ b/gcc/tree-complex.cc @@ -281,6 +281,7 @@ init_dont_simulate_again (void) case NEGATE_EXPR: case CONJ_EXPR: + case PAREN_EXPR: if (TREE_CODE (TREE_TYPE (op0)) == COMPLEX_TYPE) saw_a_complex_op = true; break; @@ -391,6 +392,7 @@ complex_propagate::visit_stmt (gimple *stmt, edge *taken_edge_p ATTRIBUTE_UNUSED break; case NEGATE_EXPR: + case PAREN_EXPR: case CONJ_EXPR: new_l = find_lattice_value (gimple_assign_rhs1 (stmt)); break; @@ -852,8 +854,7 @@ expand_complex_move (gimple_stmt_iterator *gsi, tree type) update_complex_components_on_edge (e, lhs, r, i); } else if (is_gimple_call (stmt) - || gimple_has_side_effects (stmt) - || gimple_assign_rhs_code (stmt) == PAREN_EXPR) + || gimple_has_side_effects (stmt)) { r = build1 (REALPART_EXPR, inner_type, lhs); i = build1 (IMAGPART_EXPR, inner_type, lhs); @@ -1545,6 +1546,25 @@ expand_complex_negation (gimple_stmt_iterator *gsi, tree inner_type, update_complex_assignment (gsi, rr, ri); } +/* Expand complex paren to scalars: + ((a)) = ((ar)) + i((ai)) +*/ + +static void +expand_complex_paren (gimple_stmt_iterator *gsi, tree inner_type, + tree ar, tree ai) +{ + tree rr, ri; + gimple_seq stmts = NULL; + location_t loc = gimple_location (gsi_stmt (*gsi)); + + rr = gimple_build (&stmts, loc, PAREN_EXPR, inner_type, ar); + ri = gimple_build (&stmts, loc, PAREN_EXPR, inner_type, ai); + + gsi_insert_seq_before (gsi, stmts, GSI_SAME_STMT); + update_complex_assignment (gsi, rr, ri); +} + /* Expand complex conjugate to scalars: ~a = (ar) + i(-ai) */ @@ -1697,6 +1717,7 @@ expand_complex_operations_1 (gimple_stmt_iterator *gsi) case ROUND_DIV_EXPR: case RDIV_EXPR: case NEGATE_EXPR: + case PAREN_EXPR: case CONJ_EXPR: if (TREE_CODE (type) != COMPLEX_TYPE) return; @@ -1815,6 +1836,10 @@ expand_complex_operations_1 (gimple_stmt_iterator *gsi) expand_complex_comparison (gsi, ar, ai, br, bi, code); break; + case PAREN_EXPR: + expand_complex_paren (gsi, inner_type, ar, ai); + break; + default: gcc_unreachable (); }