public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ubizjak at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/109052] Unnecessary reload with -mfpmath=both
Date: Fri, 17 Mar 2023 14:12:15 +0000	[thread overview]
Message-ID: <bug-109052-4-acAkOrN7e1@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-109052-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Vladimir Makarov from comment #4)

> So I think the current patch is probably an adequate solution.

Perhaps the compiler should also try to swap input operands to fit the combined
insn when commutative operands are allowed. This would solve the testcase from
Comment #2:

double foo (double a, double b)
{
  double z = __builtin_fmod (a, 3.14);
  return z * b;
}

gcc -O2 -mfpmath=both -mavx:

    Failed combined insn:
   24: r90:DF=r96:DF*r85:DF
      REG_DEAD r85:DF
      REG_DEAD r82:DF
    Restoring insn after failed combining:

(^^^ shouldn't there be a memory operand mentioned in the above RTX dump?)

...
(insn 42 41 24 6 (set (reg/v:DF 23 xmm3 [orig:82 z ] [82])
        (mem/c:DF (plus:DI (reg/f:DI 7 sp)
                (const_int 8 [0x8])) [1 %sfp+-24 S8 A64])) "fmod.c":4:12 145
{*movdf_internal}
     (nil))
(insn 24 42 30 6 (set (reg:DF 20 xmm0 [90])
        (mult:DF (reg/v:DF 23 xmm3 [orig:82 z ] [82])
            (reg/v:DF 22 xmm2 [orig:85 b ] [85]))) "fmod.c":4:12 1189
{*fop_df_comm}
     (nil))
...

As can be seen in the above dump, swapped input operands would fit alternative
(v,v,vm) in the insn pattern:

  [(set (match_operand:MODEF 0 "register_operand" "=f,x,v")
        (match_operator:MODEF 3 "binary_fp_operator"
          [(match_operand:MODEF 1 "nonimmediate_operand" "%0,0,v")
           (match_operand:MODEF 2 "nonimmediate_operand" "fm,xm,vm")]))]

  parent reply	other threads:[~2023-03-17 14:12 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07 12:57 [Bug rtl-optimization/109052] New: " ubizjak at gmail dot com
2023-03-07 12:58 ` [Bug rtl-optimization/109052] " ubizjak at gmail dot com
2023-03-07 13:58 ` ubizjak at gmail dot com
2023-03-17 13:07 ` cvs-commit at gcc dot gnu.org
2023-03-17 13:21 ` vmakarov at gcc dot gnu.org
2023-03-17 14:12 ` ubizjak at gmail dot com [this message]
2023-03-17 14:39 ` vmakarov at gcc dot gnu.org
2023-03-17 19:51 ` bergner at gcc dot gnu.org
2023-03-31 15:05 ` cvs-commit at gcc dot gnu.org
2024-01-08  9:10 ` 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-109052-4-acAkOrN7e1@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).