From patchwork Thu Nov 3 17:47:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kwok Cheung Yeung X-Patchwork-Id: 15039 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp676575wru; Thu, 3 Nov 2022 10:48:23 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WdNLF2BvVjmAVNSe1UguJAraJT+xMYPUPXX4Jr2BH4Und5kreaeN777KyYaaNE2FeMnio X-Received: by 2002:a17:907:d093:b0:7ae:108:9728 with SMTP id vc19-20020a170907d09300b007ae01089728mr10216376ejc.484.1667497703118; Thu, 03 Nov 2022 10:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667497703; cv=none; d=google.com; s=arc-20160816; b=B6O1QixLAvFWcS5WDhG7zHzO9edFeWnhp8kQlYnmXuUiKpMSCDhikeru6FEnb5Ydec 9mo3hJFi+xJ2DVfnRNjESS8rt5SkrMMvy8c1DnrbOBW8+r6Rj+XRM3Y/IATSK3aUH69A 2KeulRZ3OgQNYVmR3++i8lpnSWff/kQ09zpyi0+LDtfbg+YilN5+Dcy5ZM7jARaMwHWe gLgTeTKx2daFhnkB9WI7yFeCb66lBr5frnGSAGlKRpu3Or0uGQ1ZAUdhVWgLukZR6rUP SBuWKZpNbvzTMr3D3qZAHy9xZQhXZT+8scVrjqgie+NUSrtcm5503CVVoDmRgoapYqDf QXzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:to:subject:from:user-agent :mime-version:date:message-id:ironport-sdr:dmarc-filter:delivered-to; bh=V0MVsZNx6wx0bkTf6GNgJknGWLx0IfhZPNuo58jHK3Y=; b=f3veuUlng/utTeaxlzJFS0TaBuN5qukxCRaUtZMzLE5F6P20vjPnpVQz4WqFsYj+ki JP/EJS+bfVzn3063Lh77pXZmBQi1CwQmv9Y1mj06UEYUESDOUcZPSKt/p7NIWFskERAS BSJwmicyjFRCZGb51ZbkrIZAkg7wnDJA/yGvway26qY7kgmi1JIpIRsi7yELlCLiEjC9 JdXp6lMujyUATnXeOlls2NjeusppESKtuAcUtSKySZ20luAgwWLfZ1qRwdD4dRkOwOPF wWDCW3agCbWIjDSX+ozr11qvqcK0wyBuUKrYoNKOq3E6v6yUzhaLdQ6vr0uocCU0Iigo eZFw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id l14-20020a170906794e00b007ad8218ad7fsi2486399ejo.379.2022.11.03.10.48.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 10:48:23 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C162C3858298 for ; Thu, 3 Nov 2022 17:48:17 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id DE1BD3858D38 for ; Thu, 3 Nov 2022 17:47:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DE1BD3858D38 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.96,134,1665475200"; d="scan'208,223";a="88910269" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 03 Nov 2022 09:47:47 -0800 IronPort-SDR: uhlhnNRLsK2c+N1p5i6jhMCi8g/04yvN6oKYg1+bb3nzK+aJuHc6TuYb5MJM6EsUX6UikLSxCe lNbjSJDcyCkgvlrxp0T87NQeGC2QmMhuAjhq7GeY9XoC2ojO+iMgWOPP0cTpQRKIdFHLLSrA/0 7h20xZ+0ebUlPWj6+hS3pvHYNbk1pxrkXX8tMzyVJu4TJXunFQQUCbZwZ+SPepzu4/lqkqg/zM uLXprcsIcJ7c3z8WTMxXVm8hZWE2V7osE+uttRDcoejkl6TmAi2zxBWckFUl4JjaNIDDb6E//E MXY= Message-ID: Date: Thu, 3 Nov 2022 17:47:35 +0000 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.4.1 From: Kwok Cheung Yeung Subject: [PATCH] amdgcn: Fix instruction generation for exp2 and log2 operations To: gcc-patches , Andrew Stubbs X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, KAM_SHORT, SPF_HELO_PASS, SPF_PASS, TXREP 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: , 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?1748498071763295418?= X-GMAIL-MSGID: =?utf-8?q?1748498071763295418?= Hello This patch fixes a bug introduced in a previous patch adding support for generating native instructions for the exp2 and log2 patterns. The problem is that the name of the instruction implementing the exp2 operation is v_exp (and not v_exp2), and similarly log2 is implemented by v_log, so we cannot use the RTL name of the operation when outputting the instruction. I've added an extra iterator for the GCN operation name and used that when outputting instructions instead. I have also added an extra testcase for GCN that exercises this case. Okay for trunk? Thanks Kwok From c0e74e01743cd3a3e0dcb2a071396e3a5751ff4c Mon Sep 17 00:00:00 2001 From: Kwok Cheung Yeung Date: Thu, 3 Nov 2022 17:19:11 +0000 Subject: [PATCH] amdgcn: Fix instruction generation for exp2 and log2 operations The GCN instructions for the exp2 and log2 operations are v_exp_* and v_log_* respectively, which unfortunately do not line up with the RTL naming convention. To deal with this, a new set of int attributes is now used when generating the assembly for these instructions. 2022-11-03 Kwok Cheung Yeung gcc/ * config/gcn/gcn-valu.md (math_unop_insn): New attribute. (2, 2, 2, 2, *2_insn, *2_insn): Use math_unop_insn to generate assembler output. gcc/testsuite/ * gcc.target/gcn/unsafe-math-1.c: New. --- gcc/config/gcn/gcn-valu.md | 20 ++++++++++++++------ gcc/testsuite/gcc.target/gcn/unsafe-math-1.c | 10 ++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/gcn/unsafe-math-1.c -- 2.25.1 diff --git a/gcc/config/gcn/gcn-valu.md b/gcc/config/gcn/gcn-valu.md index 3b619512e13..9f4353831bd 100644 --- a/gcc/config/gcn/gcn-valu.md +++ b/gcc/config/gcn/gcn-valu.md @@ -2549,13 +2549,21 @@ (UNSPEC_SIN "sin") (UNSPEC_COS "cos")]) +(define_int_attr math_unop_insn + [(UNSPEC_FLOOR "floor") + (UNSPEC_CEIL "ceil") + (UNSPEC_EXP2 "exp") + (UNSPEC_LOG2 "log") + (UNSPEC_SIN "sin") + (UNSPEC_COS "cos")]) + (define_insn "2" [(set (match_operand:FP 0 "register_operand" "= v") (unspec:FP [(match_operand:FP 1 "gcn_alu_operand" "vSvB")] MATH_UNOP_1OR2REG))] "" - "v_%i0\t%0, %1" + "v_%i0\t%0, %1" [(set_attr "type" "vop1") (set_attr "length" "8")]) @@ -2565,7 +2573,7 @@ [(match_operand:V_FP 1 "gcn_alu_operand" "vSvB")] MATH_UNOP_1OR2REG))] "" - "v_%i0\t%0, %1" + "v_%i0\t%0, %1" [(set_attr "type" "vop1") (set_attr "length" "8")]) @@ -2575,7 +2583,7 @@ [(match_operand:FP_1REG 1 "gcn_alu_operand" "vSvB")] MATH_UNOP_1REG))] "flag_unsafe_math_optimizations" - "v_%i0\t%0, %1" + "v_%i0\t%0, %1" [(set_attr "type" "vop1") (set_attr "length" "8")]) @@ -2585,7 +2593,7 @@ [(match_operand:V_FP_1REG 1 "gcn_alu_operand" "vSvB")] MATH_UNOP_1REG))] "flag_unsafe_math_optimizations" - "v_%i0\t%0, %1" + "v_%i0\t%0, %1" [(set_attr "type" "vop1") (set_attr "length" "8")]) @@ -2595,7 +2603,7 @@ [(match_operand:FP_1REG 1 "gcn_alu_operand" "vSvB")] MATH_UNOP_TRIG))] "flag_unsafe_math_optimizations" - "v_%i0\t%0, %1" + "v_%i0\t%0, %1" [(set_attr "type" "vop1") (set_attr "length" "8")]) @@ -2605,7 +2613,7 @@ [(match_operand:V_FP_1REG 1 "gcn_alu_operand" "vSvB")] MATH_UNOP_TRIG))] "flag_unsafe_math_optimizations" - "v_%i0\t%0, %1" + "v_%i0\t%0, %1" [(set_attr "type" "vop1") (set_attr "length" "8")]) diff --git a/gcc/testsuite/gcc.target/gcn/unsafe-math-1.c b/gcc/testsuite/gcc.target/gcn/unsafe-math-1.c new file mode 100644 index 00000000000..2b54fa232e9 --- /dev/null +++ b/gcc/testsuite/gcc.target/gcn/unsafe-math-1.c @@ -0,0 +1,10 @@ +/* { dg-do link } */ +/* { dg-options "-O0 -ffast-math" } */ + +int main (void) +{ + float x = 0.123456f; + + float r1 = __builtin_exp2f (x); + float r2 = __builtin_log2f (x); +}