From patchwork Tue Sep 28 13:17:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robin Dapp X-Patchwork-Id: 45502 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1C0AF3858436 for ; Tue, 28 Sep 2021 13:18:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1C0AF3858436 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1632835089; bh=yfWm4ysxGmOanCTJcRdEfIkiUgpdYxNN5tJZhiT2Dok=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=qmpJJfECxjQImGyeObKH1dGfjony1hiuczAs500V1jVNddWemCSH2OT/AvcqplPyN na8UuS35rkRuQMAfMjfjTsMg/hQywc8Zy5bxzgjwK1HPhsvd0mcCDsOHcO8L9MiYsk nMs8o0AwzK7cz/2DAEZvp9/VsP5ruGvwlM6z7xUs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id BB8AB3858408 for ; Tue, 28 Sep 2021 13:17:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BB8AB3858408 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18SCOElx010015; Tue, 28 Sep 2021 09:17:37 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 3bc1nsu5bc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Sep 2021 09:17:36 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 18SDDGFS014022; Tue, 28 Sep 2021 13:17:35 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 3b9u1jec67-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 28 Sep 2021 13:17:35 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 18SDCVAO61735178 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 28 Sep 2021 13:12:31 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 246C2AE053; Tue, 28 Sep 2021 13:17:32 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EEA46AE057; Tue, 28 Sep 2021 13:17:31 +0000 (GMT) Received: from li-926bd7cc-2dd1-11b2-a85c-f6adc0f5efec.ibm.com (unknown [9.171.2.81]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Tue, 28 Sep 2021 13:17:31 +0000 (GMT) Subject: [PATCH 8/7] ifcvt: Second try in order to avoid unnecessary temporaries To: GCC Patches , richard.sandiford@arm.com Message-ID: <1b37f716-ac71-d61e-469c-69aceb371019@linux.ibm.com> Date: Tue, 28 Sep 2021 15:17:31 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-GUID: zRRPip_fm3aAmJtLKqhpTH57yIqdR_jt X-Proofpoint-ORIG-GUID: zRRPip_fm3aAmJtLKqhpTH57yIqdR_jt X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-09-28_05,2021-09-28_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 mlxlogscore=999 suspectscore=0 phishscore=0 impostorscore=0 adultscore=0 lowpriorityscore=0 priorityscore=1501 bulkscore=0 mlxscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2109280075 X-Spam-Status: No, score=-12.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Robin Dapp via Gcc-patches From: Robin Dapp Reply-To: Robin Dapp Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch implements the latest of my attempts to avoid some of the unnecessary temporaries noce_convert_multiple currently emits. I named it 8/7 because it actually applies on top of the last series that is not yet approved while being a rather minor change. The idea is to go over the list of convertible sets a second time if, during the first try, we noticed that we potentially overwrite the condition but no later set makes use of it anymore (because it can rely on the CC directly instead). In that case we omit creating a temporary. The whole series was bootstrapped and regtested on s390, x86 and ppc64. Regards Robin --- gcc/ChangeLog: * ifcvt.c (noce_convert_multiple_sets): Perform a second try with less temporaries. commit dd5a0f8d7d39447025d36ed5305709d38fe3f16b Author: Robin Dapp Date: Fri Sep 17 20:22:10 2021 +0200 ifcvt: Run second pass if it is possible to omit a temporary. If one of the to-be-converted SETs requires the original comparison (i.e. in order to generate a min/max insn) but no other insn after it does, we can omit creating temporaries, thus facilitating costing. diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c index 4f3af5e1b00..2243157e32c 100644 --- a/gcc/ifcvt.c +++ b/gcc/ifcvt.c @@ -3261,6 +3261,11 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) need_cmov_or_rewire (then_bb, &need_no_cmov, &rewired_src); + int last_needs_comparison = -1; + bool second_try = false; + +restart: + FOR_BB_INSNS (then_bb, insn) { /* Skip over non-insns. */ @@ -3302,8 +3307,12 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) Therefore we introduce a temporary every time we are about to overwrite a variable used in the check. Costing of a sequence with these is going to be inaccurate so only use temporaries when - needed. */ - if (reg_overlap_mentioned_p (target, cond)) + needed. + + If performing a second try, we know how many insns require a + temporary. For the last of these, we can omit creating one. */ + if (reg_overlap_mentioned_p (target, cond) + && (!second_try || count < last_needs_comparison)) temp = gen_reg_rtx (GET_MODE (target)); else temp = target; @@ -3386,6 +3395,8 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) { seq = seq1; temp_dest = temp_dest1; + if (!second_try) + last_needs_comparison = count; } else if (seq2 != NULL_RTX) { @@ -3409,6 +3420,24 @@ noce_convert_multiple_sets (struct noce_if_info *if_info) unmodified_insns.safe_push (insn); } + /* If there are insns that overwrite part of the initial + comparison, we can still omit creating temporaries for + the last of them. + As the second try will always create a less expensive, + valid sequence, we do not need to compare and can discard + the first one. */ + if (!second_try && last_needs_comparison >= 0) + { + end_sequence (); + start_sequence (); + count = 0; + targets.truncate (0); + temporaries.truncate (0); + unmodified_insns.truncate (0); + second_try = true; + goto restart; + } + /* We must have seen some sort of insn to insert, otherwise we were given an empty BB to convert, and we can't handle that. */ gcc_assert (!unmodified_insns.is_empty ());