From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id AED553857828; Sat, 2 Jan 2021 08:44:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AED553857828 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/94802] Failure to recognize identities with __builtin_clz Date: Sat, 02 Jan 2021 08:44:34 +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: 10.0 X-Bugzilla-Keywords: easyhack, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org X-Bugzilla-Status: NEW 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 02 Jan 2021 08:44:34 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94802 --- Comment #5 from Jakub Jelinek --- Even when the optimization is restricted to GIMPLE only, the single_use in there doesn't work really well before fre1 optimizes it, because the above mentioned testcase doesn't reuse the same expression, but has a different subtraction that just needs to be CSEd first. An alternative would be to treat (signed undefined overflow) x >=3D y and x= - y interchangeably by SCCVN, i.e. hash them the same and if we find both forms= (in either order), transform the x >=3D y back into (x - y) >=3D 0 (similar for= other non-equality comparisons). I guess that would fix both that testcase and PR94798 which also suffers from that: int foo (int a, int b) { return (b >=3D a) ? (b - a) : 0; } int bar (int a, int b) { return ((b - a) >=3D 0) ? (b - a) : 0; } bar is optimized more than foo - but in this case it is a user that wrote i= t in two different forms rather than one. Another option is to enable the x - y op 0 to x op y canonicalization only after SCCVN got a chance to CSE stuff after inlining, while that would fix = the por45397.c testcase, it wouldn't the above PR94798 one. Richi, any thoughts on this?=