public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/19804] New: Missed jump threading opportunity on "else" arm of COND_EXPR
@ 2005-02-07 15:33 kazu at cs dot umass dot edu
  2005-02-07 17:25 ` [Bug tree-optimization/19804] " pinskia at gcc dot gnu dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: kazu at cs dot umass dot edu @ 2005-02-07 15:33 UTC (permalink / raw)
  To: gcc-bugs

Consider:

int
foo (int a, int b)
{
  if (a == 0)
    if (b != 2)
      return 10;

  if (b == 1)
    return 10;

  return 20;
}

Here is t21.dom1:

foo (a, b)
{
  int D.1120;

<bb 0>:
  if (a_2 == 0) goto <L0>; else goto <L2>;

<L0>:;
  if (b_4 != 2) goto <L1>; else goto <L2>;

<L1>:;
  D.1120_7 = 10;
  goto <bb 6> (<L6>);

<L2>:;
  if (b_4 == 1) goto <L4>; else goto <L5>;

<L4>:;
  D.1120_6 = 10;
  goto <bb 6> (<L6>);

<L5>:;
  D.1120_5 = 20;

  # D.1120_1 = PHI <10(2), 10(4), 20(5)>;
<L6>:;
  return D.1120_1;

}

Note that edge from <L0> to <L2> can be threaded through L2.

This seems to be due to an artificial restriction in
tree-ssa-dom.c:dom_opt_finalize_block.

	      /* If we have a simple NAME = VALUE equivalency record it.
		 Until the jump threading selection code improves, only
		 do this if both the name and value are SSA_NAMEs with
		 the same underlying variable to avoid missing threading
		 opportunities.  */
	      if (lhs
		  && TREE_CODE (COND_EXPR_COND (last)) == SSA_NAME)
		record_const_or_copy (lhs, rhs);

This "if" should just say "if (lhs)".

But be careful though.  Making the above change seems to miss other jump
threading opportunities as far as I can tell from my coverage test.
I have yet to find a test case that would be less optimized with the above
change.

By the way, the comment above the "if" statement is just a cut-n-paste from
the "then" case.  It does not reflect what the "if" statement does though.

-- 
           Summary: Missed jump threading opportunity on "else" arm of
                    COND_EXPR
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P2
         Component: tree-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kazu at cs dot umass dot edu
                CC: gcc-bugs at gcc dot gnu dot org,law at redhat dot com
OtherBugsDependingO 19794
             nThis:


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19804


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-04-25  5:07 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-02-07 15:33 [Bug tree-optimization/19804] New: Missed jump threading opportunity on "else" arm of COND_EXPR kazu at cs dot umass dot edu
2005-02-07 17:25 ` [Bug tree-optimization/19804] " pinskia at gcc dot gnu dot org
2005-02-07 19:36 ` kazu at cs dot umass dot edu
2005-02-07 19:48 ` kazu at cs dot umass dot edu
2005-02-15  1:37 ` law at redhat dot com
2005-04-23  1:14 ` law at redhat dot com
2005-04-25  5:07 ` law at redhat dot com

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).