From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A12A43858426; Mon, 22 May 2023 12:57:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A12A43858426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1684760260; bh=w5NlwOsQGojVoJ3tG8CfKwNZTaKBPiU2uy7bVEfFMLI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BKlYv/g2bwN7/G4Mmc8FN8YKqFPzUzCAbQ276zwlrh6DDQNLuQAoUVfWTUFAPEvaK pg1gUV8oQP/MgvGdZiYfhLXWhl9w2RtDYGM2xEiDt0jmo8As3GO6XbBQnzhxU6Zjm5 6F2ZshDXYHTmiv8cCDWd95Cbxgv70z9Ppij8LnGI= From: "antoshkka at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/109931] Knowledge on literal not used in optimization Date: Mon, 22 May 2023 12:57:40 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: Message-ID: In-Reply-To: References: 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 --- Comment #3 from Antony Polukhin --- > But that's because nothing in the function asserts this? Without fully > specializing and unrolling on the constant "hello" argument at least. Yes, I was hoping for that unrolling to happen Probably a more simplified case: constexpr bool EqualICase(const char* lowercase, const char* y) noexcept { for (;;) { const auto lowercase_c =3D *lowercase; if (!lowercase_c) return true; if (lowercase_c !=3D *y) { return false; } ++lowercase; ++y; } } bool test2(const char* y) { return EqualICase("he", y); } With range info for loads from read-only constants I'd expect this to become just a test2(char const*): cmp BYTE PTR [rdi], 104 jne .L3 cmp BYTE PTR [rdi+1], 101 sete al ret .L3: xor eax, eax ret rather than a fair loop with checks for \0 Godbolt: https://godbolt.org/z/z6rTYEzWx=