From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 6F5963890417; Fri, 16 Apr 2021 07:13:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 6F5963890417 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 13G73nh9183914; Fri, 16 Apr 2021 03:13:43 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 37xs0tj3j4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Apr 2021 03:13:42 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 13G74E1P186052; Fri, 16 Apr 2021 03:13:42 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 37xs0tj3hb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Apr 2021 03:13:42 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.0.43/8.16.0.43) with SMTP id 13G7Cfp3019190; Fri, 16 Apr 2021 07:13:39 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 37u3n8va6b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 16 Apr 2021 07:13:39 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 13G7DEQq32833898 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 16 Apr 2021 07:13:14 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BD5654C040; Fri, 16 Apr 2021 07:13:36 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 98E444C044; Fri, 16 Apr 2021 07:13:35 +0000 (GMT) Received: from marlin.aus.stglabs.ibm.com (unknown [9.40.194.84]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 16 Apr 2021 07:13:35 +0000 (GMT) From: Xiong Hu Luo To: gcc-patches@gcc.gnu.org Cc: segher@kernel.crashing.org, dje.gcc@gmail.com, wschmidt@linux.ibm.com, guojiufu@linux.ibm.com, linkw@gcc.gnu.org, Xiong Hu Luo Subject: [PATCH] rs6000: Expand fmod and remainder when built with fast-math [PR97142] Date: Fri, 16 Apr 2021 02:10:07 -0500 Message-Id: <20210416071007.78812-1-luoxhu@linux.ibm.com> X-Mailer: git-send-email 2.27.0.90.geebb51ba8c MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 22dy22Ercpc6HsnVOHg_dBY90CUj6KFW X-Proofpoint-GUID: u3y_o29cxgH9BS13XRdJTh935pRq_tWE X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.761 definitions=2021-04-15_11:2021-04-15, 2021-04-15 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 priorityscore=1501 phishscore=0 mlxlogscore=999 clxscore=1015 impostorscore=0 adultscore=0 mlxscore=0 malwarescore=0 suspectscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104060000 definitions=main-2104160051 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, 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: Fri, 16 Apr 2021 07:13:44 -0000 fmod/fmodf and remainder/remainderf could be expanded instead of library call when fast-math build, which is much faster. fmodf: fdivs f0,f1,f2 friz f0,f0 fnmsubs f1,f2,f0,f1 remainderf: fdivs f0,f1,f2 frin f0,f0 fnmsubs f1,f2,f0,f1 gcc/ChangeLog: 2021-04-16 Xionghu Luo PR target/97142 * config/rs6000/rs6000.md (fmod3): New define_expand. (remainder3): Likewise. gcc/testsuite/ChangeLog: 2021-04-16 Xionghu Luo PR target/97142 * gcc.target/powerpc/pr97142.c: New test. --- gcc/config/rs6000/rs6000.md | 36 ++++++++++++++++++++++ gcc/testsuite/gcc.target/powerpc/pr97142.c | 30 ++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 gcc/testsuite/gcc.target/powerpc/pr97142.c diff --git a/gcc/config/rs6000/rs6000.md b/gcc/config/rs6000/rs6000.md index a1315523fec..7e0e94e6ba4 100644 --- a/gcc/config/rs6000/rs6000.md +++ b/gcc/config/rs6000/rs6000.md @@ -4902,6 +4902,42 @@ (define_insn "fre" [(set_attr "type" "fp") (set_attr "isa" "*,")]) +(define_expand "fmod3" + [(use (match_operand:SFDF 0 "gpc_reg_operand")) + (use (match_operand:SFDF 1 "gpc_reg_operand")) + (use (match_operand:SFDF 2 "gpc_reg_operand"))] + "TARGET_HARD_FLOAT + && TARGET_FPRND + && flag_unsafe_math_optimizations" +{ + rtx div = gen_reg_rtx (mode); + emit_insn (gen_div3 (div, operands[1], operands[2])); + + rtx friz = gen_reg_rtx (mode); + emit_insn (gen_btrunc2 (friz, div)); + + emit_insn (gen_nfms4 (operands[0], operands[2], friz, operands[1])); + DONE; + }) + +(define_expand "remainder3" + [(use (match_operand:SFDF 0 "gpc_reg_operand")) + (use (match_operand:SFDF 1 "gpc_reg_operand")) + (use (match_operand:SFDF 2 "gpc_reg_operand"))] + "TARGET_HARD_FLOAT + && TARGET_FPRND + && flag_unsafe_math_optimizations" +{ + rtx div = gen_reg_rtx (mode); + emit_insn (gen_div3 (div, operands[1], operands[2])); + + rtx frin = gen_reg_rtx (mode); + emit_insn (gen_round2 (frin, div)); + + emit_insn (gen_nfms4 (operands[0], operands[2], frin, operands[1])); + DONE; + }) + (define_insn "*rsqrt2" [(set (match_operand:SFDF 0 "gpc_reg_operand" "=,wa") (unspec:SFDF [(match_operand:SFDF 1 "gpc_reg_operand" ",wa")] diff --git a/gcc/testsuite/gcc.target/powerpc/pr97142.c b/gcc/testsuite/gcc.target/powerpc/pr97142.c new file mode 100644 index 00000000000..48f25ca5b5b --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/pr97142.c @@ -0,0 +1,30 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast" } */ + +#include + +float test1 (float x, float y) +{ + return fmodf (x, y); +} + +double test2 (double x, double y) +{ + return fmod (x, y); +} + +float test3 (float x, float y) +{ + return remainderf (x, y); +} + +double test4 (double x, double y) +{ + return remainder (x, y); +} + +/* { dg-final { scan-assembler-not {\mbl fmod\M} } } */ +/* { dg-final { scan-assembler-not {\mbl fmodf\M} } } */ +/* { dg-final { scan-assembler-not {\mbl remainder\M} } } */ +/* { dg-final { scan-assembler-not {\mbl remainderf\M} } } */ + -- 2.27.0.90.geebb51ba8c