From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A089C386F401; Tue, 15 Dec 2020 16:29:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A089C386F401 From: "jakub at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/98292] New: Optimize away C return; in function returning integral/pointer Date: Tue, 15 Dec 2020 16:29:36 +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: 11.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jakub at gcc dot gnu.org 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 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: Tue, 15 Dec 2020 16:29:36 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D98292 Bug ID: 98292 Summary: Optimize away C return; in function returning integral/pointer Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: jakub at gcc dot gnu.org Target Milestone: --- This is related to the PR94779, but that one talks just about switches. int foo (int x) { if (x > 20) return x; } int bar (int x) { if (x > 30) return 30; } int baz (int x) { if (x > 40) return x + 1U; } int qux (int x) { if (x > 50) return x | 32; } is optimized to just the return statement in C++ (because we add __builtin_unreachable() in that case), but not in C. I think we should do that also in C, provided that there are no non-debug non-CLOBBER stmts on the branch with GIMPLE_RETURN without argument, and provided that on the other branch there are just very few cheap stmts guaranteed not to invoke UB/trap (appart from debug/CLOBBER stmts) plus the GIMPLE_RETURN with argument. LLVM seems to optimize that (though not sure if it isn't because it incorre= ctly adds something like __builtin_unreachable () even for C).=