From patchwork Sun Oct 15 12:43:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajit Agarwal X-Patchwork-Id: 153008 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp2911593vqb; Sun, 15 Oct 2023 05:44:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcsdGABnfE3fUrHCmeN6MHXRFnrazFlrXFuOHtP8y0wZYe0YjZ79fsi5MvEnQBzJ5ZnYQX X-Received: by 2002:a05:690c:338c:b0:5a7:d997:cc7b with SMTP id fl12-20020a05690c338c00b005a7d997cc7bmr13803652ywb.23.1697373855542; Sun, 15 Oct 2023 05:44:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1697373855; cv=pass; d=google.com; s=arc-20160816; b=N/WXoheFxYi0Y0VZL3vTYhI5TWi1X2YaOiNVHwbCIdwfW+Gih/WzAmq2tSGcvAVe+k kujNGKGZPidu48KJV6mTKihZ/t/wmI4ndDnZraUq7lATTKk/+n371BFqHRtaVD5gKaTF Qnsrl78I7T24Hega0LQ5pTAGwD+/Yc99wNn+CFp8gd6oKDyE30RWIIMwQyVrmAtE9zPF pKE0QmYXcd2H+BgVZ2K+lZMMviG2cV9/I+RvHtSbBdQ2gXUms06ubUf8zLcius6X7/AG sVBGoOKat1IogWYHZhXhzp1dKqT4yzkpRToAuxLfC4Nnlx8U29JiAAmxBwvqdqwUHpXW 5jdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :in-reply-to:from:cc:to:references:content-language:subject :user-agent:mime-version:date:message-id:dkim-signature:dmarc-filter :arc-filter:delivered-to; bh=y6R1OgKDzALCjuY3HV23iKXUSWdaWuLZSG/icLtfZMQ=; fh=+XVqlVKqB3CY7AAWqEyeid1pgplNpfF/vMwN7kJwlwo=; b=sB/MCJ4iq/DruyaLnLKfFM94a+dglfXium0RtoDz5uo2rOgJ1AAfAgQm+fEOmibksM yWOiBE2ckdwk+WQFn/wS1fEMO1w3MpVEo/x0jddpNU2VczwHYipU5G7sudsLSggOdOOS KCS8lG3sjPsQbWe6g8A7KbSvgAVE+Fo1eoXoPg4alds58Kj2OmHJXIBkg9CwP7xuQvIE MGsl5rN3dU9Si6ktSud0MBnZmOaEo0Gd34RA1rZ4RPAopYhfwNhEzFuQsNN39Xl2uYJt rfr9G6cSGDIT3lfR33aidjOgKbLzNrfFaB1nAALHG6oFGHY+wtADldWGvW1zTqENJh5P 4CKw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=fRNLn2UA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id z2-20020a0cf002000000b0066cf26bb45esi3864576qvk.144.2023.10.15.05.44.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Oct 2023 05:44:15 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@ibm.com header.s=pp1 header.b=fRNLn2UA; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=REJECT sp=NONE dis=NONE) header.from=ibm.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4E82B385842C for ; Sun, 15 Oct 2023 12:44:15 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id B47733858D33 for ; Sun, 15 Oct 2023 12:43:49 +0000 (GMT) ARC-Filter: OpenARC Filter v1.0.0 sourceware.org B47733858D33 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697373831; cv=none; b=mPqEnZA8vhNgBuKPuaFDmMypfRi/iNnFgcB8dTDpbMbICxanYKolJXuROYgC1F//PfsqIzanwcnHYC6reAEONPBOlRV+CPzhTKG7JSvg+ZUBNIQJwkHo0y1NHRPH7Ri9ER9QG+lrb8kEd2YAE98XBCVKdVy6Bbr3T823fSC2RpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697373831; c=relaxed/simple; bh=8Fv3KdkfWORfn24RDitBMg83U7fpYYKDJqd4bDQV1dI=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=NJ2kqTaNXsG03ZKkrtBqd8qlyWSchGsntw/OeUNq3gLxSgilegXVvJR2Hs0p5ecNgAImxAxAPcZmGpuPUkQOmNfdB26cs9icZAr99BAJH4GqLbJe0xlAt2/KjxnIwI+J355iPGmPDZKchZ0B0LFW74u1qHlPe9PxK7Gmh3AIJFk= ARC-Authentication-Results: i=1; server2.sourceware.org DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B47733858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39FCCtvm004445; Sun, 15 Oct 2023 12:43:48 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : references : to : cc : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=y6R1OgKDzALCjuY3HV23iKXUSWdaWuLZSG/icLtfZMQ=; b=fRNLn2UANK6cz24mFerHQ8alGJEGTq/bebeEMeeO0aQ+J3qqTcx40VmBUAes9fiE9cs/ fEFxZJjerA0V879aHlEbw/ag7o74B2UDA6D4CT18cs6j3rV0WwI4zk/vw0Qnw0pCq8Ei IFhhrFnH3d3J5yM05xq2/XwImA8aF4atvNhRPinjSiyy9T5sv+aWGS0GimoddzyUiz3D TaGU88qffmc0W9GuMRH411h/rhjQd/yERKNuFEKD2PhWfQfHrIEeNj+0CedBVlPO/H4J +9Epm8M8SS0uZuUhGcqiFlZik6F5qKRPMhylDHWH17YwRI1QA5SDstgZlNXxYBcMQD7c bg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3trfvr0e4r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 12:43:48 +0000 Received: from m0356517.ppops.net (m0356517.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39FCDL7i004948; Sun, 15 Oct 2023 12:43:48 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3trfvr0e4e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 12:43:47 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39FBI3CB012880; Sun, 15 Oct 2023 12:43:46 GMT Received: from smtprelay02.dal12v.mail.ibm.com ([172.16.1.4]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tr5pxtwpy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 15 Oct 2023 12:43:46 +0000 Received: from smtpav02.wdc07v.mail.ibm.com (smtpav02.wdc07v.mail.ibm.com [10.39.53.229]) by smtprelay02.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39FChjPD34603600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 15 Oct 2023 12:43:45 GMT Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5362858059; Sun, 15 Oct 2023 12:43:45 +0000 (GMT) Received: from smtpav02.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4293358058; Sun, 15 Oct 2023 12:43:42 +0000 (GMT) Received: from [9.43.104.193] (unknown [9.43.104.193]) by smtpav02.wdc07v.mail.ibm.com (Postfix) with ESMTP; Sun, 15 Oct 2023 12:43:41 +0000 (GMT) Message-ID: <316ff561-2180-4cc6-8675-b6e27623d6d9@linux.ibm.com> Date: Sun, 15 Oct 2023 18:13:40 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PING ^0] [PATCH v8 4/4] ree: Improve ree pass for rs6000 target using defined ABI interfaces Content-Language: en-US References: <4aed9b18-3c58-b640-e9ac-cd81cb6e4dfa@linux.ibm.com> To: gcc-patches Cc: Jeff Law , Vineet Gupta , Richard Biener , Segher Boessenkool , Peter Bergner , "Kewen.Lin" From: Ajit Agarwal In-Reply-To: <4aed9b18-3c58-b640-e9ac-cd81cb6e4dfa@linux.ibm.com> X-Forwarded-Message-Id: <4aed9b18-3c58-b640-e9ac-cd81cb6e4dfa@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: PwahOU0EEc0qX1Azh5AubZJm89ocO4ta X-Proofpoint-GUID: wPcm3cA5QF55HBsRYqmlBM_sV0HtQpf- X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-14_03,2023-10-12_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 clxscore=1011 priorityscore=1501 spamscore=0 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310150114 X-Spam-Status: No, score=-12.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777455875706179481 X-GMAIL-MSGID: 1779825487889136169 Hello All: Please review and update with your comments so that code changes are committed in trunk. Thanks & Regards Ajit -------- Forwarded Message -------- Subject: [PATCH v8 4/4] ree: Improve ree pass for rs6000 target using defined ABI interfaces Date: Wed, 20 Sep 2023 02:40:49 +0530 From: Ajit Agarwal To: gcc-patches CC: Jeff Law , Vineet Gupta , Richard Biener , Segher Boessenkool , Peter Bergner Hello All: This version 8 of the patch uses abi interfaces to remove zero and sign extension elimination. Bootstrapped and regtested on powerpc-linux-gnu. Incorporated all the review comments of version 6. Added sign extension elimination using abi interfaces. Thanks & Regards Ajit ree: Improve ree pass for rs6000 target using defined abi interfaces For rs6000 target we see redundant zero and sign extension and done to improve ree pass to eliminate such redundant zero and sign extension using defined ABI interfaces. 2023-09-20 Ajit Kumar Agarwal gcc/ChangeLog: * ree.cc (combine_reaching_defs): Use of zero_extend and sign_extend defined abi interfaces. (add_removable_extension): Use of defined abi interfaces for no reaching defs. (abi_extension_candidate_return_reg_p): New function. (abi_extension_candidate_p): New function. (abi_extension_candidate_argno_p): New function. (abi_handle_regs_without_defs_p): New function. (abi_target_promote_function_mode): New function. gcc/testsuite/ChangeLog: * g++.target/powerpc/zext-elim-3.C --- gcc/ree.cc | 161 +++++++++++++++++- .../g++.target/powerpc/zext-elim-3.C | 13 ++ 2 files changed, 171 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.target/powerpc/zext-elim-3.C diff --git a/gcc/ree.cc b/gcc/ree.cc index fc04249fa84..e833db2432d 100644 --- a/gcc/ree.cc +++ b/gcc/ree.cc @@ -514,7 +514,8 @@ get_uses (rtx_insn *insn, rtx reg) if (REGNO (DF_REF_REG (def)) == REGNO (reg)) break; - gcc_assert (def != NULL); + if (def == NULL) + return NULL; ref_chain = DF_REF_CHAIN (def); @@ -750,6 +751,134 @@ get_extended_src_reg (rtx src) return src; } +/* Return TRUE if target mode is equal to source mode of zero_extend + or sign_extend otherwise false. */ + +static bool +abi_target_promote_function_mode (machine_mode mode) +{ + int unsignedp; + machine_mode tgt_mode + = targetm.calls.promote_function_mode (NULL_TREE, mode, &unsignedp, + NULL_TREE, 1); + + if (tgt_mode == mode) + return true; + else + return false; +} + +/* Return TRUE if the candidate insn is zero extend and regno is + a return registers. */ + +static bool +abi_extension_candidate_return_reg_p (rtx_insn *insn, int regno) +{ + rtx set = single_set (insn); + rtx src = SET_SRC (set); + + if (GET_CODE (src) != ZERO_EXTEND && GET_CODE (src) != SIGN_EXTEND) + return false; + + if (targetm.calls.function_value_regno_p (regno)) + return true; + + return false; +} + +/* Return TRUE if reg source operand of zero_extend is argument registers + and not return registers and source and destination operand are same + and mode of source and destination operand are not same. */ + +static bool +abi_extension_candidate_p (rtx_insn *insn) +{ + rtx set = single_set (insn); + rtx src = SET_SRC (set); + + if (GET_CODE (src) != ZERO_EXTEND && GET_CODE (src) != SIGN_EXTEND) + return false; + + machine_mode dst_mode = GET_MODE (SET_DEST (set)); + rtx orig_src = XEXP (SET_SRC (set), 0); + + if (!FUNCTION_ARG_REGNO_P (REGNO (orig_src)) + || abi_extension_candidate_return_reg_p (insn, REGNO (orig_src))) + return false; + + /* Mode of destination and source of zero_extend should be different. */ + if (dst_mode == GET_MODE (orig_src)) + return false; + + /* REGNO of source and destination of zero_extend should be same. */ + if (REGNO (SET_DEST (set)) != REGNO (orig_src)) + return false; + + return true; +} + +/* Return TRUE if the candidate insn is zero extend and regno is + an argument registers. */ + +static bool +abi_extension_candidate_argno_p (rtx_code code, int regno) +{ + if (code != ZERO_EXTEND && code != SIGN_EXTEND) + return false; + + if (FUNCTION_ARG_REGNO_P (regno)) + return true; + + return false; +} + +/* Return TRUE if the candidate insn doesn't have defs and have + * uses without RTX_BIN_ARITH/RTX_COMM_ARITH/RTX_UNARY rtx class. */ + +static bool +abi_handle_regs (rtx_insn *insn) +{ + if (side_effects_p (PATTERN (insn))) + return false; + + struct df_link *uses = get_uses (insn, SET_DEST (PATTERN (insn))); + + if (!uses) + return false; + + for (df_link *use = uses; use; use = use->next) + { + if (!use->ref) + return false; + + if (BLOCK_FOR_INSN (insn) != BLOCK_FOR_INSN (DF_REF_INSN (use->ref))) + return false; + + rtx_insn *use_insn = DF_REF_INSN (use->ref); + + if (GET_CODE (PATTERN (use_insn)) == SET) + { + rtx_code code = GET_CODE (SET_SRC (PATTERN (use_insn))); + + if (GET_RTX_CLASS (code) == RTX_BIN_ARITH + || GET_RTX_CLASS (code) == RTX_COMM_ARITH + || GET_RTX_CLASS (code) == RTX_UNARY) + return false; + } + } + + rtx set = single_set (insn); + + if (GET_CODE (SET_SRC (set)) == SIGN_EXTEND) + { + machine_mode mode = GET_MODE (XEXP (SET_SRC (set), 0)); + bool promote_p = abi_target_promote_function_mode (mode); + + return promote_p; + } + return true; +} + /* This function goes through all reaching defs of the source of the candidate for elimination (CAND) and tries to combine the extension with the definition instruction. The changes @@ -770,6 +899,11 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, ext_state *state) state->defs_list.truncate (0); state->copies_list.truncate (0); + rtx orig_src = XEXP (SET_SRC (cand->expr),0); + + if (abi_extension_candidate_p (cand->insn) + && (!get_defs (cand->insn, orig_src, NULL))) + return abi_handle_regs (cand->insn); outcome = make_defs_and_copies_lists (cand->insn, set_pat, state); @@ -1036,6 +1170,15 @@ combine_reaching_defs (ext_cand *cand, const_rtx set_pat, ext_state *state) } } + rtx insn_set = single_set (cand->insn); + + machine_mode mode = (GET_MODE (XEXP (SET_SRC (insn_set), 0))); + + bool promote_p = abi_target_promote_function_mode (mode); + + if (promote_p) + return true; + if (merge_successful) { /* Commit the changes here if possible @@ -1112,6 +1255,14 @@ add_removable_extension (const_rtx expr, rtx_insn *insn, rtx reg = XEXP (src, 0); struct df_link *defs, *def; ext_cand *cand; + defs = get_defs (insn, reg, NULL); + + if (!defs && abi_extension_candidate_argno_p (code, REGNO (reg))) + { + ext_cand e = {expr, code, mode, insn}; + insn_list->safe_push (e); + return; + } /* Zero-extension of an undefined value is partly defined (it's completely undefined for sign-extension, though). So if there exists @@ -1131,7 +1282,6 @@ add_removable_extension (const_rtx expr, rtx_insn *insn, } /* Second, make sure we can get all the reaching definitions. */ - defs = get_defs (insn, reg, NULL); if (!defs) { if (dump_file) @@ -1321,7 +1471,8 @@ find_and_remove_re (void) && (REGNO (SET_DEST (set)) != REGNO (XEXP (SET_SRC (set), 0)))) { reinsn_copy_list.safe_push (curr_cand->insn); - reinsn_copy_list.safe_push (state.defs_list[0]); + if (state.defs_list.length () != 0) + reinsn_copy_list.safe_push (state.defs_list[0]); } reinsn_del_list.safe_push (curr_cand->insn); state.modified[INSN_UID (curr_cand->insn)].deleted = 1; @@ -1345,6 +1496,10 @@ find_and_remove_re (void) for (unsigned int i = 0; i < reinsn_copy_list.length (); i += 2) { rtx_insn *curr_insn = reinsn_copy_list[i]; + + if ((i+1) >= reinsn_copy_list.length ()) + continue; + rtx_insn *def_insn = reinsn_copy_list[i + 1]; /* Use the mode of the destination of the defining insn diff --git a/gcc/testsuite/g++.target/powerpc/zext-elim-3.C b/gcc/testsuite/g++.target/powerpc/zext-elim-3.C new file mode 100644 index 00000000000..5a050df06ff --- /dev/null +++ b/gcc/testsuite/g++.target/powerpc/zext-elim-3.C @@ -0,0 +1,13 @@ +/* { dg-options "-mcpu=power9 -O2" } */ + +void *memset(void *b, int c, unsigned long len) +{ + unsigned long i; + + for (i = 0; i < len; i++) + ((unsigned char *)b)[i] = c; + + return b; +} + +/* { dg-final { scan-assembler-not "\mrlwinm\M" } } */