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 E5FA4385783C for ; Mon, 4 Dec 2023 09:21:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E5FA4385783C 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 ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E5FA4385783C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701681706; cv=none; b=GMBqJoiwvpWAm8LY2FcpgvvzTEuxMCYkKgb4RKL6zCR4egn1gKw6/MdBp1vJSvzhaiOoG/7b84W/kd2j+BR/+llcsidKzPKP39uB81FRW7SvXitOMuzaBwmRMyiPuB6s/qfa0uRc0gtwfsXHGtxFxqDpprf09I4KWwdxIlSHmcs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701681706; c=relaxed/simple; bh=9Jnx4WA1map0YTCsHUIoYEVI5rDo4e9V8bb3GifIpfQ=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=b4Y9ieubw8qfPCXPlN3DWCJfGhBzNNMn4m5j9a8ritwWJT0OqkToZpwASgZh+SFBAYW2OMP+I4O7MCri9kP93bpFWt4lUQmdKjNhVB710fZRy2Q/nJTxNJ/0RNnP5QTQu5WtIYsGl68J8gr3WT1i/F2hOsX6AFTC+C6cr4Dsydk= ARC-Authentication-Results: i=1; server2.sourceware.org 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 3B48r4Ww029015; Mon, 4 Dec 2023 09:21:40 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=E1CEuBEojq5xPMf/laVqbpMqhx6NHB8qM+5Xo3L4dsU=; b=GfTLaXufwZP0Om85dFPkSwSHxw+IcE5n8FCyvDfQcIX9OU2wGZOp1m68IhpC4jvWVjw0 iXOv8Qg1iv1c+CbknXP93T3JIkHBhFxuxVAuYP2TFf4R2MiiRI01s056U8orqbpG2ecy vMHKe6m5yKPANresEkvflj4rKIogDh5/hkSt0YAhIzols0Tk1uV1ayv9kNOgVcf0R+DP L4QsbP/FSEjHq/A0IC0PJHukZNYz9vzHX0nf9dFoPJVMajmvv8QICoBsVglTu3y+LR+H k5XBlkgFUZVaT1dcfsp/+WZgvnqNz4swPD8w7chqGvnVnRgQc/ZcX3yAJMqhXroN0L6/ fg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3usbn10y39-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 09:21:40 +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 3B49GETk014465; Mon, 4 Dec 2023 09:21:39 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3usbn10y2m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 09:21:39 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3B474Wj2007764; Mon, 4 Dec 2023 09:21:38 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3urgdkq510-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 04 Dec 2023 09:21:38 +0000 Received: from smtpav02.fra02v.mail.ibm.com (smtpav02.fra02v.mail.ibm.com [10.20.54.101]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 3B49LaL722348426 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 4 Dec 2023 09:21:36 GMT Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 421B220040; Mon, 4 Dec 2023 09:21:36 +0000 (GMT) Received: from smtpav02.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8127B20043; Mon, 4 Dec 2023 09:21:33 +0000 (GMT) Received: from [9.177.13.229] (unknown [9.177.13.229]) by smtpav02.fra02v.mail.ibm.com (Postfix) with ESMTP; Mon, 4 Dec 2023 09:21:33 +0000 (GMT) Message-ID: Date: Mon, 4 Dec 2023 17:21:31 +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] rs6000: Canonicalize copysign (x, -1) back to -abs (x) in the backend [PR112606] Content-Language: en-US To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, Tamar Christina , Andrew Pinski , David Edelsohn , Segher Boessenkool References: From: "Kewen.Lin" In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: CMSx7s6GslzHNquZ4TPp5-bET6WDGuBz X-Proofpoint-ORIG-GUID: umIl7TqgzxBDtavOfVmsKeUW-8CbAQz0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-04_06,2023-11-30_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 suspectscore=0 mlxlogscore=803 impostorscore=0 phishscore=0 clxscore=1011 adultscore=0 lowpriorityscore=0 mlxscore=0 spamscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2311060000 definitions=main-2312040070 X-Spam-Status: No, score=-7.4 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_MSPIKE_H4,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 Jakub, on 2023/11/25 18:17, Jakub Jelinek wrote: > Hi! > > The middle-end has been changed quite recently to canonicalize > -abs (x) to copysign (x, -1) rather than the other way around. > While I agree with that at GIMPLE level, since it matches the GIMPLE > goal of as few operations as possible for a canonical form (-abs (x) > is 2 GIMPLE statements, copysign (x, -1) is just one), I must say > I don't really like that being done on RTL as well (or at least > not canonicalizing (COPYSIGN x, negative) back to (NEG (ABS x))), > because on most targets most of floating point constants need to be loaded > from memory, there are a few exceptions but -1 is often not one of them. > > Anyway, the following patch fixes the rs6000 regression caused by the > change in GIMPLE canonicalization (i.e. the desirable one). As rs6000 > clearly prefers -abs (x) form because it has a single instruction to do > that while it also has copysign instruction, but that requires loading the > -1 from memory, the following patch just ensures the copysign expander > can actually see the floating point constant and in that case emits the > -abs (x) code (or in the hypothetical case of copysign with non-negative > constant abs (x) - but there copysign (x, 1) in GIMPLE is canonicalized > to abs (x)), otherwise forces the operand to be the expected gpc_reg_operand > and does what it did before. > > Bootstrapped/regtested on powerpc64le-linux, ok for trunk? Thanks for fixing this! IIUC even with Tamar's further improvement proposal, we still need some rs6000 specific work, then updating this copysign expansion looks more straightforward. So okay for trunk, thanks! BR, Kewen > > 2023-11-25 Jakub Jelinek > > PR target/112606 > * config/rs6000/rs6000.md (copysign3): Change predicate > of the last argument from gpc_reg_operand to any_operand. If > operands[2] is CONST_DOUBLE, emit abs or neg abs depending on > its sign, otherwise if it doesn't satisfy gpc_reg_operand, > force it to REG using copy_to_mode_reg. > > --- gcc/config/rs6000/rs6000.md.jj 2023-10-13 19:34:43.927834877 +0200 > +++ gcc/config/rs6000/rs6000.md 2023-11-24 18:54:13.587876170 +0100 > @@ -5358,7 +5358,7 @@ (define_expand "copysign3" > (set (match_dup 4) > (neg:SFDF (abs:SFDF (match_dup 1)))) > (set (match_operand:SFDF 0 "gpc_reg_operand") > - (if_then_else:SFDF (ge (match_operand:SFDF 2 "gpc_reg_operand") > + (if_then_else:SFDF (ge (match_operand:SFDF 2 "any_operand") > (match_dup 5)) > (match_dup 3) > (match_dup 4)))] > @@ -5369,6 +5369,24 @@ (define_expand "copysign3" > || TARGET_CMPB > || VECTOR_UNIT_VSX_P (mode))" > { > + /* Middle-end canonicalizes -fabs (x) to copysign (x, -1), > + but PowerPC prefers -fabs (x). */ > + if (CONST_DOUBLE_AS_FLOAT_P (operands[2])) > + { > + if (real_isneg (CONST_DOUBLE_REAL_VALUE (operands[2]))) > + { > + operands[3] = gen_reg_rtx (mode); > + emit_insn (gen_abs2 (operands[3], operands[1])); > + emit_insn (gen_neg2 (operands[0], operands[3])); > + } > + else > + emit_insn (gen_abs2 (operands[0], operands[1])); > + DONE; > + } > + > + if (!gpc_reg_operand (operands[2], mode)) > + operands[2] = copy_to_mode_reg (mode, operands[2]); > + > if (TARGET_CMPB || VECTOR_UNIT_VSX_P (mode)) > { > emit_insn (gen_copysign3_fcpsgn (operands[0], operands[1], > > Jakub >