From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 37ACB3858C41; Tue, 11 Jun 2024 00:08:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 37ACB3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1718064507; bh=eQm0P3IQyxX3+gIY5X+o5ThBfo/jknC8cdT0WhexFas=; h=From:To:Subject:Date:From; b=MutCdtUzQexwOVHuiq+AhdvLy/8qh5xY3+zkZEcKaoNLUvVS3PJkDCnWnyMbuQCvE GizeVAzoKqfol70B2T+8JrixWMj4UNhxpzMta6F0H2LMVxZkHY0+at47CzO5L8Sydn EM8L8uQbUhbn8fSrYfQzEggMH6FLo7f82tHLtc0o= From: "blubban at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: blubban at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D115423 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, ".") =3D=3D 0 || __builtin_strcmp(c, "..") =3D=3D 0; } bool h(const char* c) { return (c[0] =3D=3D '.' && c[1] =3D=3D '\0') || (c[0] =3D=3D '.' && c[1] =3D=3D '.' && c[2] =3D=3D '\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. Fe= el free to move it if it's wrong.)=