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

Jeffrey A. Law <law at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
                 CC|                            |law at redhat dot com
           Assignee|unassigned at gcc dot gnu.org      |law at redhat dot com

--- Comment #6 from Jeffrey A. Law <law at redhat dot com> ---
Andrew, Manu, wrong.  This is not a failing to handle logicals, threading
handles those just fine.  It's code that tries to keep the cost of jump
threading down.  Jump threading is expensive and scales poorly -- left to its
own devices it'd actually try to thread every potential path through the CFG
which is obviously undesirable.

The thread3 dump looks something like this:

;;   basic block 2, loop depth 0
;;    pred:       ENTRY
  j_6 = rand ();
  if (i_3(D) >= j_6)
    goto <bb 8>; [55.78%]
  else
    goto <bb 3>; [44.22%]
;;    succ:       8
;;                3

;;   basic block 3, loop depth 0
;;    pred:       2
  if (i_3(D) < 0)
    goto <bb 4>; [13.00%]
  else
    goto <bb 5>; [87.00%]
;;    succ:       4
;;                5

;;   basic block 4, loop depth 0
;;    pred:       3
;;                8
  # j_26 = PHI <j_6(3), j_12(D)(8)>
  # prephitmp_20 = PHI <0(3), 1(8)>
  i_4 = rand ();
;;    succ:       5

;;   basic block 5, loop depth 0
;;    pred:       4
;;                3
  # i_5 = PHI <i_4(4), i_3(D)(3)>
  # j_27 = PHI <j_26(4), j_6(3)>
  # prephitmp_7 = PHI <prephitmp_20(4), 0(3)>
  _16 = i_5 > 9;
  _17 = _16 | prephitmp_7;
  if (_17 != 0)
    goto <bb 6>; [0.00%]
  else
    goto <bb 7>; [100.00%]
;;    succ:       6
;;                7

;;   basic block 6, loop depth 0
;;    pred:       5
;;                8
;;    succ:       7

;;   basic block 7, loop depth 0
;;    pred:       6
;;                5
  # _1 = PHI <0(6), j_27(5)>
  return _1;
;;    succ:       EXIT

;;   basic block 8, loop depth 0
;;    pred:       2
  if (i_3(D) < 0)
    goto <bb 4>; [35.41%]
  else
    goto <bb 6>; [64.59%]
;;    succ:       4
;;                6


The path we want to thread is bb8->bb4->bb5 which will always result in
reaching bb6.  But bb4 doesn't look interesting to the threader (it's got
statements with side effects (so it's not a forwarder) and it has a single
successor.

If we loosen the requirements for what looks interesting to the threader (say
by making everything interesting), then the threader will pick up this missed
jump thread and as a side effect of eliminating the infeasible path
(8->4->5->7) eliminates the false positive.

Reply via email to