From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D3AE13858D37; Mon, 22 May 2023 12:33:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D3AE13858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684758809; bh=E7lIGxjwYtmqmRNzi71XlaUE1X/c1O9MlVutf18SX1c=; h=From:To:Subject:Date:From; b=Tq2XPRhSE4t0tbihveY3Pp1Skm+aP3r7GmanyhAkk2scsiQXyybgTyQEeo+l5Z4DK Cg+4UgWYWrVKel04JNM/TzO24T1DIiYBF6cIFN2skifnxT2gO/d3DMNRNDZmtDWx41 pOjUzRuZdVcpmhR/2Q5w9Gslyu75KSAAlOOjbcW8= From: "antoshkka at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109931] New: Knowledge on literal not used in optimization Date: Mon, 22 May 2023 12:33:29 +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: 14.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: antoshkka 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 keywords 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=3D109931 Bug ID: 109931 Summary: Knowledge on literal not used in optimization Product: gcc Version: 14.0 Status: UNCONFIRMED Keywords: missed-optimization Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: antoshkka at gmail dot com Target Milestone: --- Function for comparing a lower-cased string with runtime string of known si= ze: constexpr bool ICaseEqualLowercase(const char* lowercase, const char* y, unsigned size) noexcept { constexpr char kLowerToUpperMask =3D static_cast(~unsigned{32}); for (unsigned i =3D 0; i < size; ++i) { const auto lowercase_c =3D lowercase[i]; if (lowercase_c !=3D y[i]) { if (!('a' <=3D lowercase_c && lowercase_c <=3D 'z') || (lowercase_c & kLowerToUpperMask) !=3D y[i]) { return false; } } } return true; } bool test2(const char* y) { return ICaseEqualLowercase("hello", y, 5); } With GCC trunk and -O2 flags the GCC fails to understand that all the characters of `lowercase` are lowercase ASCII and the expression `!('a' <=3D lowercase_c && lowercase_c <=3D 'z')` is always `false`. Because of that, additional instructions in loop are emitted: lea esi, [rdx-97] cmp sil, 25 ja .L6 Godbolt playground: https://godbolt.org/z/xrc1T4oeW=