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 target/113701] Issues with __int128 argument passing
Date: Thu, 01 Feb 2024 09:46:20 +0000	[thread overview]
Message-ID: <bug-113701-4-y1SnX5IITI@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-113701-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Uroš Bizjak from comment #0)
> Following testcase:
> 
> --cut here--
> typedef unsigned __int128 U;
> 
> U f0 (U x, U y) { return x + y; }
> U f1 (U x, U y) { return x - y; }
> 
> U f2 (U x, U y) { return x | y; }
> 
> int f3 (U x, U y) { return x == y; }
> int f4 (U x, U y) { return x < y; }
> --cut here--
> 
> shows some issues with __int128 parameter passing.
> 
> gcc -O2:
> 
> f0:
>         movq    %rdx, %rax
>         movq    %rcx, %rdx
>         addq    %rdi, %rax
>         adcq    %rsi, %rdx
>         ret
> 
> f1:
>         xchgq   %rdi, %rsi
>         movq    %rdx, %r8
>         movq    %rsi, %rax
>         movq    %rdi, %rdx
>         subq    %r8, %rax
>         sbbq    %rcx, %rdx
>         ret
> 
> f2:
>         xchgq   %rdi, %rsi
>         movq    %rdx, %rax
>         movq    %rcx, %rdx
>         orq     %rsi, %rax
>         orq     %rdi, %rdx
>         ret
> 
> f3:
>         xchgq   %rdi, %rsi
>         movq    %rdx, %r8
>         movq    %rcx, %rax
>         movq    %rsi, %rdx
>         movq    %rdi, %rcx
>         xorq    %rax, %rcx
>         xorq    %r8, %rdx
>         xorl    %eax, %eax
>         orq     %rcx, %rdx
>         sete    %al
>         ret
> 
> f4:
>         xorl    %eax, %eax
>         cmpq    %rdx, %rdi
>         sbbq    %rcx, %rsi
>         setc    %al
>         ret
> 
> Functions f0 and f4 are now optimal.
> 
> Functions f1, f2 and f3 emit extra XCHG, but the swap should be propagated
> to MOV instructions instead.
> 
> The most problematic function is f3, which regressed noticeably from gcc-12.3:

This patch solves the regression:

--cut here--
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index bac0a6ade67..02fed16db72 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -1632,11 +1632,6 @@ (define_insn_and_split "*cmp<dwi>_doubleword"
              (set (match_dup 4) (ior:DWIH (match_dup 4) (match_dup 5)))])]
 {
   split_double_mode (<DWI>mode, &operands[0], 2, &operands[0], &operands[2]);
-  /* Placing the SUBREG pieces in pseudos helps reload.  */
-  for (int i = 0; i < 4; i++)
-    if (SUBREG_P (operands[i]))
-      operands[i] = force_reg (<MODE>mode, operands[i]);
-
   operands[4] = gen_reg_rtx (<MODE>mode);

   /* Special case comparisons against -1.  */
--cut here--

gcc -O2:

f3:
        xchgq   %rdi, %rsi
        xorl    %eax, %eax
        xorq    %rsi, %rdx
        xorq    %rdi, %rcx
        orq     %rcx, %rdx
        sete    %al
        ret

  parent reply	other threads:[~2024-02-01  9:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01  9:17 [Bug target/113701] New: " ubizjak at gmail dot com
2024-02-01  9:20 ` [Bug target/113701] " ubizjak at gmail dot com
2024-02-01  9:46 ` ubizjak at gmail dot com [this message]
2024-02-01 10:31 ` rguenth at gcc dot gnu.org
2024-02-01 10:53 ` ubizjak at gmail dot com
2024-02-01 11:14 ` roger at nextmovesoftware dot com
2024-02-01 20:25 ` cvs-commit at gcc dot gnu.org

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-113701-4-y1SnX5IITI@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).