public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.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	[thread overview]
Message-ID: <bug-98292-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98292

            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 incorrectly
adds something like __builtin_unreachable () even for C).

             reply	other threads:[~2020-12-15 16:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-15 16:29 jakub at gcc dot gnu.org [this message]
2021-01-06 12:01 ` [Bug tree-optimization/98292] " marxin at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-98292-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).