From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id B0C62385F011 for ; Wed, 15 Apr 2020 08:48:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B0C62385F011 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 03F8YMIO024080 for ; Wed, 15 Apr 2020 04:48:09 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0b-001b2d01.pphosted.com with ESMTP id 30dnmqx0rm-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 15 Apr 2020 04:48:09 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 15 Apr 2020 09:47:26 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 15 Apr 2020 09:47:24 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 03F8m38S49610826 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 15 Apr 2020 08:48:03 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 66A1142047; Wed, 15 Apr 2020 08:48:03 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2631742042; Wed, 15 Apr 2020 08:48:02 +0000 (GMT) Received: from genoa.aus.stglabs.ibm.com (unknown [9.40.192.157]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 15 Apr 2020 08:48:01 +0000 (GMT) From: luoxhu@linux.ibm.com To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, wschmidt@linux.ibm.com, guojiufu@linux.ibm.com, linkw@gcc.gnu.org, joseph@codesourcery.com, pinskia@gmail.com, Xionghu Luo Subject: [PATCH] Fold (add -1; zero_ext; add +1) operations to zero_ext when not zero (PR37451, PR61837) Date: Wed, 15 Apr 2020 03:47:55 -0500 X-Mailer: git-send-email 2.21.0.777.g83232e3864 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 x-cbid: 20041508-0020-0000-0000-000003C827D8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20041508-0021-0000-0000-00002221087D Message-Id: <20200415084755.72653-1-luoxhu@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.676 definitions=2020-04-15_01:2020-04-14, 2020-04-15 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 clxscore=1015 phishscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 spamscore=0 mlxscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004150062 X-Spam-Status: No, score=-26.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_DMARC_STATUS, KAM_SHORT, RCVD_IN_DNSWL_LOW, 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-List-Received-Date: Wed, 15 Apr 2020 08:48:11 -0000 From: Xionghu Luo This "subtract/extend/add" existed for a long time and still annoying us (PR37451, PR61837) when converting from 32bits to 64bits, as the ctr register is used as 64bits on powerpc64, Andraw Pinski had a patch but caused some issue and reverted by Joseph S. Myers(PR37451, PR37782). Andraw: http://gcc.gnu.org/ml/gcc-patches/2008-09/msg01070.html http://gcc.gnu.org/ml/gcc-patches/2008-10/msg01321.html Joseph: https://gcc.gnu.org/legacy-ml/gcc-patches/2011-11/msg02405.html However, the doloop code improved a lot since so many years passed, gcc.c-torture/execute/doloop-1.c is no longer a simple loop with constant desc->niter_expr since r125:SI#0 is not SImode, so it is not a valid doloop and no transform done in doloop again. Thus we can do the simplification from "subtract/extend/add" to only extend as the condition in doloop will never be false based on loop ch's optimization. What's more, this patch is slightly different with Andrw's implementation, the check of ZERO_EXT and SImode will guard the count won't be changed from char/short caused cases not time out on slow platforms before. Any comments? Thanks. doloop-1.c.257r.loop2_doloop ... 12: [r129:DI]=r123:SI REG_DEAD r129:DI REG_DEAD r123:SI 13: r125:SI=r120:DI#0-0x1 REG_DEAD r120:DI 14: r120:DI=zero_extend(r125:SI#0) REG_DEAD r125:SI 16: r126:CC=cmp(r120:DI,0) 17: pc={(r126:CC!=0)?L43:pc} REG_DEAD r126:CC ... Bootstrap and regression tested pass on Power8-LE. gcc/ChangeLog 2020-04-15 Xiong Hu Luo PR rtl-optimization/37451, PR target/61837 loop-doloop.c (doloop_modify): Simplify (add -1; zero_ext; add +1) to zero_ext. --- gcc/loop-doloop.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/loop-doloop.c b/gcc/loop-doloop.c index db6a014e43d..9f967fa3a0b 100644 --- a/gcc/loop-doloop.c +++ b/gcc/loop-doloop.c @@ -477,7 +477,31 @@ doloop_modify (class loop *loop, class niter_desc *desc, } if (increment_count) - count = simplify_gen_binary (PLUS, mode, count, const1_rtx); + { + /* Fold (add -1; zero_ext; add +1) operations to zero_ext based on addop0 + is never zero, as gimple pass loop ch will do optimization to simplify + the loop to NO loop for loop condition is false. */ + bool simplify_zext = false; + rtx extop0 = XEXP (count, 0); + if (mode == E_DImode + && GET_CODE (count) == ZERO_EXTEND + && GET_CODE (extop0) == PLUS) + { + rtx addop0 = XEXP (extop0, 0); + rtx addop1 = XEXP (extop0, 1); + if (CONST_SCALAR_INT_P (addop1) + && GET_MODE (addop0) == E_SImode + && addop1 == GEN_INT (-1)) + { + count = simplify_gen_unary (ZERO_EXTEND, mode, addop0, + GET_MODE (addop0)); + simplify_zext = true; + } + } + + if (!simplify_zext) + count = simplify_gen_binary (PLUS, mode, count, const1_rtx); + } /* Insert initialization of the count register into the loop header. */ start_sequence (); -- 2.21.0.777.g83232e3864