public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115423] New: Inlined strcmp optimizes poorly
@ 2024-06-11  0:08 blubban at gmail dot com
  2024-06-11  4:24 ` [Bug tree-optimization/115423] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: blubban at gmail dot com @ 2024-06-11  0:08 UTC (permalink / raw)
  To: gcc-bugs

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.)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-06-11 10:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-11  0:08 [Bug tree-optimization/115423] New: Inlined strcmp optimizes poorly blubban at gmail dot com
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

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).