From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by sourceware.org (Postfix) with ESMTPS id 4F6A53833013 for ; Wed, 11 Aug 2021 06:36:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4F6A53833013 Received: by mail-qt1-x82c.google.com with SMTP id d2so1255625qto.6 for ; Tue, 10 Aug 2021 23:36:48 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=cK3v9o6noPkvqsw+Urjf2n5kdUV4Et7oI9GTHmmPDoI=; b=MQT7jv97cShWIKu1SXiqwZwHbDwSY3PEYRmRT6A4oVQO8BVulKgt/iV3EJvmFDYXfo Rly3OwUttHh43UiLJf2qkx8kaqsCVHikeeUad9n/Psm19yFFvL6ZN5nZMU6YTu8a7NqQ F3I4Idu8bI+RYoGoogpAErgSeDgmKn2l/ug5pdFeBnIaoxP0Bk8x744i3vaeelcrbgrp mFyln5TV+uaq7tiB3qwMw4It6kokx4bvr/mE4dW3bVWUddGNAAdJkmSPo76SoYmCtzqZ dt648aiAMnrMu9ZBeYcHqwua/TDrNMiSkX1M56B0WgDKVKk/DvlxG0ehxGr+7orXRq5N ToYA== X-Gm-Message-State: AOAM532bLv5iMWCCOcN9WHeDaKVFF3Aw8amy3ScFMkFavkhyDig6i1M1 7GCP0AymNUC9krhDXHlLJ0BtignvKzc3ZEY58s0= X-Google-Smtp-Source: ABdhPJwXrexMwQtuaCD+UVHF7By1mk7CjQJJSdSm9kzOicg9kuhUlf9g9XiUydSdRskFyq1QXfgGuGBSbtzv8ns/TcQ= X-Received: by 2002:ac8:1249:: with SMTP id g9mr28333914qtj.292.1628663807766; Tue, 10 Aug 2021 23:36:47 -0700 (PDT) MIME-Version: 1.0 References: <20210810121315.3409758-1-hongtao.liu@intel.com> In-Reply-To: <20210810121315.3409758-1-hongtao.liu@intel.com> From: Uros Bizjak Date: Wed, 11 Aug 2021 08:36:36 +0200 Message-ID: Subject: Re: [PATCH] Extend ldexp{s, d}f3 to vscalefs{s, d} when TARGET_AVX512F and TARGET_SSE_MATH. To: liuhongt Cc: "gcc-patches@gcc.gnu.org" , Hongtao Liu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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: Wed, 11 Aug 2021 06:36:58 -0000 On Tue, Aug 10, 2021 at 2:13 PM liuhongt wrote: > > Hi: > AVX512F supported vscalefs{s,d} which is the same as ldexp except the second operand should be floating point. > Bootstrapped and regtested on x86_64-linux-gnu{-m32,}. > > gcc/ChangeLog: > > PR target/98309 > * config/i386/i386.md (ldexp3): Extend to vscalefs[sd] > when TARGET_AVX512F and TARGET_SSE_MATH. > > gcc/testsuite/ChangeLog: > > PR target/98309 > * gcc.target/i386/pr98309-1.c: New test. > * gcc.target/i386/pr98309-2.c: New test. OK. Thanks, Uros. > --- > gcc/config/i386/i386.md | 34 +++++++++++++++----- > gcc/testsuite/gcc.target/i386/pr98309-1.c | 18 +++++++++++ > gcc/testsuite/gcc.target/i386/pr98309-2.c | 39 +++++++++++++++++++++++ > 3 files changed, 83 insertions(+), 8 deletions(-) > create mode 100644 gcc/testsuite/gcc.target/i386/pr98309-1.c > create mode 100644 gcc/testsuite/gcc.target/i386/pr98309-2.c > > diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md > index bc1c30b77f4..56b09c566ed 100644 > --- a/gcc/config/i386/i386.md > +++ b/gcc/config/i386/i386.md > @@ -17914,17 +17914,35 @@ (define_expand "ldexp3" > [(use (match_operand:MODEF 0 "register_operand")) > (use (match_operand:MODEF 1 "general_operand")) > (use (match_operand:SI 2 "register_operand"))] > - "TARGET_USE_FANCY_MATH_387 > - && (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) > - || TARGET_MIX_SSE_I387) > + "((TARGET_USE_FANCY_MATH_387 > + && (!(SSE_FLOAT_MODE_P (mode) && TARGET_SSE_MATH) > + || TARGET_MIX_SSE_I387)) > + || (TARGET_AVX512F && TARGET_SSE_MATH)) > && flag_unsafe_math_optimizations" > { > - rtx op0 = gen_reg_rtx (XFmode); > - rtx op1 = gen_reg_rtx (XFmode); > + /* Prefer avx512f version. */ > + if (TARGET_AVX512F && TARGET_SSE_MATH) > + { > + rtx op2 = gen_reg_rtx (mode); > + emit_insn (gen_floatsi2 (op2, operands[2])); > + operands[0] = lowpart_subreg (mode, operands[0], mode); > + if (MEM_P (operands[1])) > + operands[1] = force_reg (mode, operands[1]); > + operands[1] = lowpart_subreg (mode, operands[1], mode); > + op2 = lowpart_subreg (mode, op2, mode); > + emit_insn (gen_avx512f_vmscalef (operands[0], > + operands[1], > + op2)); > + } > + else > + { > + rtx op0 = gen_reg_rtx (XFmode); > + rtx op1 = gen_reg_rtx (XFmode); > > - emit_insn (gen_extendxf2 (op1, operands[1])); > - emit_insn (gen_ldexpxf3 (op0, op1, operands[2])); > - emit_insn (gen_truncxf2 (operands[0], op0)); > + emit_insn (gen_extendxf2 (op1, operands[1])); > + emit_insn (gen_ldexpxf3 (op0, op1, operands[2])); > + emit_insn (gen_truncxf2 (operands[0], op0)); > + } > DONE; > }) > > diff --git a/gcc/testsuite/gcc.target/i386/pr98309-1.c b/gcc/testsuite/gcc.target/i386/pr98309-1.c > new file mode 100644 > index 00000000000..3a7afb58971 > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr98309-1.c > @@ -0,0 +1,18 @@ > +/* { dg-do compile } */ > +/* { dg-options "-mavx512f -O2 -mfpmath=sse -ffast-math" } */ > +/* { dg-final { scan-assembler-times "vcvtsi2s\[sd\]" "2" } } */ > +/* { dg-final { scan-assembler-times "vscalefs\[sd\]" "2" } } */ > + > +double > +__attribute__((noipa)) > +foo (double a, int b) > +{ > + return __builtin_ldexp (a, b); > +} > + > +float > +__attribute__((noipa)) > +foo2 (float a, int b) > +{ > + return __builtin_ldexpf (a, b); > +} > diff --git a/gcc/testsuite/gcc.target/i386/pr98309-2.c b/gcc/testsuite/gcc.target/i386/pr98309-2.c > new file mode 100644 > index 00000000000..ecfb9168b7d > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr98309-2.c > @@ -0,0 +1,39 @@ > +/* { dg-do run } */ > +/* { dg-options "-mavx512f -O2 -mfpmath=sse -ffast-math" } */ > +/* { dg-require-effective-target avx512f } */ > + > +#define AVX512F > +#ifndef CHECK > +#define CHECK "avx512f-helper.h" > +#endif > + > +#include CHECK > + > +#include "pr98309-1.c" > + > +double > +__attribute__((noipa, target("fpmath=387"))) > +foo_i387 (double a, int b) > +{ > + return __builtin_ldexp (a, b); > +} > + > +float > +__attribute__((noipa, target("fpmath=387"))) > +foo2_i387 (float a, int b) > +{ > + return __builtin_ldexpf (a, b); > +} > + > +static void > +test_512 (void) > +{ > + float fa = 14.5; > + double da = 44.5; > + int fb = 12; > + int db = 8; > + if (foo_i387 (da, db) != foo (da, db)) > + abort (); > + if (foo2_i387 (fa, fb) != foo2 (fa, fb)) > + abort (); > +} > -- > 2.27.0 >