Bug 65650 - CCP does not propgate copies
Summary: CCP does not propgate copies
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: ---
Assignee: Richard Biener
URL:
Keywords: missed-optimization
Depends on:
Blocks:
 
Reported: 2015-04-01 12:11 UTC by Richard Biener
Modified: 2015-04-21 13:17 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work: 6.0
Known to fail:
Last reconfirmed: 2015-04-01 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2015-04-01 12:11:34 UTC
CCP should be able to optimize the following to return 0; in a single pass invocation.

int foo (int i)
{
  int j = i;
  int k = 0;
  int l = j + k;
  int m = l - j;
  return m;
}
Comment 1 Richard Biener 2015-04-01 12:12:11 UTC
I have a patch teaching CCP to perform copy propagation in its lattice.
Comment 2 Richard Biener 2015-04-21 12:53:14 UTC
Author: rguenth
Date: Tue Apr 21 12:52:43 2015
New Revision: 222267

URL: https://gcc.gnu.org/viewcvs?rev=222267&root=gcc&view=rev
Log:
2015-04-21  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/65650
	* tree-ssa-ccp.c (valid_lattice_transition): Allow lattice
	transitions involving copies.
	(set_lattice_value): Adjust for copy lattice state.
	(ccp_lattice_meet): Do not merge UNDEFINED and a copy to the copy
	if that doesn't dominate the merge point.
	(bit_value_unop): Adjust what we treat as varying mask.
	(bit_value_binop): Likewise.
	(bit_value_assume_aligned): Likewise.
	(evaluate_stmt): When we simplified to a SSA name record a copy
	instead of dropping to varying.
	(visit_assignment): Simplify.

	* gimple-match.h (gimple_simplify): Add another callback.
	* gimple-fold.c (fold_stmt_1): Adjust caller.
	(gimple_fold_stmt_to_constant_1): Likewise - pass valueize
	for the 2nd callback.
	* gimple-match-head.c (gimple_simplify): Add a callback that is
	used to valueize the stmt operands and use it that way.

	* gcc.dg/tree-ssa/ssa-ccp-37.c: New testcase.
	* gcc.dg/tree-ssa/forwprop-11.c: Adjust.
	* gcc.dg/tree-ssa/ssa-fre-3.c: Likewise.
	* gcc.dg/tree-ssa/ssa-fre-4.c: Likewise.
	* gcc.dg/tree-ssa/ssa-fre-5.c: Likewise.
	* gcc.dg/tree-ssa/ssa-fre-32.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-37.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/gimple-fold.c
    trunk/gcc/gimple-match-head.c
    trunk/gcc/gimple-match.h
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gcc.dg/tree-ssa/forwprop-11.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-3.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-32.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-4.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-5.c
    trunk/gcc/tree-ssa-ccp.c
Comment 3 Richard Biener 2015-04-21 13:17:25 UTC
Fixed.