From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 7A8443858C54; Wed, 7 Jun 2023 06:09:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7A8443858C54 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 (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 357665TF026058; Wed, 7 Jun 2023 06:09:31 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : references : date : in-reply-to : message-id : mime-version : content-type; s=pp1; bh=y+/z3L2SDsvuIIJ/07wOQaTN8iFT9qFGYiHjDMxAZmY=; b=ox0dD5b7ZmgBMcSkjRrazJa52oyr7N47O03/+tkgseRWluCjz3v1g6K1iMPMZm7rASH7 oR5+vU1LjD50aytsYLAnOzbJLtsczVWSFKwY/vms/27pGm4V8MFA+cJUAwyqpTzlY8PB 1YoI+9v7Uq3/aNDD/pL8GvOCyZbosf9MTa49C+GORwabwFvfffduMUz3RZu1xJlTr+FM t1R3gFM69ZbAKwiXPsu270FuZzRE6C7sF94dSUxqZStsUsh8DyJj4NBOPYlsIYJzuFae y2i45bZckXOuLxkBCCTg82/A3gQRGN8PUyWz26owd1bSSrVN99uwIYaoaQs+lEObA2E+ kg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r2kyn0j1g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jun 2023 06:09:31 +0000 Received: from m0353729.ppops.net (m0353729.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 357668QX026194; Wed, 7 Jun 2023 06:09:31 GMT Received: from ppma03dal.us.ibm.com (b.bd.3ea9.ip4.static.sl-reverse.com [169.62.189.11]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3r2kyn0j01-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jun 2023 06:09:30 +0000 Received: from pps.filterd (ppma03dal.us.ibm.com [127.0.0.1]) by ppma03dal.us.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 356IZ5Xr024186; Wed, 7 Jun 2023 06:09:29 GMT Received: from smtprelay02.wdc07v.mail.ibm.com ([9.208.129.120]) by ppma03dal.us.ibm.com (PPS) with ESMTPS id 3r2a760u0n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 07 Jun 2023 06:09:29 +0000 Received: from smtpav05.wdc07v.mail.ibm.com (smtpav05.wdc07v.mail.ibm.com [10.39.53.232]) by smtprelay02.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 35769SEW43188648 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 7 Jun 2023 06:09:28 GMT Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 369AA58053; Wed, 7 Jun 2023 06:09:28 +0000 (GMT) Received: from smtpav05.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DC5D358065; Wed, 7 Jun 2023 06:09:27 +0000 (GMT) Received: from ltcden2-lp1.aus.stglabs.ibm.com (unknown [9.3.90.43]) by smtpav05.wdc07v.mail.ibm.com (Postfix) with ESMTPS; Wed, 7 Jun 2023 06:09:27 +0000 (GMT) From: Jiufu Guo To: David Edelsohn Cc: GCC Patches , Segher Boessenkool , linkw@gcc.gnu.org Subject: Re: [PATCH 1/4] rs6000: build constant via li;rotldi References: Date: Wed, 07 Jun 2023 14:09:25 +0800 In-Reply-To: (David Edelsohn's message of "Fri, 2 Jun 2023 10:22:40 -0400") Message-ID: <7n4jnjiz1m.fsf@ltcden2-lp1.aus.stglabs.ibm.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-TM-AS-GCONF: 00 X-Proofpoint-GUID: _aQnew1VNBitM9AX8N_k2_-XQa87uVv9 X-Proofpoint-ORIG-GUID: bPevj5JxqXqE0Z6x5iTI0XRH2sLOwzld X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-07_03,2023-06-06_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 adultscore=0 mlxscore=0 suspectscore=0 priorityscore=1501 impostorscore=0 mlxlogscore=999 bulkscore=0 malwarescore=0 lowpriorityscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306070049 X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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 David, David Edelsohn writes: > > Hi, Jiufu > * config/rs6000/rs6000.cc (can_be_rotated_to_possitive_li): New function. > (can_be_rotated_to_negative_li): New function. > (can_be_built_by_li_and_rotldi): New function. > (rs6000_emit_set_long_const): Call can_be_built_by_li_and_rotldi. > In English the word "positive" contains one "s", not two. Please correct throughout the patches. > Also a style issue, comments before a function should be followed by a > blank line. Sure, I will update accordingly, and check other patches. >> +/* Check if C can be rotated to a possitive value which 'li' instruction > positive >> + is able to load. If so, set *ROT to the number by which C is rotated, >> + and return true. Return false otherwise. */ > Add a blank line here >> +static bool >> +can_be_rotated_to_possitive_li (HOST_WIDE_INT c, int *rot) > positive >> +{ >> + /* 49 leading zeros and 15 lowbits on the possitive value > low bits, positive Thanks for your careful review! >> + generated by 'li' instruction. */ >> + return can_be_rotated_to_lowbits (c, 15, rot); >> +} >> +/* Check if value C can be built by 2 instructions: one is 'li', another is >> + rotldi. >> + >> + If so, *SHIFT is set to the shift operand of rotldi(rldicl), and *MASK >> + is set to -1, and return true. Return false otherwise. */ >> +static bool >> +can_be_built_by_li_and_rotldi (HOST_WIDE_INT c, int *shift, >> + HOST_WIDE_INT *mask) >> +{ >> + int n; >> + if (can_be_rotated_to_possitive_li (c, &n) >> + || can_be_rotated_to_negative_li (c, &n)) >> + { >> + *mask = HOST_WIDE_INT_M1; >> + *shift = HOST_BITS_PER_WIDE_INT - n; >> + return true; >> + } >> + >> + return false; >> +} >> + >> /* Subroutine of rs6000_emit_set_const, handling PowerPC64 DImode. >> Output insns to set DEST equal to the constant C as a series of >> lis, ori and shl instructions. */ >> @@ -10246,15 +10285,14 @@ static void >> rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) >> { >> rtx temp; >> + int shift; >> + HOST_WIDE_INT mask; >> HOST_WIDE_INT ud1, ud2, ud3, ud4; >> >> ud1 = c & 0xffff; >> - c = c >> 16; >> - ud2 = c & 0xffff; >> - c = c >> 16; >> - ud3 = c & 0xffff; >> - c = c >> 16; >> - ud4 = c & 0xffff; >> + ud2 = (c >> 16) & 0xffff; >> + ud3 = (c >> 32) & 0xffff; >> + ud4 = (c >> 48) & 0xffff; >> >> if ((ud4 == 0xffff && ud3 == 0xffff && ud2 == 0xffff && (ud1 & 0x8000)) >> || (ud4 == 0 && ud3 == 0 && ud2 == 0 && ! (ud1 & 0x8000))) >> @@ -10278,6 +10316,19 @@ rs6000_emit_set_long_const (rtx dest, HOST_WIDE_INT c) >> emit_move_insn (dest, gen_rtx_XOR (DImode, temp, >> GEN_INT ((ud2 ^ 0xffff) << 16))); >> } >> + else if (can_be_built_by_li_and_rotldi (c, &shift, &mask)) >> + { >> + temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); >> + unsigned HOST_WIDE_INT imm = (c | ~mask); >> + imm = (imm >> shift) | (imm << (HOST_BITS_PER_WIDE_INT - shift)); >> + >> + emit_move_insn (temp, GEN_INT (imm)); >> + if (shift != 0) >> + temp = gen_rtx_ROTATE (DImode, temp, GEN_INT (shift)); >> + if (mask != HOST_WIDE_INT_M1) > How is mask != HOST_WIDE_INT_M1? The call to can_by_built_by_li_and_rotldi() set it > to that value and it is not modified in the interim statements. Oh, Thanks for catching this! Actually this line is shared for these patches. "if (mask != HOST_WIDE_INT_M1)" is useful with patch [3/4], and it should be merged into that patch. Thanks again for your review! >> + temp = gen_rtx_AND (DImode, temp, GEN_INT (mask)); >> + emit_move_insn (dest, temp); >> + } >> else if (ud3 == 0 && ud4 == 0) >> { >> temp = !can_create_pseudo_p () ? dest : gen_reg_rtx (DImode); > Thanks, David