From patchwork Wed Oct 20 09:04:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: HAO CHEN GUI X-Patchwork-Id: 46429 Return-Path: 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 A24D83858036 for ; Wed, 20 Oct 2021 09:05:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A24D83858036 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634720738; bh=ir2lqrOFLJiEQr7g7ztFQsq85u4RoEjyve6yKpBVWUA=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=BbwADmS0UtY3M3jJpy3l78NQtWb+s1OvSs7vbnGQ4ZX+VTEz/LP1RxH76soR8/gpV XTsq0bdosdkwGUSfKWUV2oPgkj2f/oC8NH5eutUDqMIm1f0PKUR2YwjSYUBPQ7hyBK e1vIBzzQulXNRkEPsR58r5322in1u8hkC91B0PFc= 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 81ADE3858419 for ; Wed, 20 Oct 2021 09:05:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 81ADE3858419 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19K8letA008795; Wed, 20 Oct 2021 05:05:07 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3btfwrrb5r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Oct 2021 05:05:07 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 19K8mBEU011907; Wed, 20 Oct 2021 05:05:06 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3btfwrrb4n-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Oct 2021 05:05:06 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 19K91v7f001144; Wed, 20 Oct 2021 09:05:04 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03ams.nl.ibm.com with ESMTP id 3bqpca2msk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 20 Oct 2021 09:05:04 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 19K94xYq43516358 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 20 Oct 2021 09:04:59 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87C8711C052; Wed, 20 Oct 2021 09:04:59 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 234F111C07A; Wed, 20 Oct 2021 09:04:58 +0000 (GMT) Received: from [9.200.100.183] (unknown [9.200.100.183]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 20 Oct 2021 09:04:57 +0000 (GMT) Message-ID: <787f0d5d-a8f5-c513-997f-a5b906951da4@linux.ibm.com> Date: Wed, 20 Oct 2021 17:04:56 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.1.2 Content-Language: en-US To: gcc-patches 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-ORIG-GUID: iJT1aHQP3nR-XLUcncsaJWQSLhqYWMOE X-Proofpoint-GUID: 2M4B4Ua75_OCGer8MHLQLapvZxbWxulO 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-10-20_04,2021-10-19_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 bulkscore=0 phishscore=0 priorityscore=1501 mlxscore=0 clxscore=1015 suspectscore=0 spamscore=0 impostorscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109230001 definitions=main-2110200051 X-Spam-Status: No, score=-1.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, UNWANTED_LANGUAGE_BODY 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-Patchwork-Original-From: HAO CHEN GUI via Gcc-patches From: HAO CHEN GUI Reply-To: HAO CHEN GUI Cc: Bill Schmidt , David , Segher Boessenkool Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi, This patch disables gimple folding for float or double vec_min/max when fast-math is not set. It makes vec_min/max conform with the guide. Bootstrapped and tested on powerpc64le-linux with no regressions. Is this okay for trunk? Any recommendations? Thanks a lot.   I refined the patch according to reviewers' advice. The attachments are the ChangeLog and patch diff in case the email body is messed up. ChangeLog 2021-10-20 Haochen Gui 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-10-20 Haochen Gui 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 b4e13af4dc6..51c7ba447c3 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -12159,6 +12159,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) || HONOR_SIGNED_ZEROS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMINSD: case P8V_BUILTIN_VMINUD: case ALTIVEC_BUILTIN_VMINSB: @@ -12167,7 +12175,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 +12184,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) || HONOR_SIGNED_ZEROS (type)) + return false; + gcc_fallthrough (); + } case P8V_BUILTIN_VMAXSD: case P8V_BUILTIN_VMAXUD: case ALTIVEC_BUILTIN_VMAXSB: @@ -12185,7 +12200,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 + +#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 + +#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/config/rs6000/rs6000-call.c b/gcc/config/rs6000/rs6000-call.c index b4e13af4dc6..51c7ba447c3 100644 --- a/gcc/config/rs6000/rs6000-call.c +++ b/gcc/config/rs6000/rs6000-call.c @@ -12159,6 +12159,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) || HONOR_SIGNED_ZEROS (type)) +         return false; +       gcc_fallthrough (); +      }      case P8V_BUILTIN_VMINSD:      case P8V_BUILTIN_VMINUD:      case ALTIVEC_BUILTIN_VMINSB: @@ -12167,7 +12175,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 +12184,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) || HONOR_SIGNED_ZEROS (type)) +         return false; +       gcc_fallthrough (); +      }      case P8V_BUILTIN_VMAXSD:      case P8V_BUILTIN_VMAXUD:      case ALTIVEC_BUILTIN_VMAXSB: @@ -12185,7 +12200,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 + +#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 + +#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); +}