From patchwork Thu Aug 25 09:39:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 752 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp155956wro; Thu, 25 Aug 2022 02:40:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR65Gy4GsFdvrQ80xRD935NQ7H/a5/jQtVi2bnXZDPpytxw7d6NHeaEbZy7werMWbpUBqFXc X-Received: by 2002:a05:6402:3408:b0:43c:2dd3:d86b with SMTP id k8-20020a056402340800b0043c2dd3d86bmr2496280edc.108.1661420445493; Thu, 25 Aug 2022 02:40:45 -0700 (PDT) Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id 3-20020a508e43000000b0043a9bb390d3si5554688edx.278.2022.08.25.02.40.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Aug 2022 02:40:45 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=FOwDoK0y; arc=fail (signature failed); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A3573385F026 for ; Thu, 25 Aug 2022 09:40:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3573385F026 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661420443; bh=orm39klZksLQ8lBEW7tZ9lYwzGTdi8CqdJjLOootOYg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=FOwDoK0yYAP5QgANNLso6/OiA+JXn4SS7Pgay/WSoRC+/y56R5Pimb7fc1VgmT67Q qIvLmEwtmcoTS23vrZTl5+8KXZGe7avTZVknBPfNi5L5qcICqpgEZ1QmPowpVF9AJu wA9ndM8EudbzRF77oUpyQMMLp5pZkfaNsm/Ae2bM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by sourceware.org (Postfix) with ESMTPS id B942E3858C2F for ; Thu, 25 Aug 2022 09:39:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B942E3858C2F X-IronPort-AV: E=McAfee;i="6500,9779,10449"; a="355921028" X-IronPort-AV: E=Sophos;i="5.93,262,1654585200"; d="scan'208";a="355921028" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Aug 2022 02:39:56 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.93,262,1654585200"; d="scan'208";a="613115850" Received: from orsmsx602.amr.corp.intel.com ([10.22.229.15]) by fmsmga007.fm.intel.com with ESMTP; 25 Aug 2022 02:39:55 -0700 Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) by ORSMSX602.amr.corp.intel.com (10.22.229.15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 25 Aug 2022 02:39:54 -0700 Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Thu, 25 Aug 2022 02:39:54 -0700 Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31 via Frontend Transport; Thu, 25 Aug 2022 02:39:54 -0700 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (104.47.58.169) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2375.31; Thu, 25 Aug 2022 02:39:53 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Icx0dy2vxdIx2+I9QilFkrAzROVHAt8kqWkARpjh9jbDNr+jjx555roN6eu0+P5H18Ow6df4OT8FLNWWBoNQjElMVWF8ARkUFAxB80TH3Od9nZ0hkvRPUav5n8Fjna5tyrMwdFiHsbhDCBM/WsWzthNLw9I4DADj5IVUjwkZIoHxFrBSPV7VHKCDq1q5j5lENCxg7eBBk9eCDQKMZlRRtheTrAjU0ap/eFt6cqaF92rhv6RmbOT1juvt1blenbXXOR6RO+YCp7nmwB1MTz5whFsYyDdEMHzgNMGyrDu9GOjBIWlLLJq5mhC7T+3teaioKBQ/UGKbRf/beyYJAh5VrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=orm39klZksLQ8lBEW7tZ9lYwzGTdi8CqdJjLOootOYg=; b=IYZeV1PPtMtZAqWVjUf8yoHt+4IR56UorouBei+zHhkWZzr/kn7SAf8uczjTFy4qXv+sm2H2jkyTRl+ZaOXg+xsnqMWd67aEDb239vAfmNaRJG6X1yTXjm04dI4knRxL3qfK9wCivsVGhSHOZBMlxpHI0z7bo+/yacJ6MVgrQDFXnQKbZ9ic8UEX00eYQ2zwBGXA36I6oCSrVhbt8lSQnfd5i9rDYricPGxEqoJmuHq40E3i9VW/io4oy3pinjUk/2CLAiPrqdUCuKkgVM4nzwDwysznj9UUXvlsY4Ge+W2vZlPegOEUnU7PqqvGPnpebnRlr58/BRvRNqFNFL18Hg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Received: from DM4PR11MB5487.namprd11.prod.outlook.com (2603:10b6:5:39f::22) by DM5PR11MB1402.namprd11.prod.outlook.com (2603:10b6:3:7::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.15; Thu, 25 Aug 2022 09:39:50 +0000 Received: from DM4PR11MB5487.namprd11.prod.outlook.com ([fe80::1cf5:eb50:5eb:a1c3]) by DM4PR11MB5487.namprd11.prod.outlook.com ([fe80::1cf5:eb50:5eb:a1c3%9]) with mapi id 15.20.5566.015; Thu, 25 Aug 2022 09:39:50 +0000 To: "Liu, Hongtao" , "gcc-patches@gcc.gnu.org" , "richard.guenther@gmail.com" Subject: [PATCH] middle-end: Add MULT_EXPR recognition for cond scalar reduction Thread-Topic: [PATCH] middle-end: Add MULT_EXPR recognition for cond scalar reduction Thread-Index: Adi4YxhQXB9/tGQkQ5q+lSGDNyDMBg== Date: Thu, 25 Aug 2022 09:39:50 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 11.6.500.17 dlp-reaction: no-action x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0c67f8e9-75f3-4db6-18f1-08da867dc1c3 x-ms-traffictypediagnostic: DM5PR11MB1402:EE_ x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: BZmHTofcRHrnbjlSMETzow8H5mFBqpND1A4SUD4k0tcBH0VODFlK+aaJMeDc3nUX3+6b9xFYEpzOCUycjpavXiKz/RHRhCV3RwHmGczyDE5vnndGTBcdZprdHmPmsYFM8pUTYSqv7/GTk1gbcBkYbEcRjGDs5T/axcLbIRXEp6TEQtFqEISc2dV6I/f1Z5BzJutCGTQxHaqx9HoxJ/qOeiBxN5cYtgU9/GD9KZb+ByG9Dcm8DosVm6KYujKfMm3I/6CcIYSrUQcaQ4pNnKcGmS1Yd1br8hdE2uCKTit31t1q+Btx9IHWdqF249wYVs8uOBi4oZtpYffMU2MRFRElPLkj7R4PgOkzbJchwVhhbLjOxhUp6KfDY1ZIlMikBQjPrcaYjcVOZtkeNbmjqEEYEiND3qr48n6x0iWGJk/WOwnVyBnPf8iLUK4iTSvy+j+bARCLmBot4ogi0tZMlQs7hnXw1gIcl6bHPKxbZuvDpn6Jwg78CXbL0CGSX/aphAh98+m4RaxLLiF+RpkzmHO3e/aPEph6kCyVnfjHy7QClg+3TurQ7WBmMUG7A7QsKUpN4c7kq9i1pff3RuaET650BwNTdztLR1Nqqz34V3zfYThPRcy47DmFoLOm8N/hWvZ0IiEAOBFzguYXRZc9cln5/am6qTQRm/+JdWwp064snCrPCbrg+aejrFBo6qgEBN0mD0eDa+aO/dfmp9uw52Ad82gjKjflz4ZmNUlK7tuJDVAWtscX60hp5dViZ3tU7UjmR3WlwimcNQeXdwe/Ux018QFZAmeKUI8DKlDjl5CnwAE= x-forefront-antispam-report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DM4PR11MB5487.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230016)(376002)(366004)(396003)(39860400002)(346002)(136003)(82960400001)(38070700005)(86362001)(316002)(26005)(9686003)(478600001)(84970400001)(186003)(110136005)(55016003)(71200400001)(38100700002)(122000001)(76116006)(66946007)(66556008)(66446008)(64756008)(66476007)(4326008)(8676002)(8936002)(107886003)(5660300002)(6506007)(7696005)(41300700001)(33656002)(52536014)(2906002); DIR:OUT; SFP:1102; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: zwgjzebgDi8RZVuzqmkh1SfSwOghtNDOzWeGhM4DviNmcNx4z7PNIhGSsI7VNr4ue7RFLhJw8w1BOTnL5YWc7Qcuk8FDsUxKd2JxYGUI7IvChx7yujfT/wEQH6Qekhsq1Sscy7gr7UOEBze05VvTY0vZJdIabcrAphQ/nSfmft9derEYjyAXF7JGZ6QizGWwJMdoSw9XR3/U02lZ4h53tzphSJbunfttmCSaZN1cj9wT1VaT5IceR70jubpBIDbZN2JnatFEAGXeuReOL4QjXH9Si0iTVhYB+NUUaOZt9UbAbSI43tUG8QvxfhebXT70ohRV5d22a5Eq9EmmxrYAZTA8rvusi6lQH1zXD06bzhego8AE/+dwET68g6VViq4RxShfiaitQxykw8PVCDmGt2UbTvTwpqn8HiNZfJJwFRUtRg3HBRVZkPysmA23ghPXj2Lb1h6b26tmIPRL7g2CNyaPHr3rgDgc7izH2HOZtwS6/xV92JAGcTkr5u4Pn/7r9Flxg3CjcaDhGYCyruAyQsVl7sHhZmcmNPsbtwV9LTRQbe9r569JaT/gMZyp3KuOCL429fdkCHgeODmIYrYsY4ajkTnHnr+TxZsCW6xl1e2gdnXQwRIhzIREpnR0LBTemn3Mhjhz+9PvArRy9q+MYBIKTLpR89dOJ9Gc0n4KSdRxb2yPwWpyzMj2Xqzh7jqUtgzHLdsBc0DPpVdUw17th12rbw/HQy0fuvrpO1/6LhHUftTHe72U4S+hBjaLFbrWNSMWm9yMsmOqs8o9I56z2WhPXPuLiKbj7tTZN0IXPp+GfJKF9jNqGFkv15fSw0LYIfiHFXvqPk9CF31HeDYbpAEl/lgcpPS1Ue+pZQMm/88Ts2zkL0vuTuvzgVHqOqgZ7nVQ/hdbjVVaPrv9BtjEkRHR/BQoEcjidLOtpSMOnjUciT3egTKdc5kQ7w7CmxIQzHui1ez3nJracwzUeySOX+s7uY/KDcTW7ZewnM35K9VM+4BlTHGK4ACzJpqjE2chvmtXE4fKeFnIOZbcjT5BGauzfOuCL1FCY7tpDUjGDEo2nZiDsM8ypm+S+TSYwC2V4tF8anQ9THG397YGIu2ttCP4KFWBzHnxrs7MJhN0orK+rRVaa2BDWZ+scwqjSNIvGT/8t0YUIaLeGL8A8yFPFOwqlzUoNgpXp1klEWMEt6mQ5eI4x2hF9favser5LH93q+x17woVmJtJVvwHm6MXUPKukBYxzxwmlsuBRRzfdmk8oTnP4bJzZlpm+TMAPHAXITLlETpHtxb/rAgThiQ2NYJEc2PfEBhJAVLWpUQRl/0X7GByZvoQq0wMc9rgB1XRLb20Z+aO4aGi6LdhDqwg5E5C+laENlkk4BUYH49NTLdG9Dmba2LDz39fsDEY9Mhc5iKJSY4q4U9aETAdYdaz3NWNwSB5hfKOX5o//1lF953SDjNIY6kJmhFrqBCJV7T/gQJbR8Q+pm15MNXIyIoLJ1dlGPQ9omxD1N2/56ITTl8dfPrSiNZKZxFUljGRxIlZdB0XvNa+W1lphdtDENizTW6CBZ0xpHcbM9yQtafuLSgRvS7T0s2rJ4LDXSe6tEY3 MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM4PR11MB5487.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c67f8e9-75f3-4db6-18f1-08da867dc1c3 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Aug 2022 09:39:50.5857 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: IG/81aAEZQaTU1Wybar3ihr6OCM3nnZ4SOmYXUegvh+Nh7sv31PxXpu9wfKukYsaNCfJfDm+T1hR0jKX1nnGxA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR11MB1402 X-OriginatorOrg: intel.com X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, 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 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: "Kong, Lingling via Gcc-patches" From: "Li, Pan2 via Gcc-patches" Reply-To: "Kong, Lingling" Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742125604825427752?= X-GMAIL-MSGID: =?utf-8?q?1742125604825427752?= Hi, The conditional mult reduction cannot be recognized with current GCC. The following loop cannot be vectorized. Now add MULT_EXPR recognition for conditional scalar reduction. float summa(int n, float *arg1, float *arg2) { int i; float res1 = 1.0; for(i = 0; i < n; i++) { if(arg2[i]) res1 *= arg1[i]; } return res1; } gcc/ChangeLog: * tree-if-conv.cc (is_cond_scalar_reduction): Add MULT_EXPR recognition. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/gen-vect-34.c: New test. * gcc.dg/vect/vect-ifcvt-18.c: New test. --- gcc/testsuite/gcc.dg/tree-ssa/gen-vect-34.c | 16 +++++++++ gcc/testsuite/gcc.dg/vect/vect-ifcvt-18.c | 38 +++++++++++++++++++++ gcc/tree-if-conv.cc | 1 + 3 files changed, 55 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/gen-vect-34.c create mode 100644 gcc/testsuite/gcc.dg/vect/vect-ifcvt-18.c -- 2.18.2 diff --git a/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-34.c b/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-34.c new file mode 100644 index 00000000000..8d2d36401fe --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/gen-vect-34.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-Ofast -fdump-tree-vect-details" } */ +/* { dg-additional-options "-mavx2" { target { x86_64-*-* i?86-*-* } } +} */ + +float summul(int n, float *arg1, float *arg2) +{ + int i; + float res1 = 1.0; + for(i = 0; i < n; i++) { + if(arg2[i]) + res1 *= arg1[i]; + } + return res1; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" { +target { ! { avr-*-* pru-*-* } } } } } */ diff --git a/gcc/testsuite/gcc.dg/vect/vect-ifcvt-18.c b/gcc/testsuite/gcc.dg/vect/vect-ifcvt-18.c new file mode 100644 index 00000000000..c1d3c27d819 --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/vect-ifcvt-18.c @@ -0,0 +1,38 @@ +/* { dg-require-effective-target vect_condition } */ +/* { dg-require-effective-target vect_float } */ +/* { dg-additional-options "-Ofast -mavx" { target avx_runtime } } */ + + +int A0[4] = {36,39,42,45}; +int B0[4] = {42,42,0,42}; +float A1[8] = {36,39,42,45,43,32,21,12}; float B1[8] = +{42,42,0,42,42,42,0,42}; double A2[16] = +{36,39,42,45,43,32,21,12,23,34,45,56,42,78,89,11}; +double B2[16] = {42,42,0,42,42,42,42,42,42,42,42,42,0,42,42,42}; + +int main () +{ + int i, j; + int res0 = 1; + float res1 = 1.0; + double res2 = 1.0; + + for (i = 0; i < 4; i++) + if (B0[i]) + res0 *= A0[i]; + + for (i = 0; i < 8; i++) + if (B1[i]) + res1 *= A1[i]; + + for (i = 0; i < 16; i++) + if (B2[i]) + res2 *= A2[i]; + /* check results: */ + if (res0 != 63180 || res1 != 1043228160.000000 + ||res2 != 3296728515318523101184.000000) + __builtin_abort (); + return 0; +} + +/* { dg-final { scan-tree-dump "vectorized 3 loops" "vect" { target +i?86-*-* x86_64-*-* } } } */ diff --git a/gcc/tree-if-conv.cc b/gcc/tree-if-conv.cc index 1c8e1a45234..bac29fb5574 100644 --- a/gcc/tree-if-conv.cc +++ b/gcc/tree-if-conv.cc @@ -1739,6 +1739,7 @@ is_cond_scalar_reduction (gimple *phi, gimple **reduc, tree arg_0, tree arg_1, if (reduction_op != PLUS_EXPR && reduction_op != MINUS_EXPR + && reduction_op != MULT_EXPR && reduction_op != BIT_IOR_EXPR && reduction_op != BIT_XOR_EXPR && reduction_op != BIT_AND_EXPR)