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 648A93858D37; Thu, 1 Dec 2022 05:35:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 648A93858D37 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 (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B15BBTX020958; Thu, 1 Dec 2022 05:35:57 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=message-id : date : mime-version : subject : to : cc : references : from : in-reply-to : content-type : content-transfer-encoding; s=pp1; bh=eWRaLawpisiX+rE9SzZpXZSBUN6t+tWAZCH+mxdZaQU=; b=OD6xTbrqAlPSVTI7V4/quplKuuUoAKSmG897M0kD76SYhu2HMYIH9P5J9ONHt9eEtyX0 3GYODoHTt0dyxSLJNjMrTZ85/oan9vY/YvVN0l0MO9c3hc7mvE5NF/RUrxTf5CT7/blF NUTfn/EyI3ngSmj1BpzBHZeNVXNJjpo2dv6M+zWBOiyd4lqWb5XU0dzDZowavmChmxGT byDZP3ukTx56xV2WOrxz2KYic4+tCXAsvLlGuoR9K44/jYAxwXMUlXMFRz4/jpqWPhWM gMhu3iFbnyTtEZq9SLN15jV4dR/M2BCe6dc2cmCPu9uEUsoLAnM6JK7MQLmhy+XjIGVi Dg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3m6nky8s3b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 05:35:56 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2B15J9CU017191; Thu, 1 Dec 2022 05:35:56 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3m6nky8s1w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 05:35:56 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2B15ZWSX001521; Thu, 1 Dec 2022 05:35:54 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03ams.nl.ibm.com with ESMTP id 3m3ae9eu5k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 05:35:53 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2B15aYMT65011988 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Dec 2022 05:36:34 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C7E6A4051; Thu, 1 Dec 2022 05:35:51 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 792CFA4040; Thu, 1 Dec 2022 05:35:49 +0000 (GMT) Received: from [9.200.99.34] (unknown [9.200.99.34]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 1 Dec 2022 05:35:49 +0000 (GMT) Message-ID: <9cbc0b3d-0d4b-5646-0ed8-fa2d4f8dc8c3@linux.ibm.com> Date: Thu, 1 Dec 2022 13:35:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Subject: Re: [PATCH 2/3]rs6000: NFC use sext_hwi to replace ((v&0xf..f)^0x80..0) - 0x80..0 Content-Language: en-US To: "Kewen.Lin" Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, linkw@gcc.gnu.org, gcc-patches@gcc.gnu.org References: <20221201013619.196004-1-guojiufu@linux.ibm.com> <20221201013619.196004-2-guojiufu@linux.ibm.com> <94338e4c-baf4-ec09-68a7-064a23c79327@linux.ibm.com> From: Jiufu Guo In-Reply-To: <94338e4c-baf4-ec09-68a7-064a23c79327@linux.ibm.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: lTF6uc3FxmDiCSJFwaOTJtD-NcYT8qg4 X-Proofpoint-GUID: HTImR0eZYxmjNId6hTtTitMod8zlkk89 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-01_03,2022-11-30_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 bulkscore=0 mlxscore=0 lowpriorityscore=0 clxscore=1015 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212010038 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,GIT_PATCH_0,KAM_NUMSUBJECT,NICE_REPLY_A,RCVD_IN_MSPIKE_H2,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 List-Id: Hi Kewen, Thanks for your quick and insight review! 在 12/1/22 1:17 PM, Kewen.Lin 写道: > Hi Jeff, > > on 2022/12/1 09:36, Jiufu Guo wrote: >> Hi, >> >> This patch just uses sext_hwi to replace the expression like: >> ((value & 0xf..f) ^ 0x80..0) - 0x80..0 for rs6000.cc and rs6000.md. >> >> Bootstrap & regtest pass on ppc64{,le}. >> Is this ok for trunk? > > You didn't say it clearly but I guessed you have grepped in the whole > config/rs6000 directory, right? I noticed there are still two places > using this kind of expression in function constant_generates_xxspltiw, > but I assumed it's intentional as their types are not HOST_WIDE_INT. > > gcc/config/rs6000/rs6000.cc: short sign_h_word = ((h_word & 0xffff) ^ 0x8000) - 0x8000; > gcc/config/rs6000/rs6000.cc: int sign_word = ((word & 0xffffffff) ^ 0x80000000) - 0x80000000; > > If so, could you state it clearly in commit log like "with type > signed/unsigned HOST_WIDE_INT" or similar? > Good question! And as you said sext_hwi is more for "signed/unsigned HOST_WIDE_INT". For these two places, it seems sext_hwi is not needed actually! And I did see why these expressions are used, may be just an assignment is ok. So, this patch does not cover these two places. BR, Jeff (Jiufu) > This patch is OK once the above question gets confirmed, thanks! > > BR, > Kewen > >> >> BR, >> Jeff (Jiufu) >> >> gcc/ChangeLog: >> >> * config/rs6000/rs6000.cc (num_insns_constant_gpr): Use sext_hwi. >> (darwin_rs6000_legitimate_lo_sum_const_p): Likewise. >> (mem_operand_gpr): Likewise. >> (mem_operand_ds_form): Likewise. >> (rs6000_legitimize_address): Likewise. >> (rs6000_emit_set_const): Likewise. >> (rs6000_emit_set_long_const): Likewise. >> (print_operand): Likewise. >> * config/rs6000/rs6000.md: Likewise. >> >> --- >> gcc/config/rs6000/rs6000.cc | 30 +++++++++++++----------------- >> gcc/config/rs6000/rs6000.md | 10 +++++----- >> 2 files changed, 18 insertions(+), 22 deletions(-) >> >> diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc >> index 5efe9b22d8b..718072cc9a1 100644 >> --- a/gcc/config/rs6000/rs6000.cc >> +++ b/gcc/config/rs6000/rs6000.cc >> @@ -6021,7 +6021,7 @@ num_insns_constant_gpr (HOST_WIDE_INT value) >> >> else if (TARGET_POWERPC64) >> { >> - HOST_WIDE_INT low = ((value & 0xffffffff) ^ 0x80000000) - 0x80000000; >> + HOST_WIDE_INT low = sext_hwi (value, 32); >> HOST_WIDE_INT high = value >> 31; >> >> if (high == 0 || high == -1) >> @@ -8456,7 +8456,7 @@ darwin_rs6000_legitimate_lo_sum_const_p (rtx x, machine_mode mode) >> } >> >> /* We only care if the access(es) would cause a change to the high part. */ >> - offset = ((offset & 0xffff) ^ 0x8000) - 0x8000; >> + offset = sext_hwi (offset, 16); >> return SIGNED_16BIT_OFFSET_EXTRA_P (offset, extra); >> } >> >> @@ -8522,7 +8522,7 @@ mem_operand_gpr (rtx op, machine_mode mode) >> if (GET_CODE (addr) == LO_SUM) >> /* For lo_sum addresses, we must allow any offset except one that >> causes a wrap, so test only the low 16 bits. */ >> - offset = ((offset & 0xffff) ^ 0x8000) - 0x8000; >> + offset = sext_hwi (offset, 16); >> >> return SIGNED_16BIT_OFFSET_EXTRA_P (offset, extra); >> } >> @@ -8562,7 +8562,7 @@ mem_operand_ds_form (rtx op, machine_mode mode) >> if (GET_CODE (addr) == LO_SUM) >> /* For lo_sum addresses, we must allow any offset except one that >> causes a wrap, so test only the low 16 bits. */ >> - offset = ((offset & 0xffff) ^ 0x8000) - 0x8000; >> + offset = sext_hwi (offset, 16); >> >> return SIGNED_16BIT_OFFSET_EXTRA_P (offset, extra); >> } >> @@ -9136,7 +9136,7 @@ rs6000_legitimize_address (rtx x, rtx oldx ATTRIBUTE_UNUSED, >> { >> HOST_WIDE_INT high_int, low_int; >> rtx sum; >> - low_int = ((INTVAL (XEXP (x, 1)) & 0xffff) ^ 0x8000) - 0x8000; >> + low_int = sext_hwi (INTVAL (XEXP (x, 1)), 16); >> if (low_int >= 0x8000 - extra) >> low_int = 0; >> high_int = INTVAL (XEXP (x, 1)) - low_int; >> @@ -10203,7 +10203,7 @@ rs6000_emit_set_const (rtx dest, rtx source) >> lo = operand_subword_force (dest, WORDS_BIG_ENDIAN != 0, >> DImode); >> emit_move_insn (hi, GEN_INT (c >> 32)); >> - c = ((c & 0xffffffff) ^ 0x80000000) - 0x80000000; >> + c = sext_hwi (c, 32); >> emit_move_insn (lo, GEN_INT (c)); >> } >> else >> @@ -10242,7 +10242,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) >> >> if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) >> || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) >> - emit_move_insn (dest, GEN_INT ((ud1 ^ 0x8000) - 0x8000)); >> + emit_move_insn (dest, GEN_INT (sext_hwi (ud1, 16))); >> >> else if ((ud4 == 0xffff && ud3 == 0xffff && (ud2 & 0x8000)) >> || (ud4 == 0 && ud3 == 0 && ! (ud2 & 0x8000))) >> @@ -10250,7 +10250,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) >> temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); >> >> emit_move_insn (ud1 != 0 ? copy_rtx (temp) : dest, >> - GEN_INT (((ud2 << 16) ^ 0x80000000) - 0x80000000)); >> + GEN_INT (sext_hwi (ud2 << 16, 32))); >> if (ud1 != 0) >> emit_move_insn (dest, >> gen_rtx_IOR (DImode, copy_rtx (temp), >> @@ -10261,8 +10261,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) >> temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); >> >> gcc_assert (ud2 & 0x8000); >> - emit_move_insn (copy_rtx (temp), >> - GEN_INT (((ud2 << 16) ^ 0x80000000) - 0x80000000)); >> + emit_move_insn (copy_rtx (temp), GEN_INT (sext_hwi (ud2 << 16, 32))); >> if (ud1 != 0) >> emit_move_insn (copy_rtx (temp), >> gen_rtx_IOR (DImode, copy_rtx (temp), >> @@ -10273,7 +10272,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) >> { >> temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); >> HOST_WIDE_INT num = (ud2 << 16) | ud1; >> - rs6000_emit_set_long_const (temp, (num ^ 0x80000000) - 0x80000000); >> + rs6000_emit_set_long_const (temp, sext_hwi (num, 32)); >> rtx one = gen_rtx_AND (DImode, temp, GEN_INT (0xffffffff)); >> rtx two = gen_rtx_ASHIFT (DImode, temp, GEN_INT (32)); >> emit_move_insn (dest, gen_rtx_IOR (DImode, one, two)); >> @@ -10283,8 +10282,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) >> { >> temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); >> >> - emit_move_insn (copy_rtx (temp), >> - GEN_INT (((ud3 << 16) ^ 0x80000000) - 0x80000000)); >> + emit_move_insn (copy_rtx (temp), GEN_INT (sext_hwi (ud3 << 16, 32))); >> if (ud2 != 0) >> emit_move_insn (copy_rtx (temp), >> gen_rtx_IOR (DImode, copy_rtx (temp), >> @@ -10336,8 +10334,7 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) >> { >> temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); >> >> - emit_move_insn (copy_rtx (temp), >> - GEN_INT (((ud4 << 16) ^ 0x80000000) - 0x80000000)); >> + emit_move_insn (copy_rtx (temp), GEN_INT (sext_hwi (ud4 << 16, 32))); >> if (ud3 != 0) >> emit_move_insn (copy_rtx (temp), >> gen_rtx_IOR (DImode, copy_rtx (temp), >> @@ -14167,8 +14164,7 @@ print_operand (FILE *file, rtx x, int code) >> /* If constant, low-order 16 bits of constant, signed. Otherwise, write >> normally. */ >> if (INT_P (x)) >> - fprintf (file, HOST_WIDE_INT_PRINT_DEC, >> - ((INTVAL (x) & 0xffff) ^ 0x8000) - 0x8000); >> + fprintf (file, HOST_WIDE_INT_PRINT_DEC, sext_hwi (INTVAL (x), 16)); >> else >> print_operand (file, x, 0); >> return; >> diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md >> index 3bae303086b..4bd1dfd3da9 100644 >> --- a/gcc/config/rs6000/rs6000.md >> +++ b/gcc/config/rs6000/rs6000.md >> @@ -1787,7 +1787,7 @@ (define_expand "add3" >> } >> >> HOST_WIDE_INT val = INTVAL (operands[2]); >> - HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000; >> + HOST_WIDE_INT low = sext_hwi (val, 16); >> HOST_WIDE_INT rest = trunc_int_for_mode (val - low, mode); >> >> if (mode == DImode && !satisfies_constraint_L (GEN_INT (rest))) >> @@ -1930,7 +1930,7 @@ (define_split >> (set (match_dup 0) (plus:GPR (match_dup 0) (match_dup 4)))] >> { >> HOST_WIDE_INT val = INTVAL (operands[2]); >> - HOST_WIDE_INT low = ((val & 0xffff) ^ 0x8000) - 0x8000; >> + HOST_WIDE_INT low = sext_hwi (val, 16); >> HOST_WIDE_INT rest = trunc_int_for_mode (val - low, mode); >> >> operands[4] = GEN_INT (low); >> @@ -8213,7 +8213,7 @@ (define_split >> operands[2] = operand_subword (operands[0], endian, 0, mode); >> operands[3] = operand_subword (operands[0], 1 - endian, 0, mode); >> operands[4] = GEN_INT (value >> 32); >> - operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000); >> + operands[1] = GEN_INT (sext_hwi (value, 32)); >> }) >> >> (define_split >> @@ -9577,7 +9577,7 @@ (define_split >> operands[3] = operand_subword_force (operands[0], WORDS_BIG_ENDIAN != 0, >> DImode); >> operands[4] = GEN_INT (value >> 32); >> - operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000); >> + operands[1] = GEN_INT (sext_hwi (value, 32)); >> }) >> >> (define_split >> @@ -12425,7 +12425,7 @@ (define_peephole2 >> SImode, >> operands[1], operands[2]); >> HOST_WIDE_INT c = INTVAL (cnst); >> - HOST_WIDE_INT sextc = ((c & 0xffff) ^ 0x8000) - 0x8000; >> + HOST_WIDE_INT sextc = sext_hwi (c, 16); >> HOST_WIDE_INT xorv = c ^ sextc; >> >> operands[9] = GEN_INT (xorv);