public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "blubban at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/115423] New: Inlined strcmp optimizes poorly
Date: Tue, 11 Jun 2024 00:08:26 +0000	[thread overview]
Message-ID: <bug-115423-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 115423
           Summary: Inlined strcmp optimizes poorly
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: blubban at gmail dot com
  Target Milestone: ---

bool g(const char* c) {
    return __builtin_strcmp(c, ".") == 0 ||
           __builtin_strcmp(c, "..") == 0;
}
bool h(const char* c) {
    return (c[0] == '.' && c[1] == '\0') ||
           (c[0] == '.' && c[1] == '.' && c[2] == '\0');
}


Compile with -O2.


Expected result: Same output from both.

Actual: The former results in a mess that, among other inefficiencies, loads
c[0] twice.


Online reproducer: https://godbolt.org/z/E4vEshvcM


(I don't know if this is an RTL or tree optimizer issue, I just guessed. Feel
free to move it if it's wrong.)

             reply	other threads:[~2024-06-11  0:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-11  0:08 blubban at gmail dot com [this message]
2024-06-11  4:24 ` [Bug tree-optimization/115423] " pinskia at gcc dot gnu.org
2024-06-11  9:48 ` rguenth at gcc dot gnu.org
2024-06-11 10:08 ` blubban 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-115423-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).