public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/112310] [14 Regression] Wrong code at -O2/3 on x86_64-linux-gnu since r14-1161-g5476de2618f
Date: Fri, 03 Nov 2023 09:40:18 +0000	[thread overview]
Message-ID: <bug-112310-4-OwK2DWPBzU@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-112310-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hm.  It's more complicated, we cannot keep the intersection of expressions here
as seen by the added testcase

int foo (int flag, int * __restrict a, int * __restrict b)
{
  int res;
  if (flag)
    res = *a + *b;
  else
    {
      res = *a;
      *a = 1;
      res += *b;
    }
  return res;
}

here we expect to hoist the *a and *b load and the addition.  But while we
can make the loads have the same expression, the adds will inevitably
differ as we do not have valueized operands there.

So what happens is that we have multiple expressions for the same value
we'd like to hoist, and currently by r14-1161-g5476de2618f we're picking
the "first".  For the case in this PR it's the "wrong" one, but we can't
easily decide which one is correct.

For the bug we have {nop_expr,iftmp.1_43} (0028) and
{mult_expr,p.5_7,2022160547} (0028) where the first depends on
{mult_expr,_4,2022160547} (0033) and the second depends on
{nop_expr,_4} (0007) - both are not values we intended to hoist
but we'd generate them anyway via create_expression_by_pieces.

So instead of forcing the expressions to be the same on all paths as it
was before r14-1161-g5476de2618f we can go and check whether the
resulting set of expressions to hoist is self-consistent, in that it
contains all dependent expressions we'd have to hoist.

That also ensures we can truly eliminate the whole computation on both
paths (consider the dependent expressions to be live).

Ideally we'd keep the union of the expressions from both paths like
compute_antic does and then we can pick the representation that
fulfills the constraints.

  parent reply	other threads:[~2023-11-03  9:40 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-31 11:13 [Bug tree-optimization/112310] New: " shaohua.li at inf dot ethz.ch
2023-10-31 12:02 ` [Bug tree-optimization/112310] " rguenth at gcc dot gnu.org
2023-10-31 12:03 ` rguenth at gcc dot gnu.org
2023-10-31 15:52 ` rguenth at gcc dot gnu.org
2023-11-03  9:40 ` rguenth at gcc dot gnu.org [this message]
2023-11-03 10:35 ` cvs-commit at gcc dot gnu.org
2023-11-03 10:35 ` rguenth 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-112310-4-OwK2DWPBzU@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).