From patchwork Wed Dec 16 08:49:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kewen.Lin" X-Patchwork-Id: 1416944 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=K1Jz7Yfj; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CwpjW3Dtzz9sRf for ; Wed, 16 Dec 2020 19:50:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A401C386F46D; Wed, 16 Dec 2020 08:50:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A401C386F46D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1608108602; bh=ZN1YmzBrnPrZWpKoiKZriDYXhhhXCQR9oZ5Z+pPti+w=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=K1Jz7YfjmcKCJF74Oc4LeopeaGXSBkzALA6z3zR+nk2Z/SxZugYH+7EKsSC14wid+ vupdm6EKXMrLN0nYHg2UOnr2aY3oJZTofskHsM37SF3azaOCZsPHaorqjE5pd6bbH/ I5Xyak0ITMTu7117P720FgwsYCclN9lK2bk1sr3E= 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 8B624386F439 for ; Wed, 16 Dec 2020 08:49:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 8B624386F439 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0BG8WdpC029594; Wed, 16 Dec 2020 03:49:57 -0500 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 35feshrfep-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 03:49:57 -0500 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0BG8h66q015942; Wed, 16 Dec 2020 08:49:55 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 35cng843hc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Dec 2020 08:49:54 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0BG8nqu632047370 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Dec 2020 08:49:52 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0715F42041; Wed, 16 Dec 2020 08:49:52 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 04B014203F; Wed, 16 Dec 2020 08:49:51 +0000 (GMT) Received: from kewenlins-mbp.cn.ibm.com (unknown [9.200.147.206]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 16 Dec 2020 08:49:50 +0000 (GMT) To: GCC Patches Subject: [PATCH/RFC] combine: Tweak the condition of last_set invalidation Message-ID: <6bcd32fa-d0ef-b136-ddd9-92a1d21f60af@linux.ibm.com> Date: Wed, 16 Dec 2020 16:49:49 +0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.9.0 MIME-Version: 1.0 Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2020-12-16_02:2020-12-15, 2020-12-16 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 mlxscore=0 bulkscore=0 phishscore=0 malwarescore=0 adultscore=0 impostorscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012160051 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "Kewen.Lin via Gcc-patches" From: "Kewen.Lin" Reply-To: "Kewen.Lin" Cc: Bill Schmidt , Segher Boessenkool Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi, When I was investigating unsigned int vec_init issue on Power, I happened to find there seems something we can enhance in how combine pass invalidate last_set (set last_set_invalid nonzero). Currently we have the check: if (!insn || (value && rsp->last_set_table_tick >= label_tick_ebb_start)) rsp->last_set_invalid = 1; which means if we want to record some value for some reg and this reg got refered before in a valid scope, we invalidate the set of reg (last_set_invalid to 1). It avoids to find the wrong set for one reg reference, such as the case like: ... op regX // this regX could find wrong last_set below regX = ... // if we think this set is valid ... op regX But because of retry's existence, the last_set_table_tick could be set by some later reference insns, but we see it's set due to retry on the set (for that reg) insn again, such as: insn 1 insn 2 regX = ... --> (a) ... op regX --> (b) insn 3 // assume all in the same BB. Assuming we combine 1, 2 -> 3 sucessfully and replace them as two (3 insns -> 2 insns), retrying from insn1 or insn2 again: it will scan insn (a) again, the below condition holds for regX: (value && rsp->last_set_table_tick >= label_tick_ebb_start) it will mark this set as invalid set. But actually the last_set_table_tick here is set by insn (b) before retrying, so it should be safe to be taken as valid set. This proposal is to check whether the last_set_table safely happens after the current set, make the set still valid if so. Bootstrapped/regtested on powerpc64le-linux-gnu (P9), aarch64-linux-gnu and x86_64-pc-linux-gnu. Full SPEC2017 building shows this patch gets more sucessful combines from 1902208 to 1902243 (trivial though). Any comments are highly appreciated! BR, Kewen ----- gcc/ChangeLog: * combine.c (struct reg_stat_type): New member last_set_table_luid. (update_table_tick): Add one argument for insn luid and set last_set_table_luid with it. (record_value_for_reg): Adjust the condition to set last_set_invalid nonzero. diff --git a/gcc/combine.c b/gcc/combine.c index 6fb2fa82c3f..2f45a0ad733 100644 --- a/gcc/combine.c +++ b/gcc/combine.c @@ -202,6 +202,10 @@ struct reg_stat_type { int last_set_table_tick; + /* Record the luid of the insn whose expression involving register n. */ + + int last_set_table_luid; + /* Record the value of label_tick when the value for register n is placed in last_set_value. */ @@ -480,7 +484,7 @@ static rtx gen_lowpart_for_combine (machine_mode, rtx); static enum rtx_code simplify_compare_const (enum rtx_code, machine_mode, rtx, rtx *); static enum rtx_code simplify_comparison (enum rtx_code, rtx *, rtx *); -static void update_table_tick (rtx); +static void update_table_tick (rtx, int); static void record_value_for_reg (rtx, rtx_insn *, rtx); static void check_promoted_subreg (rtx_insn *, rtx); static void record_dead_and_set_regs_1 (rtx, const_rtx, void *); @@ -13228,7 +13232,7 @@ count_rtxs (rtx x) for each register mentioned. Similar to mention_regs in cse.c */ static void -update_table_tick (rtx x) +update_table_tick (rtx x, int insn_luid) { enum rtx_code code = GET_CODE (x); const char *fmt = GET_RTX_FORMAT (code); @@ -13243,7 +13247,21 @@ update_table_tick (rtx x) for (r = regno; r < endregno; r++) { reg_stat_type *rsp = ®_stat[r]; - rsp->last_set_table_tick = label_tick; + if (rsp->last_set_table_tick >= label_tick_ebb_start) + { + /* Later references should not have lower ticks. */ + gcc_assert (label_tick >= rsp->last_set_table_tick); + /* Should pick up the lowest luid if the references + are in the same block. */ + if (label_tick == rsp->last_set_table_tick + && rsp->last_set_table_luid > insn_luid) + rsp->last_set_table_luid = insn_luid; + } + else + { + rsp->last_set_table_tick = label_tick; + rsp->last_set_table_luid = insn_luid; + } } return; @@ -13279,16 +13297,17 @@ update_table_tick (rtx x) if (ARITHMETIC_P (x0) && (x1 == XEXP (x0, 0) || x1 == XEXP (x0, 1))) { - update_table_tick (XEXP (x0, x1 == XEXP (x0, 0) ? 1 : 0)); + update_table_tick (XEXP (x0, x1 == XEXP (x0, 0) ? 1 : 0), + insn_luid); break; } } - update_table_tick (XEXP (x, i)); + update_table_tick (XEXP (x, i), insn_luid); } else if (fmt[i] == 'E') for (j = 0; j < XVECLEN (x, i); j++) - update_table_tick (XVECEXP (x, i, j)); + update_table_tick (XVECEXP (x, i, j), insn_luid); } /* Record that REG is set to VALUE in insn INSN. If VALUE is zero, we @@ -13359,7 +13378,10 @@ record_value_for_reg (rtx reg, rtx_insn *insn, rtx value) /* Mark registers that are being referenced in this value. */ if (value) - update_table_tick (value); + { + gcc_assert (insn); + update_table_tick (value, DF_INSN_LUID (insn)); + } /* Now update the status of each register being set. If someone is using this register in this block, set this register @@ -13372,8 +13394,11 @@ record_value_for_reg (rtx reg, rtx_insn *insn, rtx value) { rsp = ®_stat[i]; rsp->last_set_label = label_tick; + gcc_assert (label_tick >= rsp->last_set_table_tick); if (!insn - || (value && rsp->last_set_table_tick >= label_tick_ebb_start)) + || (value && rsp->last_set_table_tick >= label_tick_ebb_start + && !(label_tick == rsp->last_set_table_tick + && DF_INSN_LUID (insn) < rsp->last_set_table_luid))) rsp->last_set_invalid = 1; else rsp->last_set_invalid = 0;