From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by sourceware.org (Postfix) with ESMTPS id DF5D73858001 for ; Tue, 12 Dec 2023 08:21:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF5D73858001 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 DF5D73858001 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=1702369303; cv=none; b=E1DCPsbCfF3l9aHdh6fVF1FhOgw8s+dxV+dCw6h8EcTsfgsTsDSQvhK0pT2V7Ha9Y3HEfTYZ5VKwLdS9S4fceupoR3tkHi6zDXDTD5hBtliT5+4WIZdbVu0tG/KVnNzr7Y3wP17vBcdAMPurWWRVzDgofJGnCeLsrgdkSz5AJR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702369303; c=relaxed/simple; bh=HpJehm+/ZpXNnU+skVKwQedCFY8FhuDVW7meyMFuHj0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=QRZ+DUtoxfWsgmssGS7TJcDiCWP3Pgo3qLDt0/ZFYgQUZ55nbpkw/vj4zJC71BJrqnbl7dqRN0neNzXbXOcbDJJjC+tum65p5VGJWwMTy3m3FTOKzLsUm6GY9k680EeNSdoc3zHPZCFAY9T6KP8/G+UlXr4mnJKBAeH17bru5P4= 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.17.1.24/8.17.1.24) with ESMTP id 3BC8LX9t003656 for ; Tue, 12 Dec 2023 08:21:41 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:subject:date:message-id:mime-version :content-transfer-encoding:content-type; s=qcppdkim1; bh=8Tk9g96 5Ia5VHvlkKwmipRVHvsa9caG3f8sRXOVRyVQ=; b=YtNNRDz1Q924CHRUKE25dIG ddlbf/N6a/I6qjEaalZoUnyx6W58ZGbZM1/zR9GdigkvtxybiaWCJR/+Mg4mh4eM VItKJbDE5z7A00ahkqJ9nxQPfEqDhdwprxH+bDC5WsWkSEdbruzPu5/7czlUBPp2 QMW5bKy4AHsvaWNy+nvbpuI5bW3fTi/VmuNIpcxw5LiBu3aaJ32pPZ3JGfbTfkHl iR6TVeVRq6Q1nJ7h/6LwKpnvQ4E2SFS5lUOr4CBEhk2787y+/05g/dXRZuJLUxqG KOqNIcD97kbOJm50j7j9hHFKfvEbfgSYjmeQHBJNcsLdbkbEt88jMI5c248Oqjg= = Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3uxkx58024-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 12 Dec 2023 08:21:41 +0000 (GMT) Received: from nasanex01c.na.qualcomm.com (nasanex01c.na.qualcomm.com [10.45.79.139]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BC8Le1Z020472 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 12 Dec 2023 08:21:40 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.1118.40; Tue, 12 Dec 2023 00:21:39 -0800 From: Andrew Pinski To: Subject: [PATCH] aarch64/expr: Use ccmp when the outer expression is used twice [PR100942] Date: Tue, 12 Dec 2023 00:21:29 -0800 Message-ID: <20231212082129.2556235-1-quic_apinski@quicinc.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain 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-GUID: cQMEL8SUDfUyTDTdhte_LYCAYrRfEM69 X-Proofpoint-ORIG-GUID: cQMEL8SUDfUyTDTdhte_LYCAYrRfEM69 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 bulkscore=0 impostorscore=0 mlxscore=0 spamscore=0 clxscore=1015 priorityscore=1501 phishscore=0 lowpriorityscore=0 mlxlogscore=414 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312120065 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE,URIBL_SBL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Ccmp is not used if the result of the and/ior is used by both a GIMPLE_COND and a GIMPLE_ASSIGN. This improves the code generation here by using ccmp in this case. Two changes is required, first we need to allow the outer statement's result be used more than once. The second change is that during the expansion of the gimple, we need to try using ccmp. This is needed because we don't use expand the ssa name of the lhs but rather expand directly from the gimple. A small note on the ccmp_4.c testcase, we should be able to get slightly better than with this patch but it is one extra instruction compared to before. Bootstraped and tested on aarch64-linux-gnu with no regressions. PR target/100942 gcc/ChangeLog: * ccmp.cc (ccmp_candidate_p): Add outer argument. Allow if the outer is true and the lhs is used more than once. (expand_ccmp_expr): Update call to ccmp_candidate_p. * cfgexpand.cc (expand_gimple_stmt_1): Try using ccmp for binary assignments. gcc/testsuite/ChangeLog: * gcc.target/aarch64/ccmp_3.c: New test. * gcc.target/aarch64/ccmp_4.c: New test. Signed-off-by: Andrew Pinski --- gcc/ccmp.cc | 9 +++--- gcc/cfgexpand.cc | 25 ++++++++++++++++ gcc/testsuite/gcc.target/aarch64/ccmp_3.c | 20 +++++++++++++ gcc/testsuite/gcc.target/aarch64/ccmp_4.c | 35 +++++++++++++++++++++++ 4 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.target/aarch64/ccmp_3.c create mode 100644 gcc/testsuite/gcc.target/aarch64/ccmp_4.c diff --git a/gcc/ccmp.cc b/gcc/ccmp.cc index 1bd6fadea35..a274f8c3d53 100644 --- a/gcc/ccmp.cc +++ b/gcc/ccmp.cc @@ -92,7 +92,7 @@ ccmp_tree_comparison_p (tree t, basic_block bb) /* Check whether G is a potential conditional compare candidate. */ static bool -ccmp_candidate_p (gimple *g) +ccmp_candidate_p (gimple *g, bool outer = false) { tree lhs, op0, op1; gimple *gs0, *gs1; @@ -109,8 +109,9 @@ ccmp_candidate_p (gimple *g) lhs = gimple_assign_lhs (g); op0 = gimple_assign_rhs1 (g); op1 = gimple_assign_rhs2 (g); - if ((TREE_CODE (op0) != SSA_NAME) || (TREE_CODE (op1) != SSA_NAME) - || !has_single_use (lhs)) + if ((TREE_CODE (op0) != SSA_NAME) || (TREE_CODE (op1) != SSA_NAME)) + return false; + if (!outer && !has_single_use (lhs)) return false; bb = gimple_bb (g); @@ -284,7 +285,7 @@ expand_ccmp_expr (gimple *g, machine_mode mode) rtx_insn *last; rtx tmp; - if (!ccmp_candidate_p (g)) + if (!ccmp_candidate_p (g, true)) return NULL_RTX; last = get_last_insn (); diff --git a/gcc/cfgexpand.cc b/gcc/cfgexpand.cc index b860be8bb77..0f9aad8e3eb 100644 --- a/gcc/cfgexpand.cc +++ b/gcc/cfgexpand.cc @@ -74,6 +74,7 @@ along with GCC; see the file COPYING3. If not see #include "output.h" #include "builtins.h" #include "opts.h" +#include "ccmp.h" /* Some systems use __main in a way incompatible with its use in gcc, in these cases use the macros NAME__MAIN to give a quoted symbol and SYMBOL__MAIN to @@ -3972,6 +3973,30 @@ expand_gimple_stmt_1 (gimple *stmt) if (GET_CODE (target) == SUBREG && SUBREG_PROMOTED_VAR_P (target)) promoted = true; + /* Try to expand conditonal compare. */ + if (targetm.gen_ccmp_first + && gimple_assign_rhs_class (assign_stmt) == GIMPLE_BINARY_RHS) + { + machine_mode mode = TYPE_MODE (TREE_TYPE (lhs)); + gcc_checking_assert (targetm.gen_ccmp_next != NULL); + temp = expand_ccmp_expr (stmt, mode); + if (temp) + { + if (promoted) + { + int unsignedp = SUBREG_PROMOTED_SIGN (target); + convert_move (SUBREG_REG (target), temp, unsignedp); + } + else + { + temp = force_operand (temp, target); + if (temp != target) + emit_move_insn (target, temp); + } + return; + } + } + ops.code = gimple_assign_rhs_code (assign_stmt); ops.type = TREE_TYPE (lhs); switch (get_gimple_rhs_class (ops.code)) diff --git a/gcc/testsuite/gcc.target/aarch64/ccmp_3.c b/gcc/testsuite/gcc.target/aarch64/ccmp_3.c new file mode 100644 index 00000000000..a2b47fbee14 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ccmp_3.c @@ -0,0 +1,20 @@ +/* { dg-options "-O2" } */ +/* PR target/100942 */ + +void foo(void); +int f1(int a, int b) +{ + int c = a == 0 || b == 0; + if (c) foo(); + return c; +} + +/* We should get one cmp followed by ccmp and one cset. */ +/* { dg-final { scan-assembler "\tccmp\t" } } */ +/* { dg-final { scan-assembler-times "\tcset\t" 1 } } */ +/* { dg-final { scan-assembler-times "\tcmp\t" 1 } } */ +/* And not get 2 cmps and 2 (or more cset) and orr and a cbnz. */ +/* { dg-final { scan-assembler-not "\torr\t" } } */ +/* { dg-final { scan-assembler-not "\tcbnz\t" } } */ +/* { dg-final { scan-assembler-not "\tcbz\t" } } */ + diff --git a/gcc/testsuite/gcc.target/aarch64/ccmp_4.c b/gcc/testsuite/gcc.target/aarch64/ccmp_4.c new file mode 100644 index 00000000000..bc0f57a7c59 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/ccmp_4.c @@ -0,0 +1,35 @@ +/* { dg-options "-O2" } */ +/* PR target/100942 */ + +void foo(void); +int f1(int a, int b, int d) +{ + int c = a < 8 || b < 9; + int e = d < 11 || c; + if (e) foo(); + return c; +} + +/* + We really should get: + cmp w0, 7 + ccmp w1, 8, 4, gt + cset w0, le + ccmp w2, 10, 4, gt + ble .L11 + + But we currently get: + cmp w0, 7 + ccmp w1, 8, 4, gt + cset w0, le + cmp w0, 0 + ccmp w2, 10, 4, eq + ble .L11 + The middle cmp is not needed. + */ + +/* We should end up with only one cmp and 2 ccmp and 1 cset but currently we get 2 cmp + though. */ +/* { dg-final { scan-assembler-times "\tccmp\t" 2 } } */ +/* { dg-final { scan-assembler-times "\tcset\t" 1 } } */ +/* { dg-final { scan-assembler-times "\tcmp\t" 1 { xfail *-*-* } } } */ -- 2.39.3