From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by sourceware.org (Postfix) with ESMTPS id C07703858D35 for ; Fri, 5 Nov 2021 09:52:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C07703858D35 Received: by mail-ed1-x52c.google.com with SMTP id f8so31286926edy.4 for ; Fri, 05 Nov 2021 02:52:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=kkhIKfJ6IkNk5ZikDpY3/DNaExEtRP2pg9BglmopHZs=; b=MxI91foYvx0ZVeyiVcuiY+c8gAsf3bKGBIErYQaRS3mUzy+17GI7F2z98iLYKjHIWA FwXZVs6jgUmDueeDcTn+puiq+JuhFgVZYSeQa2atpWw+3ZGl31bk0PVNgvczZqoJ0NRH IF7NpdQSA7n3e+CaX2zO7ma/ntG1yawIGmHJhKT1f2wkfM34bkwcrCuftct9VzsP5rqQ 8m4JBqPc7q7Q7//sD8tx4kfwKWqB9RSSK5cHLhYmPrlqGqkE6mhRdFiDhH6cpeJvdw0f +6fKIBUly1Ylo11UhkXshYE5J4yqD/lEi1Vmfz8TfoIhTwPyYixfmk+NVYHGoBA5U3rb tG9w== X-Gm-Message-State: AOAM533I3wHQVTPh/hAtjwi8/xivWOzpHWWIn8W2UBCLyYThp1bflKv8 ctSLIfXyferJcHJ9aiz9t7qHgRIw8UTBdKzqLZA= X-Google-Smtp-Source: ABdhPJzCuBQfDYQZy3UixqRsRFRi9FAheOek3b1HndmGDl0Ji1rZ6us9AgR3cYzHItVpkrytotb5zNWeXqhhAn2IBAc= X-Received: by 2002:aa7:c656:: with SMTP id z22mr66616123edr.251.1636105943834; Fri, 05 Nov 2021 02:52:23 -0700 (PDT) MIME-Version: 1.0 References: <20211105053851.24542-1-hongtao.liu@intel.com> In-Reply-To: <20211105053851.24542-1-hongtao.liu@intel.com> From: Richard Biener Date: Fri, 5 Nov 2021 10:52:13 +0100 Message-ID: Subject: Re: [PATCH 1/2] [Gimple] Simplify (trunc)fmax/fmin((extend)a, (extend)b) to MAX/MIN(a,b) To: liuhongt Cc: GCC Patches , Hongtao Liu , "H. J. Lu" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.4 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: Fri, 05 Nov 2021 09:52:26 -0000 On Fri, Nov 5, 2021 at 6:38 AM liuhongt wrote: > > a and b are same type as trunc type and has less precision than > extend type, the transformation is guarded by flag_finite_math_only. > > Bootstrapped and regtested under x86_64-pc-linux-gnu{-m32,} > Ok for trunk? > > gcc/ChangeLog: > > PR target/102464 > * match.pd: Simplify (trunc)fmax/fmin((extend)a, (extend)b) to > MAX/MIN(a,b) > > gcc/testsuite/ChangeLog: > > * gcc.target/i386/pr102464-maxmin.c: New test. > --- > gcc/match.pd | 14 ++++++ > .../gcc.target/i386/pr102464-maxmin.c | 44 +++++++++++++++++++ > 2 files changed, 58 insertions(+) > create mode 100644 gcc/testsuite/gcc.target/i386/pr102464-maxmin.c > > diff --git a/gcc/match.pd b/gcc/match.pd > index f63079023d0..857ce7f712a 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -6182,6 +6182,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > && direct_internal_fn_supported_p (IFN_COPYSIGN, > type, OPTIMIZE_FOR_BOTH)) > (IFN_COPYSIGN @0 @1)))) > + > +(for maxmin (max min) > + (simplify > + (convert (maxmin (convert@2 @0) (convert @1))) > + (if (flag_finite_math_only I suppose you are concerned about infinities, not about NaNs. Please use !HONOR_INFINITIES (@2) then (in general testing flag_* is frowned upon). You may want to do the FLOAT_TYPE_P tests first. > + && optimize > + && FLOAT_TYPE_P (type) > + && FLOAT_TYPE_P (TREE_TYPE (@2)) > + && types_match (type, TREE_TYPE (@0)) > + && types_match (type, TREE_TYPE (@1)) > + && TYPE_PRECISION (type) < TYPE_PRECISION (TREE_TYPE (@2)) > + && optab_handler (maxmin == MAX_EXPR ? smax_optab : smin_optab, > + TYPE_MODE (type)) != CODE_FOR_nothing) > + (maxmin @0 @1)))) > #endif > > (for froms (XFLOORL XCEILL XROUNDL XRINTL) > diff --git a/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c > new file mode 100644 > index 00000000000..37867235a6c > --- /dev/null > +++ b/gcc/testsuite/gcc.target/i386/pr102464-maxmin.c > @@ -0,0 +1,44 @@ > +/* PR target/102464. */ > +/* { dg-do compile } */ > +/* { dg-options "-O2 -mavx512fp16 -mavx512vl -ffast-math -ftree-vectorize -mtune=generic -mfpmath=sse" } */ > +/* { dg-final { scan-assembler-times "vmaxph" 3 } } */ > +/* { dg-final { scan-assembler-times "vminph" 3 } } */ > +/* { dg-final { scan-assembler-times "vmaxsh" 3 } } */ > +/* { dg-final { scan-assembler-times "vminsh" 3 } } */ > +/* { dg-final { scan-assembler-times "vmaxps" 2 } } */ > +/* { dg-final { scan-assembler-times "vminps" 2 } } */ > +/* { dg-final { scan-assembler-times "vmaxss" 2 } } */ > +/* { dg-final { scan-assembler-times "vminss" 2 } } */ > +/* { dg-final { scan-assembler-times "vmaxpd" 1 } } */ > +/* { dg-final { scan-assembler-times "vminpd" 1 } } */ > +/* { dg-final { scan-assembler-times "vmaxsd" 1 } } */ > +/* { dg-final { scan-assembler-times "vminsd" 1 } } */ > + > +#include > +#define FOO(CODE,TYPE,SUFFIX) \ > + void \ > + foo_vect_##CODE##TYPE##SUFFIX (TYPE* __restrict a, TYPE* b, TYPE* c) \ > + { \ > + for (int i = 0; i != 8; i++) \ > + a[i] = CODE##SUFFIX (b[i], c[i]); \ > + } \ > + TYPE \ > + foo_##CODE##TYPE##SUFFIX (TYPE b, TYPE c) \ > + { \ > + return CODE##l (b, c); \ > + } > + > +FOO (fmax, _Float16, f); > +FOO (fmax, _Float16,); > +FOO (fmax, _Float16, l); > +FOO (fmin, _Float16, f); > +FOO (fmin, _Float16,); > +FOO (fmin, _Float16, l); > + > +FOO (fmax, float,); > +FOO (fmax, float, l); > +FOO (fmin, float,); > +FOO (fmin, float, l); > + > +FOO (fmax, double, l); > +FOO (fmin, double, l); > -- > 2.18.1 >