public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "cvs-commit at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/110762] inappropriate use of SSE (or AVX) insns for v2sf mode operations
Date: Wed, 26 Jul 2023 10:18:38 +0000	[thread overview]
Message-ID: <bug-110762-4-C4fmvT0IE7@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110762-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110762

--- Comment #19 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Uros Bizjak <uros@gcc.gnu.org>:

https://gcc.gnu.org/g:ade30fad6669e5f34ca4c587c724d74ecc953175

commit r14-2786-gade30fad6669e5f34ca4c587c724d74ecc953175
Author: Uros Bizjak <ubizjak@gmail.com>
Date:   Wed Jul 26 11:10:46 2023 +0200

    i386: Clear upper half of XMM register for V2SFmode operations [PR110762]

    Clear the upper half of a V4SFmode operand register in front of all
    potentially trapping instructions. The testcase:

    --cut here--
    typedef float v2sf __attribute__((vector_size(8)));
    typedef float v4sf __attribute__((vector_size(16)));

    v2sf test(v4sf x, v4sf y)
    {
      v2sf x2, y2;

      x2 = __builtin_shufflevector (x, x, 0, 1);
      y2 = __builtin_shufflevector (y, y, 0, 1);

      return x2 + y2;
    }
    --cut here--

    now compiles to:

            movq    %xmm1, %xmm1    # 9     [c=4 l=4]  *vec_concatv4sf_0
            movq    %xmm0, %xmm0    # 10    [c=4 l=4]  *vec_concatv4sf_0
            addps   %xmm1, %xmm0    # 11    [c=12 l=3]  *addv4sf3/0

    This approach addresses issues with exceptions, as well as issues with
    denormal/invalid values. An obvious exception to the rule is a division,
    where the value != 0.0 should be loaded into the upper half of the
    denominator to avoid division by zero exception.

    The patch effectively tightens the solution from PR95046 by clearing upper
    halves of all operand registers before every potentially trapping
instruction.
    The testcase:

    --cut here--
    typedef float __attribute__((vector_size(8))) v2sf;

    v2sf test (v2sf a, v2sf b, v2sf c)
    {
      return a * b - c;
    }
    --cut here--

    compiles to:

            movq    %xmm1, %xmm1    # 8     [c=4 l=4]  *vec_concatv4sf_0
            movq    %xmm0, %xmm0    # 9     [c=4 l=4]  *vec_concatv4sf_0
            movq    %xmm2, %xmm2    # 12    [c=4 l=4]  *vec_concatv4sf_0
            mulps   %xmm1, %xmm0    # 10    [c=16 l=3]  *mulv4sf3/0
            movq    %xmm0, %xmm0    # 13    [c=4 l=4]  *vec_concatv4sf_0
            subps   %xmm2, %xmm0    # 14    [c=12 l=3]  *subv4sf3/0

    The implementation emits V4SFmode operation, so we can remove all
"emulated"
    SSE2 V2SFmode trapping instructions and remove "emulated" SSE2 V2SFmode
    alternatives from 3dNOW! insn patterns.

            PR target/110762

    gcc/ChangeLog:

            * config/i386/i386.md (plusminusmult): New code iterator.
            * config/i386/mmx.md (mmxdoublevecmode): New mode attribute.
            (movq_<mode>_to_sse): New expander.
            (<plusminusmult:insn>v2sf3): Macroize expander from addv2sf3,
            subv2sf3 and mulv2sf3 using plusminusmult code iterator.  Rewrite
            as a wrapper around V4SFmode operation.
            (mmx_addv2sf3): Change operand 1 and operand 2 predicates to
            nonimmediate_operand.
            (*mmx_addv2sf3): Remove SSE alternatives.  Change operand 1 and
            operand 2 predicates to nonimmediate_operand.
            (mmx_subv2sf3): Change operand 2 predicate to nonimmediate_operand.
            (mmx_subrv2sf3): Change operand 1 predicate to
nonimmediate_operand.
            (*mmx_subv2sf3): Remove SSE alternatives.  Change operand 1 and
            operand 2 predicates to nonimmediate_operand.
            (mmx_mulv2sf3): Change operand 1 and operand 2 predicates to
            nonimmediate_operand.
            (*mmx_mulv2sf3): Remove SSE alternatives.  Change operand 1 and
            operand 2 predicates to nonimmediate_operand.
            (divv2sf3): Rewrite as a wrapper around V4SFmode operation.
            (<smaxmin:code>v2sf3): Ditto.
            (mmx_<smaxmin:code>v2sf3): Change operand 1 and operand 2
            predicates to nonimmediate_operand.
            (*mmx_<smaxmin:code>v2sf3): Remove SSE alternatives.  Change
            operand 1 and operand 2 predicates to nonimmediate_operand.
            (mmx_ieee_<ieee_maxmin>v2sf3): Ditto.
            (sqrtv2sf2): Rewrite as a wrapper around V4SFmode operation.
            (*mmx_haddv2sf3_low): Ditto.
            (*mmx_hsubv2sf3_low): Ditto.
            (vec_addsubv2sf3): Ditto.
            (*mmx_maskcmpv2sf3_comm): Remove.
            (*mmx_maskcmpv2sf3): Remove.
            (vec_cmpv2sfv2si): Rewrite as a wrapper around V4SFmode operation.
            (vcond<V2FI:mode>v2sf): Ditto.
            (fmav2sf4): Ditto.
            (fmsv2sf4): Ditto.
            (fnmav2sf4): Ditto.
            (fnmsv2sf4): Ditto.
            (fix_truncv2sfv2si2): Ditto.
            (fixuns_truncv2sfv2si2): Ditto.
            (mmx_fix_truncv2sfv2si2): Remove SSE alternatives.
            Change operand 1 predicate to nonimmediate_operand.
            (floatv2siv2sf2): Rewrite as a wrapper around V4SFmode operation.
            (floatunsv2siv2sf2): Ditto.
            (mmx_floatv2siv2sf2): Remove SSE alternatives.
            Change operand 1 predicate to nonimmediate_operand.
            (nearbyintv2sf2): Rewrite as a wrapper around V4SFmode operation.
            (rintv2sf2): Ditto.
            (lrintv2sfv2si2): Ditto.
            (ceilv2sf2): Ditto.
            (lceilv2sfv2si2): Ditto.
            (floorv2sf2): Ditto.
            (lfloorv2sfv2si2): Ditto.
            (btruncv2sf2): Ditto.
            (roundv2sf2): Ditto.
            (lroundv2sfv2si2): Ditto.
            (*mmx_roundv2sf2): Remove.

    gcc/testsuite/ChangeLog:

            * gcc.target/i386/pr110762.c: New test.

  parent reply	other threads:[~2023-07-26 10:18 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-21  8:43 [Bug target/110762] New: " jbeulich at suse dot com
2023-07-21  9:13 ` [Bug target/110762] " rguenth at gcc dot gnu.org
2023-07-21  9:19 ` rguenth at gcc dot gnu.org
2023-07-21  9:36 ` ubizjak at gmail dot com
2023-07-21  9:40 ` amonakov at gcc dot gnu.org
2023-07-21 10:22 ` segher at gcc dot gnu.org
2023-07-21 10:46 ` rguenth at gcc dot gnu.org
2023-07-21 10:47 ` rguenth at gcc dot gnu.org
2023-07-21 10:49 ` rguenth at gcc dot gnu.org
2023-07-21 10:53 ` jbeulich at suse dot com
2023-07-21 11:09 ` ubizjak at gmail dot com
2023-07-21 11:16 ` rguenth at gcc dot gnu.org
2023-07-21 11:25 ` rguenth at gcc dot gnu.org
2023-07-21 12:42 ` ubizjak at gmail dot com
2023-07-21 12:47 ` amonakov at gcc dot gnu.org
2023-07-21 13:18 ` jbeulich at suse dot com
2023-07-26  7:30 ` ubizjak at gmail dot com
2023-07-26  7:53 ` rguenth at gcc dot gnu.org
2023-07-26  9:34 ` ubizjak at gmail dot com
2023-07-26 10:18 ` cvs-commit at gcc dot gnu.org [this message]
2023-07-28  6:28 ` [Bug target/110762] [11/12/13 Regression] " rguenth at gcc dot gnu.org
2023-07-28  8:15 ` ubizjak at gmail dot com
2023-07-31  8:04 ` ubizjak at gmail dot com
2023-07-31  8:10 ` crazylht at gmail dot com
2023-08-07 11:52 ` cvs-commit at gcc dot gnu.org
2023-08-25  9:04 ` ubizjak at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-110762-4-C4fmvT0IE7@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).