public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "unlvsur at live dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug rtl-optimization/99548] New: Help me! Lost the fight against the compiler.
Date: Thu, 11 Mar 2021 11:00:18 +0000	[thread overview]
Message-ID: <bug-99548-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 99548
           Summary: Help me! Lost the fight against the compiler.
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: unlvsur at live dot com
  Target Milestone: ---

https://godbolt.org/z/Kd8q57

The compiler just could not generate as good as assembly as I manually wrote.
Unfortunately, due to the calling convention issues, the inline asm version
would never be portable and hurt other compiler optimizations.


Some patterns like neither GCC nor clang could correctly deal with it.
    std::uint64_t v=0;//set 0 to make compiler happy or it is UB.
    sub_borrow(carry,v,v,v);


        movl    $0, %eax
        movq    %rax, %rdx
        sbbq    %rax, %rdx

What the code actually want is to
sbb %rdx,%rdx
Which is to set the register to the UINT64_MAX when carry (borrow) flag is 1.

        movq    (%rdx), %rcx
        movq    8(%rsi), %r9
        addq    (%rsi), %rcx
        movq    16(%rsi), %r8
        movq    24(%rdx), %rax
        adcq    8(%rdx), %r9
        movq    24(%rsi), %rsi
        adcq    16(%rdx), %r8
        adcq    %rax, %rsi
        movl    $0, %eax

Do we have any possibility to fix those optimization issues in the compiler?

             reply	other threads:[~2021-03-11 11:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-11 11:00 unlvsur at live dot com [this message]
2021-03-11 20:10 ` [Bug target/99548] " pinskia at gcc dot gnu.org
2021-03-11 23:35 ` unlvsur at live dot com
2021-12-23 21:45 ` pinskia 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-99548-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).