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

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

            Bug ID: 113701
           Summary: Issues with __int128 argument passing
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ubizjak at gmail dot com
  Target Milestone: ---

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:

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

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

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-01  9:17 ubizjak at gmail dot com [this message]
2024-02-01  9:20 ` [Bug target/113701] " ubizjak at gmail dot com
2024-02-01  9:46 ` ubizjak at gmail dot com
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@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).