public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "aldyh at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/101186] predictable comparison of integer variables not folded
Date: Sun, 27 Jun 2021 15:30:22 +0000	[thread overview]
Message-ID: <bug-101186-4-qHJyAXJ2BH@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101186-4@http.gcc.gnu.org/bugzilla/>

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

Aldy Hernandez <aldyh at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aldyh at gcc dot gnu.org,
                   |                            |jeffreyalaw at gmail dot com

--- Comment #4 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
To give a little more context, the IL at thread1 looks like this:

  <bb 3> [local count: 59055800]:
  goto <bb 9>; [100.00%]

  <bb 4> [local count: 955630225]:
  if (a_5(D) != 0)
    goto <bb 5>; [67.00%]
  else
    goto <bb 7>; [33.00%]

  <bb 5> [local count: 640272253]:
  if (x_8(D) < c_12)
    goto <bb 6>; [33.00%]
  else
    goto <bb 8>; [67.00%]

  <bb 6> [local count: 211289842]:
  unreachable ();
  goto <bb 8>; [100.00%]

  <bb 7> [local count: 315357972]:
  blah ();

  <bb 8> [local count: 955630227]:
  b_11 = b_1 + 1;
  goto <bb 10>; [100.00%]

  <bb 9> [local count: 118111600]:
  # c_12 = PHI <x_8(D)(3), y_4(D)(2)>

  <bb 10> [local count: 1073741824]:
  # b_1 = PHI <b_6(D)(9), b_11(8)>
  if (b_1 <= 999)
    goto <bb 4>; [89.00%]
  else
    goto <bb 11>; [11.00%]

The path from 3->9->10->4->5 could *theoretically* resolve the conditional in
BB5.  If this were a permissible jump threading path, the threader would
replace the conditional in BB5 into a jump to BB8, thus eliding the
unreachable.

However, BB9->BB10 would cross loop boundaries which is not permitted in the
backwards threader.  Specifically, the threading candidate conditional is BB5,
which is in a loop:

;; Loop 1
;;  header 10, latch 8
;;  depth 1, outer 0
;;  nodes: 10 8 6 7 5 4 (<-- note BB5 & BB10 in here)

And BB9 is outside said loop.

See path_crosses_loops in tree-ssa-threadbackward.c as well as handle_phi()
where we specifically skip PHI edges pointing outside the current loop.

Note that even though my upcoming rewrite of the backward threader does not use
the relational oracle, Andrew says it would be trivial to do so.  In which
case, we *could* resolve the above path, but would still fail to thread it
because it crosses a loop boundary.

Perhaps Jeff can opine on whether the path duplicator in the threader back-end,
could be taught to thread through loops.

  parent reply	other threads:[~2021-06-27 15:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-24  4:25 [Bug tree-optimization/101186] New: " dizhao at os dot amperecomputing.com
2021-06-24  4:33 ` [Bug tree-optimization/101186] " pinskia at gcc dot gnu.org
2021-06-24  6:49 ` rguenth at gcc dot gnu.org
2021-06-24  6:50 ` rguenth at gcc dot gnu.org
2021-06-24  9:08 ` dizhao at os dot amperecomputing.com
2021-06-24 18:30 ` amacleod at redhat dot com
2021-06-27 15:30 ` aldyh at gcc dot gnu.org [this message]
2021-06-27 15:33 ` aldyh at gcc dot gnu.org
2021-06-28 19:20 ` law at gcc dot gnu.org
2021-07-19  6:35 ` 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-101186-4-qHJyAXJ2BH@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).