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 0A45B3858D34 for ; Thu, 26 Aug 2021 01:19:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A45B3858D34 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17Q17n72028222; Wed, 25 Aug 2021 21:19:41 -0400 Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com with ESMTP id 3anyk21x1g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 25 Aug 2021 21:19:41 -0400 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17Q1GheE001098; Thu, 26 Aug 2021 01:19:39 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma02fra.de.ibm.com with ESMTP id 3ajs48ey0m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 26 Aug 2021 01:19:39 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17Q1JZVj37028278 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 26 Aug 2021 01:19:35 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D2CAAE057; Thu, 26 Aug 2021 01:19:35 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5A7DAAE045; Thu, 26 Aug 2021 01:19:33 +0000 (GMT) Received: from [9.200.48.209] (unknown [9.200.48.209]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 26 Aug 2021 01:19:33 +0000 (GMT) Subject: Re: [PATCH, rs6000] Disable gimple fold for float or double vec_minmax when fast-math is not set To: wschmidt@linux.ibm.com, Segher Boessenkool Cc: gcc-patches , guihaoc@cn.ibm.com References: <5c3e57e6-9718-c4ab-ceaf-fcd23d48a598@linux.ibm.com> <27365670-044d-22ae-519b-a7cfa1480388@linux.ibm.com> <20210824224044.GO1583@gate.crashing.org> <42a92224-1599-4a3f-2473-98b02483a714@linux.ibm.com> From: HAO CHEN GUI Message-ID: <83076432-76a0-0a3a-0a19-2fb19b28589d@linux.ibm.com> Date: Thu, 26 Aug 2021 09:19:30 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.13.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 35ZTpMaWucpMvgbtiABpeRKedT6Gp6t_ X-Proofpoint-GUID: 35ZTpMaWucpMvgbtiABpeRKedT6Gp6t_ X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-08-25_09:2021-08-25, 2021-08-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 spamscore=0 phishscore=0 clxscore=1015 mlxscore=0 malwarescore=0 suspectscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108260005 X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 26 Aug 2021 01:19:53 -0000 Hi Bill,    Thanks for your comments. Hi Segher,    Here is the ChangeLog and patch diff. Thanks. 2021-08-25 Haochen Gui gcc/     * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin):     Modify the VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP,     VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP expansions. 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 b4e13af4dc6..90527734ceb 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -12159,6 +12159,11 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)        return true;      /* flavors of vec_min.  */      case VSX_BUILTIN_XVMINDP: +    case ALTIVEC_BUILTIN_VMINFP: +      if (!flag_finite_math_only || flag_signed_zeros) +    return false; +      /* Fall through to MIN_EXPR.  */ +      gcc_fallthrough ();      case P8V_BUILTIN_VMINSD:      case P8V_BUILTIN_VMINUD:      case ALTIVEC_BUILTIN_VMINSB: @@ -12167,7 +12172,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); @@ -12177,6 +12181,11 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)        return true;      /* flavors of vec_max.  */      case VSX_BUILTIN_XVMAXDP: +    case ALTIVEC_BUILTIN_VMAXFP: +      if (!flag_finite_math_only || flag_signed_zeros) +    return false; +      /* Fall through to MAX_EXPR.  */ +      gcc_fallthrough ();      case P8V_BUILTIN_VMAXSD:      case P8V_BUILTIN_VMAXUD:      case ALTIVEC_BUILTIN_VMAXSB: @@ -12185,7 +12194,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..547798fd65c --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c @@ -0,0 +1,53 @@ +/* { dg-do compile { target { powerpc*-*-* } } } */ +/* { 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 + +#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..4c6f4365830 --- /dev/null +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c @@ -0,0 +1,51 @@ +/* { dg-do compile { target { powerpc*-*-* } } } */ +/* { 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 + +#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 25/8/2021 下午 8:34, Bill Schmidt wrote: > Hi Haochen, > > Thanks for the updates!  This looks good to me; please await Segher's > response. > > Bill > > On 8/25/21 2:06 AM, HAO CHEN GUI wrote: >> Hi, >> >>       I refined the patch according to Bill's advice. I pasted the >> ChangeLog and diff file here. If it doesn't work, please let me know. >> Thanks. >> >> 2021-08-25 Haochen Gui >> >> gcc/ >>       * config/rs6000/rs6000-call.c (rs6000_gimple_fold_builtin): >>       Modify the VSX_BUILTIN_XVMINDP, ALTIVEC_BUILTIN_VMINFP, >>       VSX_BUILTIN_XVMAXDP, ALTIVEC_BUILTIN_VMAXFP expansions. >> >> 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 b4e13af4dc6..90527734ceb 100644 >> --- a/gcc/config/rs6000/rs6000-call.c >> +++ b/gcc/config/rs6000/rs6000-call.c >> @@ -12159,6 +12159,11 @@ rs6000_gimple_fold_builtin >> (gimple_stmt_iterator *gsi) >>          return true; >>        /* flavors of vec_min.  */ >>        case VSX_BUILTIN_XVMINDP: >> +    case ALTIVEC_BUILTIN_VMINFP: >> +      if (!flag_finite_math_only || flag_signed_zeros) >> +    return false; >> +      /* Fall through to MIN_EXPR.  */ >> +      gcc_fallthrough (); >>        case P8V_BUILTIN_VMINSD: >>        case P8V_BUILTIN_VMINUD: >>        case ALTIVEC_BUILTIN_VMINSB: >> @@ -12167,7 +12172,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); >> @@ -12177,6 +12181,11 @@ rs6000_gimple_fold_builtin >> (gimple_stmt_iterator *gsi) >>          return true; >>        /* flavors of vec_max.  */ >>        case VSX_BUILTIN_XVMAXDP: >> +    case ALTIVEC_BUILTIN_VMAXFP: >> +      if (!flag_finite_math_only || flag_signed_zeros) >> +    return false; >> +      /* Fall through to MAX_EXPR.  */ >> +      gcc_fallthrough (); >>        case P8V_BUILTIN_VMAXSD: >>        case P8V_BUILTIN_VMAXUD: >>        case ALTIVEC_BUILTIN_VMAXSB: >> @@ -12185,7 +12194,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..da92f059aea >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-1.c >> @@ -0,0 +1,53 @@ >> +/* { dg-do compile { target { powerpc64le-*-* } } } */ >> +/* { 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 >> + >> +#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..d318b933181 >> --- /dev/null >> +++ b/gcc/testsuite/gcc.target/powerpc/vec-minmax-2.c >> @@ -0,0 +1,51 @@ >> +/* { dg-do compile { target { powerpc64le-*-* } } } */ >> +/* { 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 >> + >> +#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 25/8/2021 上午 6:40, Segher Boessenkool wrote: >>> Hi! >>> >>> On Tue, Aug 24, 2021 at 03:04:26PM -0500, Bill Schmidt wrote: >>>> On 8/24/21 3:52 AM, HAO CHEN GUI wrote: >>>> Thanks for this patch!  In the future, if you can put your >>>> ChangeLog and >>>> patch inline in your post, it makes it easier to review. (Otherwise we >>>> have to manually copy it into our response and manipulate it to look >>>> quoted, etc.) >>> It is encoded even, making it impossible to easily apply the patch, >>> etc. >>> >>>>> diff --git a/gcc/config/rs6000/rs6000-call.c >>>>> b/gcc/config/rs6000/rs6000-call.c index b4e13af4dc6..90527734ceb >>>>> 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ >>>>> b/gcc/config/rs6000/rs6000-call.c @@ -12159,6 +12159,11 @@ >>>>> rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi) return >>>>> true; /* >>>>> flavors of vec_min. */ case VSX_BUILTIN_XVMINDP: + case >>> format=flawed :-( >>> >>> >>> Segher