Bug 43934 - LIM should handle PHI nodes
Summary: LIM should handle PHI nodes
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.6.0
: P3 enhancement
Target Milestone: 4.6.0
Assignee: Richard Biener
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2010-04-29 12:16 UTC by Richard Biener
Modified: 2014-06-06 07:21 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-04-29 14:16:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2010-04-29 12:16:16 UTC
Currently LIM does not handle moving invariant PHIs.

void bar (int);
void foo (int n, int m)
{
  unsigned i;
  for (i = 0; i < n; ++i)
    {
      int x;
      if (m < 0)
        x = 1;
      else
        x = m;
      bar (x);
    }
}

we should move the computation of x out of the loop.

For simple cases like this, a single invariant PHI node controlled by
the predicate

  if (m_6(D) < 0)
    goto <bb 4>;
  else
    goto <bb 9>;

<bb 9>:
  goto <bb 5>;

<bb 4>:

<bb 5>:
  # x_2 = PHI <1(4), m_6(D)(9)>

we can hoist x_2 by inserting an assignment from a COND_EXPR.  Multiple
PHI nodes and/or not trivially empty intermediate blocks should be moved
as CFG pieces instead.

Thus hacking the simple case into LIM is the same as converting such
CFG pieces to COND_EXPRs similar to what if-conversion for the vectorizer
does.
Comment 1 Richard Biener 2010-04-29 14:16:00 UTC
I have a patch.
Comment 2 Richard Biener 2010-05-06 09:04:37 UTC
Subject: Bug 43934

Author: rguenth
Date: Thu May  6 09:04:00 2010
New Revision: 159099

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=159099
Log:
2010-05-06  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/43934
	* tree-ssa-loop-im.c (movement_possibility): Handle PHI nodes.
	(stmt_cost): Likewise.
	(extract_true_false_args_from_phi): New helper.
	(determine_max_movement): For PHI nodes verify we can hoist them
	and compute their cost.
	(determine_invariantness_stmt): Handle PHI nodes.
	(move_computations_stmt): Likewise.  Hoist PHI nodes in
	if-converted form using COND_EXPRs.
	(move_computations): Return TODO_cleanup_cfg if we hoisted PHI
	nodes.
	(tree_ssa_lim): Likewise.
	* tree-flow.h (tree_ssa_lim): Adjust prototype.
	* tree-ssa-loop.c (tree_ssa_loop_im): Return todo.

	* gcc.dg/tree-ssa/ssa-lim-9.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-9.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-flow.h
    trunk/gcc/tree-ssa-loop-im.c
    trunk/gcc/tree-ssa-loop.c

Comment 3 Richard Biener 2010-05-06 13:56:38 UTC
Fixed.
Comment 4 chrbr 2014-06-06 07:21:34 UTC
Author: chrbr
Date: Fri Jun  6 07:21:02 2014
New Revision: 211302

URL: http://gcc.gnu.org/viewcvs?rev=211302&root=gcc&view=rev
Log:
PR tree-optimization/43934
* tree-ssa-loop-im.c (determine_max_movement): Add PHI def constant cost.


Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-8.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-loop-im.c