[rs6000] Disable gimple fold for float or double vec_minmax when fast-math is not set
Message ID | ff9638d7-0f97-b5e7-f57a-40f1dd721ce9@linux.ibm.com |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A146E3858424 for <patchwork@sourceware.org>; Mon, 1 Nov 2021 06:49:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A146E3858424 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1635749369; bh=g9+Kup9YWaj98zAgwBJ68fJ3hur7hjxtO87i6qHwBrI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=dfATJAvzNgPvPbNzzm36ml9lt/SfVu2qttdYlCMZ7oKe2Yw3lyL/1N3mFe24antoq cD+YfVd4kqiihOh7QbWyrZyBMI8W9p9Zda+Fhj24yDLxpxRcAnrcnsMjQ4daEqSOWa d936zBDmAakOD/MP/QJdxnvE2/E4i/VHVGgtYqfI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id EE7463858C60 for <gcc-patches@gcc.gnu.org>; Mon, 1 Nov 2021 06:48:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EE7463858C60 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 1A15llYb014752; Mon, 1 Nov 2021 06:48:57 GMT Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3c2add0yud-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Nov 2021 06:48:57 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 1A16WIXU024959; Mon, 1 Nov 2021 06:48:56 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3c2add0yty-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Nov 2021 06:48:56 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 1A16gP2e023737; Mon, 1 Nov 2021 06:48:54 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 3c0waj0ktv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 01 Nov 2021 06:48:54 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 1A16mpgZ64356806 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 1 Nov 2021 06:48:51 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B1D5411C054; Mon, 1 Nov 2021 06:48:51 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5F10B11C05C; Mon, 1 Nov 2021 06:48:50 +0000 (GMT) Received: from [9.200.100.183] (unknown [9.200.100.183]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 1 Nov 2021 06:48:50 +0000 (GMT) Content-Type: multipart/mixed; boundary="------------YUPxm8CUkXPGy2SwYVspgDNV" Message-ID: <ff9638d7-0f97-b5e7-f57a-40f1dd721ce9@linux.ibm.com> Date: Mon, 1 Nov 2021 14:48:47 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Content-Language: en-US To: gcc-patches <gcc-patches@gcc.gnu.org> Subject: [PATCH, rs6000] Disable gimple fold for float or double vec_minmax when fast-math is not set X-TM-AS-GCONF: 00 X-Proofpoint-GUID: qh3nGkdxED9Nsm4wvWnTKUmXysvw-K00 X-Proofpoint-ORIG-GUID: MtzbQfymD1hKqIUtGamEkPr2hpZFcy2E X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.425,FMLib:17.0.607.475 definitions=2021-11-01_02,2021-10-29_03,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 mlxlogscore=999 spamscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 mlxscore=0 adultscore=0 suspectscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2110150000 definitions=main-2111010037 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: HAO CHEN GUI via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: HAO CHEN GUI <guihaoc@linux.ibm.com> Cc: Bill Schmidt <wschmidt@linux.ibm.com>, David <dje.gcc@gmail.com>, Segher Boessenkool <segher@kernel.crashing.org> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
[rs6000] Disable gimple fold for float or double vec_minmax when fast-math is not set
|
|
Commit Message
HAO CHEN GUI
Nov. 1, 2021, 6:48 a.m. UTC
Hi, This patch disables gimple folding for VSX_BUILTIN_XVMINDP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMINFP and ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. With the gimple folding is enabled, the four built-ins will be implemented by c-type instructions - xs[min|max]cdp on P9 and P10 if they can be converted to scalar comparisons. While they are implemented by xv[min|max][s|d]p on P8 and P7 as P8 and P7 don't have corresponding scalar comparison instructions. The patch binds these four built-ins to xv[min|max][s|d]p when fast-math is not set. The two new test cases illustrate it. ALTIVEC_BUILTIN_VMINFP and ALTIVEC_BUILTIN_VMAXFP are not implemented by vminfp or vmaxfp. rs6000-builtin.def:BU_ALTIVEC_2 (VMAXFP, "vmaxfp", CONST, smaxv4sf3) rs6000-builtin.def:BU_ALTIVEC_2 (VMINFP, "vminfp", CONST, sminv4sf3) Bootstrapped and tested on powerpc64le-linux with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot. ChangeLog 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> gcc/ * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. gcc/testsuite/ * gcc.target/powerpc/vec-minmax-1.c: New test. * gcc.target/powerpc/vec-minmax-2.c: Likewise. patch.diff 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> gcc/ * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. gcc/testsuite/ * gcc.target/powerpc/vec-minmax-1.c: New test. * gcc.target/powerpc/vec-minmax-2.c: Likewise. diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c new file mode 100644 index 00000000000..e238659c9be --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c @@ -0,0 +1,52 @@ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ +/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */ + +/* This test verifies that float or double vec_min/max are bound to + xv[min|max][d|s]p instructions when fast-math is not set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +} diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c new file mode 100644 index 00000000000..149275d8709 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c @@ -0,0 +1,50 @@ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */ +/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */ +/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */ + +/* This test verifies that float or double vec_min/max can be converted + to scalar comparison when fast-math is set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +}
Comments
Hi, Hao Neither the inlined patch nor the attached patch seem to contain the change to rs6000-call.c. I only see the new testcases. Please resend the complete patch. Thanks David On Mon, Nov 1, 2021 at 2:48 AM HAO CHEN GUI <guihaoc@linux.ibm.com> wrote: > > Hi, > > This patch disables gimple folding for VSX_BUILTIN_XVMINDP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMINFP and ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. With the gimple folding is enabled, the four built-ins will be implemented by c-type instructions - xs[min|max]cdp on P9 and P10 if they can be converted to scalar comparisons. While they are implemented by xv[min|max][s|d]p on P8 and P7 as P8 and P7 don't have corresponding scalar comparison instructions. The patch binds these four built-ins to xv[min|max][s|d]p when fast-math is not set. The two new test cases illustrate it. > > ALTIVEC_BUILTIN_VMINFP and ALTIVEC_BUILTIN_VMAXFP are not implemented by vminfp or vmaxfp. > > rs6000-builtin.def:BU_ALTIVEC_2 (VMAXFP, "vmaxfp", CONST, smaxv4sf3) > > rs6000-builtin.def:BU_ALTIVEC_2 (VMINFP, "vminfp", CONST, sminv4sf3) > > Bootstrapped and tested on powerpc64le-linux with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot. > > > ChangeLog > > 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> > > gcc/ > * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable > gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, > VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not > set. > > gcc/testsuite/ > * gcc.target/powerpc/vec-minmax-1.c: New test. > * gcc.target/powerpc/vec-minmax-2.c: Likewise. > > > patch.diff > > diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c > new file mode 100644 > index 00000000000..e238659c9be > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c > @@ -0,0 +1,52 @@ > +/* { dg-require-effective-target powerpc_p9vector_ok } */ > +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ > +/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */ > +/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */ > +/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */ > +/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */ > + > +/* This test verifies that float or double vec_min/max are bound to > + xv[min|max][d|s]p instructions when fast-math is not set. */ > + > + > +#include <altivec.h> > + > +#ifdef _BIG_ENDIAN > + const int PREF_D = 0; > +#else > + const int PREF_D = 1; > +#endif > + > +double vmaxd (double a, double b) > +{ > + vector double va = vec_promote (a, PREF_D); > + vector double vb = vec_promote (b, PREF_D); > + return vec_extract (vec_max (va, vb), PREF_D); > +} > + > +double vmind (double a, double b) > +{ > + vector double va = vec_promote (a, PREF_D); > + vector double vb = vec_promote (b, PREF_D); > + return vec_extract (vec_min (va, vb), PREF_D); > +} > + > +#ifdef _BIG_ENDIAN > + const int PREF_F = 0; > +#else > + const int PREF_F = 3; > +#endif > + > +float vmaxf (float a, float b) > +{ > + vector float va = vec_promote (a, PREF_F); > + vector float vb = vec_promote (b, PREF_F); > + return vec_extract (vec_max (va, vb), PREF_F); > +} > + > +float vminf (float a, float b) > +{ > + vector float va = vec_promote (a, PREF_F); > + vector float vb = vec_promote (b, PREF_F); > + return vec_extract (vec_min (va, vb), PREF_F); > +} > diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c > new file mode 100644 > index 00000000000..149275d8709 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c > @@ -0,0 +1,50 @@ > +/* { dg-require-effective-target powerpc_p9vector_ok } */ > +/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */ > +/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */ > +/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */ > + > +/* This test verifies that float or double vec_min/max can be converted > + to scalar comparison when fast-math is set. */ > + > + > +#include <altivec.h> > + > +#ifdef _BIG_ENDIAN > + const int PREF_D = 0; > +#else > + const int PREF_D = 1; > +#endif > + > +double vmaxd (double a, double b) > +{ > + vector double va = vec_promote (a, PREF_D); > + vector double vb = vec_promote (b, PREF_D); > + return vec_extract (vec_max (va, vb), PREF_D); > +} > + > +double vmind (double a, double b) > +{ > + vector double va = vec_promote (a, PREF_D); > + vector double vb = vec_promote (b, PREF_D); > + return vec_extract (vec_min (va, vb), PREF_D); > +} > + > +#ifdef _BIG_ENDIAN > + const int PREF_F = 0; > +#else > + const int PREF_F = 3; > +#endif > + > +float vmaxf (float a, float b) > +{ > + vector float va = vec_promote (a, PREF_F); > + vector float vb = vec_promote (b, PREF_F); > + return vec_extract (vec_max (va, vb), PREF_F); > +} > + > +float vminf (float a, float b) > +{ > + vector float va = vec_promote (a, PREF_F); > + vector float vb = vec_promote (b, PREF_F); > + return vec_extract (vec_min (va, vb), PREF_F); > +}
David, My patch file was broken. I am sorry for it. Here is the correct one. Thanks a lot. ChangeLog 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> gcc/ * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. gcc/testsuite/ * gcc.target/powerpc/vec-minmax-1.c: New test. * gcc.target/powerpc/vec-minmax-2.c: Likewise. patch.diff diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index 7d485480225..a8e193a0089 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -12333,6 +12333,14 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return true; /* flavors of vec_min. */ case VSX_BUILTIN_XVMINDP: + case ALTIVEC_BUILTIN_VMINFP: + { + lhs = gimple_call_lhs (stmt); + tree type = TREE_TYPE (lhs); + if (HONOR_NANS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMINSD: case P8V_BUILTIN_VMINUD: case ALTIVEC_BUILTIN_VMINSB: @@ -12341,7 +12349,6 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VMINUB: case ALTIVEC_BUILTIN_VMINUH: case ALTIVEC_BUILTIN_VMINUW: - case ALTIVEC_BUILTIN_VMINFP: arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); lhs = gimple_call_lhs (stmt); @@ -12351,6 +12358,14 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return true; /* flavors of vec_max. */ case VSX_BUILTIN_XVMAXDP: + case ALTIVEC_BUILTIN_VMAXFP: + { + lhs = gimple_call_lhs (stmt); + tree type = TREE_TYPE (lhs); + if (HONOR_NANS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMAXSD: case P8V_BUILTIN_VMAXUD: case ALTIVEC_BUILTIN_VMAXSB: @@ -12359,7 +12374,6 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VMAXUB: case ALTIVEC_BUILTIN_VMAXUH: case ALTIVEC_BUILTIN_VMAXUW: - case ALTIVEC_BUILTIN_VMAXFP: arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); lhs = gimple_call_lhs (stmt); diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c new file mode 100644 index 00000000000..e238659c9be --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c @@ -0,0 +1,52 @@ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ +/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */ + +/* This test verifies that float or double vec_min/max are bound to + xv[min|max][d|s]p instructions when fast-math is not set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +} diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c new file mode 100644 index 00000000000..149275d8709 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c @@ -0,0 +1,50 @@ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */ +/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */ +/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */ + +/* This test verifies that float or double vec_min/max can be converted + to scalar comparison when fast-math is set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +} On 2/11/2021 上午 8:21, David Edelsohn wrote: > Hi, Hao > > Neither the inlined patch nor the attached patch seem to contain the > change to rs6000-call.c. I only see the new testcases. > > Please resend the complete patch. > > Thanks David > > On Mon, Nov 1, 2021 at 2:48 AM HAO CHEN GUI <guihaoc@linux.ibm.com> wrote: >> Hi, >> >> This patch disables gimple folding for VSX_BUILTIN_XVMINDP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMINFP and ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. With the gimple folding is enabled, the four built-ins will be implemented by c-type instructions - xs[min|max]cdp on P9 and P10 if they can be converted to scalar comparisons. While they are implemented by xv[min|max][s|d]p on P8 and P7 as P8 and P7 don't have corresponding scalar comparison instructions. The patch binds these four built-ins to xv[min|max][s|d]p when fast-math is not set. The two new test cases illustrate it. >> >> ALTIVEC_BUILTIN_VMINFP and ALTIVEC_BUILTIN_VMAXFP are not implemented by vminfp or vmaxfp. >> >> rs6000-builtin.def:BU_ALTIVEC_2 (VMAXFP, "vmaxfp", CONST, smaxv4sf3) >> >> rs6000-builtin.def:BU_ALTIVEC_2 (VMINFP, "vminfp", CONST, sminv4sf3) >> >> Bootstrapped and tested on powerpc64le-linux with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot. >> >> >> ChangeLog >> >> 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> >> >> gcc/ >> * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable >> gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, >> VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not >> set. >> >> gcc/testsuite/ >> * gcc.target/powerpc/vec-minmax-1.c: New test. >> * gcc.target/powerpc/vec-minmax-2.c: Likewise. >> >> >> patch.diff >> >> diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c >> new file mode 100644 >> index 00000000000..e238659c9be >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c >> @@ -0,0 +1,52 @@ >> +/* { dg-require-effective-target powerpc_p9vector_ok } */ >> +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ >> +/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */ >> +/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */ >> +/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */ >> +/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */ >> + >> +/* This test verifies that float or double vec_min/max are bound to >> + xv[min|max][d|s]p instructions when fast-math is not set. */ >> + >> + >> +#include <altivec.h> >> + >> +#ifdef _BIG_ENDIAN >> + const int PREF_D = 0; >> +#else >> + const int PREF_D = 1; >> +#endif >> + >> +double vmaxd (double a, double b) >> +{ >> + vector double va = vec_promote (a, PREF_D); >> + vector double vb = vec_promote (b, PREF_D); >> + return vec_extract (vec_max (va, vb), PREF_D); >> +} >> + >> +double vmind (double a, double b) >> +{ >> + vector double va = vec_promote (a, PREF_D); >> + vector double vb = vec_promote (b, PREF_D); >> + return vec_extract (vec_min (va, vb), PREF_D); >> +} >> + >> +#ifdef _BIG_ENDIAN >> + const int PREF_F = 0; >> +#else >> + const int PREF_F = 3; >> +#endif >> + >> +float vmaxf (float a, float b) >> +{ >> + vector float va = vec_promote (a, PREF_F); >> + vector float vb = vec_promote (b, PREF_F); >> + return vec_extract (vec_max (va, vb), PREF_F); >> +} >> + >> +float vminf (float a, float b) >> +{ >> + vector float va = vec_promote (a, PREF_F); >> + vector float vb = vec_promote (b, PREF_F); >> + return vec_extract (vec_min (va, vb), PREF_F); >> +} >> diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c >> new file mode 100644 >> index 00000000000..149275d8709 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c >> @@ -0,0 +1,50 @@ >> +/* { dg-require-effective-target powerpc_p9vector_ok } */ >> +/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */ >> +/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */ >> +/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */ >> + >> +/* This test verifies that float or double vec_min/max can be converted >> + to scalar comparison when fast-math is set. */ >> + >> + >> +#include <altivec.h> >> + >> +#ifdef _BIG_ENDIAN >> + const int PREF_D = 0; >> +#else >> + const int PREF_D = 1; >> +#endif >> + >> +double vmaxd (double a, double b) >> +{ >> + vector double va = vec_promote (a, PREF_D); >> + vector double vb = vec_promote (b, PREF_D); >> + return vec_extract (vec_max (va, vb), PREF_D); >> +} >> + >> +double vmind (double a, double b) >> +{ >> + vector double va = vec_promote (a, PREF_D); >> + vector double vb = vec_promote (b, PREF_D); >> + return vec_extract (vec_min (va, vb), PREF_D); >> +} >> + >> +#ifdef _BIG_ENDIAN >> + const int PREF_F = 0; >> +#else >> + const int PREF_F = 3; >> +#endif >> + >> +float vmaxf (float a, float b) >> +{ >> + vector float va = vec_promote (a, PREF_F); >> + vector float vb = vec_promote (b, PREF_F); >> + return vec_extract (vec_max (va, vb), PREF_F); >> +} >> + >> +float vminf (float a, float b) >> +{ >> + vector float va = vec_promote (a, PREF_F); >> + vector float vb = vec_promote (b, PREF_F); >> + return vec_extract (vec_min (va, vb), PREF_F); >> +} 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> gcc/ * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. gcc/testsuite/ * gcc.target/powerpc/vec-minmax-1.c: New test. * gcc.target/powerpc/vec-minmax-2.c: Likewise. diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index 7d485480225..a8e193a0089 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -12333,6 +12333,14 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return true; /* flavors of vec_min. */ case VSX_BUILTIN_XVMINDP: + case ALTIVEC_BUILTIN_VMINFP: + { + lhs = gimple_call_lhs (stmt); + tree type = TREE_TYPE (lhs); + if (HONOR_NANS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMINSD: case P8V_BUILTIN_VMINUD: case ALTIVEC_BUILTIN_VMINSB: @@ -12341,7 +12349,6 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VMINUB: case ALTIVEC_BUILTIN_VMINUH: case ALTIVEC_BUILTIN_VMINUW: - case ALTIVEC_BUILTIN_VMINFP: arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); lhs = gimple_call_lhs (stmt); @@ -12351,6 +12358,14 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return true; /* flavors of vec_max. */ case VSX_BUILTIN_XVMAXDP: + case ALTIVEC_BUILTIN_VMAXFP: + { + lhs = gimple_call_lhs (stmt); + tree type = TREE_TYPE (lhs); + if (HONOR_NANS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMAXSD: case P8V_BUILTIN_VMAXUD: case ALTIVEC_BUILTIN_VMAXSB: @@ -12359,7 +12374,6 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VMAXUB: case ALTIVEC_BUILTIN_VMAXUH: case ALTIVEC_BUILTIN_VMAXUW: - case ALTIVEC_BUILTIN_VMAXFP: arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); lhs = gimple_call_lhs (stmt); diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c new file mode 100644 index 00000000000..e238659c9be --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c @@ -0,0 +1,52 @@ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ +/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */ + +/* This test verifies that float or double vec_min/max are bound to + xv[min|max][d|s]p instructions when fast-math is not set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +} diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c new file mode 100644 index 00000000000..149275d8709 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c @@ -0,0 +1,50 @@ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */ +/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */ +/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */ + +/* This test verifies that float or double vec_min/max can be converted + to scalar comparison when fast-math is set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +}
On Mon, Nov 1, 2021 at 10:40 PM HAO CHEN GUI <guihaoc@linux.ibm.com> wrote: > > David, > > My patch file was broken. I am sorry for it. Here is the correct one. Thanks a lot. > > ChangeLog > > 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> > > gcc/ > * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable > gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, > VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not > set. > > gcc/testsuite/ > * gcc.target/powerpc/vec-minmax-1.c: New test. > * gcc.target/powerpc/vec-minmax-2.c: Likewise. This is okay. The default DejaGNU test action is compile, but it's a good idea to include the dg-do line to be clear and document the intention. Thanks, David
David, Thanks for your comments. I refined it according to your advice. ChangeLog 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> gcc/ * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. gcc/testsuite/ * gcc.target/powerpc/vec-minmax-1.c: New test. * gcc.target/powerpc/vec-minmax-2.c: Likewise. patch.diff diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index 7d485480225..a8e193a0089 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -12333,6 +12333,14 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return true; /* flavors of vec_min. */ case VSX_BUILTIN_XVMINDP: + case ALTIVEC_BUILTIN_VMINFP: + { + lhs = gimple_call_lhs (stmt); + tree type = TREE_TYPE (lhs); + if (HONOR_NANS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMINSD: case P8V_BUILTIN_VMINUD: case ALTIVEC_BUILTIN_VMINSB: @@ -12341,7 +12349,6 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VMINUB: case ALTIVEC_BUILTIN_VMINUH: case ALTIVEC_BUILTIN_VMINUW: - case ALTIVEC_BUILTIN_VMINFP: arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); lhs = gimple_call_lhs (stmt); @@ -12351,6 +12358,14 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return true; /* flavors of vec_max. */ case VSX_BUILTIN_XVMAXDP: + case ALTIVEC_BUILTIN_VMAXFP: + { + lhs = gimple_call_lhs (stmt); + tree type = TREE_TYPE (lhs); + if (HONOR_NANS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMAXSD: case P8V_BUILTIN_VMAXUD: case ALTIVEC_BUILTIN_VMAXSB: @@ -12359,7 +12374,6 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VMAXUB: case ALTIVEC_BUILTIN_VMAXUH: case ALTIVEC_BUILTIN_VMAXUW: - case ALTIVEC_BUILTIN_VMAXFP: arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); lhs = gimple_call_lhs (stmt); diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c new file mode 100644 index 00000000000..3f6e3760075 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ +/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */ + +/* This test verifies that float or double vec_min/max are bound to + xv[min|max][d|s]p instructions when fast-math is not set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +} diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c new file mode 100644 index 00000000000..b27bebba846 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c @@ -0,0 +1,51 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */ +/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */ +/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */ + +/* This test verifies that float or double vec_min/max can be converted + to scalar comparison when fast-math is set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +} On 2/11/2021 下午 9:12, David Edelsohn wrote: > On Mon, Nov 1, 2021 at 10:40 PM HAO CHEN GUI <guihaoc@linux.ibm.com> wrote: >> David, >> >> My patch file was broken. I am sorry for it. Here is the correct one. Thanks a lot. >> >> ChangeLog >> >> 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> >> >> gcc/ >> * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable >> gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, >> VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not >> set. >> >> gcc/testsuite/ >> * gcc.target/powerpc/vec-minmax-1.c: New test. >> * gcc.target/powerpc/vec-minmax-2.c: Likewise. > This is okay. > > The default DejaGNU test action is compile, but it's a good idea to > include the dg-do line to be clear and document the intention. > > Thanks, David 2021-11-01 Haochen Gui <guihaoc@linux.ibm.com> gcc/ * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): Disable gimple fold for VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP when fast-math is not set. gcc/testsuite/ * gcc.target/powerpc/vec-minmax-1.c: New test. * gcc.target/powerpc/vec-minmax-2.c: Likewise. diff --git a/gcc/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index 7d485480225..a8e193a0089 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -12333,6 +12333,14 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return true; /* flavors of vec_min. */ case VSX_BUILTIN_XVMINDP: + case ALTIVEC_BUILTIN_VMINFP: + { + lhs = gimple_call_lhs (stmt); + tree type = TREE_TYPE (lhs); + if (HONOR_NANS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMINSD: case P8V_BUILTIN_VMINUD: case ALTIVEC_BUILTIN_VMINSB: @@ -12341,7 +12349,6 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VMINUB: case ALTIVEC_BUILTIN_VMINUH: case ALTIVEC_BUILTIN_VMINUW: - case ALTIVEC_BUILTIN_VMINFP: arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); lhs = gimple_call_lhs (stmt); @@ -12351,6 +12358,14 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return true; /* flavors of vec_max. */ case VSX_BUILTIN_XVMAXDP: + case ALTIVEC_BUILTIN_VMAXFP: + { + lhs = gimple_call_lhs (stmt); + tree type = TREE_TYPE (lhs); + if (HONOR_NANS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMAXSD: case P8V_BUILTIN_VMAXUD: case ALTIVEC_BUILTIN_VMAXSB: @@ -12359,7 +12374,6 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) case ALTIVEC_BUILTIN_VMAXUB: case ALTIVEC_BUILTIN_VMAXUH: case ALTIVEC_BUILTIN_VMAXUW: - case ALTIVEC_BUILTIN_VMAXFP: arg0 = gimple_call_arg (stmt, 0); arg1 = gimple_call_arg (stmt, 1); lhs = gimple_call_lhs (stmt); diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c new file mode 100644 index 00000000000..3f6e3760075 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c @@ -0,0 +1,53 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ +/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */ + +/* This test verifies that float or double vec_min/max are bound to + xv[min|max][d|s]p instructions when fast-math is not set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +} diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c new file mode 100644 index 00000000000..b27bebba846 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c @@ -0,0 +1,51 @@ +/* { dg-do compile } */ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */ +/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */ +/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */ + +/* This test verifies that float or double vec_min/max can be converted + to scalar comparison when fast-math is set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +}
diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c new file mode 100644 index 00000000000..e238659c9be --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c @@ -0,0 +1,52 @@ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9" } */ +/* { dg-final { scan-assembler-times {\mxvmaxdp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmaxsp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvmindp\M} 1 } } */ +/* { dg-final { scan-assembler-times {\mxvminsp\M} 1 } } */ + +/* This test verifies that float or double vec_min/max are bound to + xv[min|max][d|s]p instructions when fast-math is not set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +} diff --git a/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c new file mode 100644 index 00000000000..149275d8709 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c @@ -0,0 +1,50 @@ +/* { dg-require-effective-target powerpc_p9vector_ok } */ +/* { dg-options "-O2 -mdejagnu-cpu=power9 -ffast-math" } */ +/* { dg-final { scan-assembler-times {\mxsmaxcdp\M} 2 } } */ +/* { dg-final { scan-assembler-times {\mxsmincdp\M} 2 } } */ + +/* This test verifies that float or double vec_min/max can be converted + to scalar comparison when fast-math is set. */ + + +#include <altivec.h> + +#ifdef _BIG_ENDIAN + const int PREF_D = 0; +#else + const int PREF_D = 1; +#endif + +double vmaxd (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_max (va, vb), PREF_D); +} + +double vmind (double a, double b) +{ + vector double va = vec_promote (a, PREF_D); + vector double vb = vec_promote (b, PREF_D); + return vec_extract (vec_min (va, vb), PREF_D); +} + +#ifdef _BIG_ENDIAN + const int PREF_F = 0; +#else + const int PREF_F = 3; +#endif + +float vmaxf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_max (va, vb), PREF_F); +} + +float vminf (float a, float b) +{ + vector float va = vec_promote (a, PREF_F); + vector float vb = vec_promote (b, PREF_F); + return vec_extract (vec_min (va, vb), PREF_F); +}