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/107839] spurious "may be used uninitialized" warning while all uses are under "if (c)"
Date: Thu, 24 Nov 2022 10:12:30 +0000	[thread overview]
Message-ID: <bug-107839-4-MS51D0v6I5@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-107839-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
We see

  <bb 2> [local count: 3508266]:
  if (c_4(D) != 0)
    goto <bb 3>; [33.00%]
  else
    goto <bb 10>; [67.00%]

  <bb 10> [local count: 2350538]:
  goto <bb 4>; [100.00%]

  <bb 4> [local count: 3508266]:
  # v_10 = PHI <v_5(D)(10), v_8(3)>
  _3 = (unsigned int) v_10;
  _12 = _3 * 2;
  _1 = (int) _12;

  <bb 5> [local count: 354334800]:
  if (c_4(D) != 0)
    goto <bb 7>; [66.33%]
  else
    goto <bb 8>; [33.67%]

it's loop invariant motion that hoists the v + v compute out of the loop
and thus outside of its controlling condition.  You can see it's careful
to not introduce undefined overflow that is possibly conditionally
executed only but it fails to consider the case of 'v' being conditionally
uninitialized.

It's very difficult to do the right thing here - it might be tempting to
hoist the compute as

  if (c)
    tem = v+v;
  while (1)
    if (c)
      f(tem);

but apart from the technical problems in invariant motion this would
cause it does introduce another variable that's only conditionally
initialized and thus might be prone to false positive diagnostics.
Not to mention the hoisted if (c) branch having a cost.

Maybe the simplest thing would be to never hoist v + v, or only
hoist it when the controlling branch is not loop invariant.

The original testcase is probably more "sensible", does it still have
a loop invariant controlling condition and a loop invariant computation
under that control?

  parent reply	other threads:[~2022-11-24 10:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-23 16:38 [Bug tree-optimization/107839] New: " vincent-gcc at vinc17 dot net
2022-11-23 21:00 ` [Bug tree-optimization/107839] " rguenth at gcc dot gnu.org
2022-11-24 10:12 ` rguenth at gcc dot gnu.org [this message]
2022-11-24 17:09 ` vincent-gcc at vinc17 dot net
2022-12-05  9:32 ` cvs-commit at gcc dot gnu.org
2022-12-05  9:47 ` rguenth at gcc dot gnu.org
2022-12-12 11:20 ` cvs-commit at gcc dot gnu.org
2024-01-20 17:22 ` pinskia 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-107839-4-MS51D0v6I5@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).