re PR tree-optimization/14287 ([tree-ssa] does not remove unnecessary extensions)

2006-05-04  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/14287
	PR tree-optimization/14844
	PR tree-optimization/19792
	PR tree-optimization/21608
	PR tree-optimization/27090
	* tree-ssa-pre.c (try_combine_conversion): New function.
	(compute_avail): After constructing the value-handle
	expression, use try_combine_conversion to combine NOP_EXPRs
	with previous value-handle expressions and use the result if it
	is available.

	* gcc.dg/tree-ssa/ssa-fre-1.c: New testcase.
	* gcc.dg/tree-ssa/ssa-fre-2.c: Likewise.
	* 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.

From-SVN: r113527
This commit is contained in:
Richard Guenther 2006-05-04 13:56:52 +00:00 committed by Richard Biener
parent 4f72054bca
commit d818832cdd
8 changed files with 153 additions and 3 deletions

View File

@ -1,3 +1,16 @@
2006-05-04 Richard Guenther <rguenther@suse.de>
PR tree-optimization/14287
PR tree-optimization/14844
PR tree-optimization/19792
PR tree-optimization/21608
PR tree-optimization/27090
* tree-ssa-pre.c (try_combine_conversion): New function.
(compute_avail): After constructing the value-handle
expression, use try_combine_conversion to combine NOP_EXPRs
with previous value-handle expressions and use the result if it
is available.
2006-05-04 Joseph S. Myers <joseph@codesourcery.com>
* config/mips/linux64.h (DWARF_OFFSET_SIZE): Remove.

View File

@ -1,3 +1,16 @@
2006-05-04 Richard Guenther <rguenther@suse.de>
PR tree-optimization/14287
PR tree-optimization/14844
PR tree-optimization/19792
PR tree-optimization/21608
PR tree-optimization/27090
* gcc.dg/tree-ssa/ssa-fre-1.c: New testcase.
* gcc.dg/tree-ssa/ssa-fre-2.c: Likewise.
* 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.
2006-05-04 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/27285

View File

@ -0,0 +1,16 @@
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-fre-details" } */
/* From PR27090. */
int f(int *a)
{
int t = *a;
unsigned *b = (unsigned *)a;
int *c = (int*)b;
return *c + t;
}
/* { dg-final { scan-tree-dump "Replaced \\\(int \\\*\\\) b_.*with a_" "fre" } } */
/* { dg-final { scan-tree-dump "Replaced \\\*c_.*with t_" "fre" } } */
/* { dg-final { cleanup-tree-dump "fre" } } */

View File

@ -0,0 +1,18 @@
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-fre-details" } */
/* From PR14287. */
short g, h;
void
foo (long a)
{
short b = a & 3;
long c = b;
g = c;
h = c;
}
/* { dg-final { scan-tree-dump "Replaced \\\(short int\\\) c_.*with b_" "fre" } } */
/* { dg-final { cleanup-tree-dump "fre" } } */

View File

@ -0,0 +1,15 @@
/* { dg-do compile } */
/* { dg-options "-O -fwrapv -fdump-tree-fre-details" } */
/* From PR14844. */
int
foo (int a, int b)
{
long long aa = a;
long long bb = b;
return aa + bb;
}
/* { dg-final { scan-tree-dump "Replaced \\\(int\\\) aa_.*with a_" "fre" } } */
/* { dg-final { cleanup-tree-dump "fre" } } */

View File

@ -0,0 +1,15 @@
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-fre-details" } */
/* From PR21608. */
#define bool _Bool
static inline bool wrap(bool f) { return f; }
bool bar(bool f)
{
return wrap(f);
}
/* { dg-final { scan-tree-dump "Replaced \\\(_Bool\\\) D.*with f_" "fre" } } */
/* { dg-final { scan-tree-dump "Replaced \\\(int\\\) f_.*with D" "fre" } } */
/* { dg-final { cleanup-tree-dump "fre" } } */

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-O -fdump-tree-fre-details" } */
/* From PR19792. */
int
bar (unsigned int t)
{
int a = t;
return a == t;
}
/* { dg-final { scan-tree-dump "Replaced \\\(unsigned int\\\) a_.*with t_" "fre" } } */
/* { dg-final { cleanup-tree-dump "fre" } } */

View File

@ -3309,6 +3309,42 @@ realify_fake_stores (void)
}
}
/* Tree-combine a value number expression *EXPR_P that does a type
conversion with the value number expression of its operand.
Returns true, if *EXPR_P simplifies to a value number or
gimple min-invariant expression different from EXPR_P and
sets *EXPR_P to the simplified expression value number.
Otherwise returns false and does not change *EXPR_P. */
static bool
try_combine_conversion (tree *expr_p)
{
tree expr = *expr_p;
tree t;
if (!((TREE_CODE (expr) == NOP_EXPR
|| TREE_CODE (expr) == CONVERT_EXPR)
&& TREE_CODE (TREE_OPERAND (expr, 0)) == VALUE_HANDLE
&& !VALUE_HANDLE_VUSES (TREE_OPERAND (expr, 0))))
return false;
t = fold_unary (TREE_CODE (expr), TREE_TYPE (expr),
VALUE_HANDLE_EXPR_SET (TREE_OPERAND (expr, 0))->head->expr);
/* Disallow value expressions we have no value number for already, as
we would miss a leader for it here. */
if (t
&& !(TREE_CODE (t) == VALUE_HANDLE
|| is_gimple_min_invariant (t)))
t = vn_lookup (t, NULL);
if (t && t != expr)
{
*expr_p = t;
return true;
}
return false;
}
/* Compute the AVAIL set for all basic blocks.
@ -3433,9 +3469,19 @@ compute_avail (void)
tree newt = create_value_expr_from (rhs, block, stmt);
if (newt)
{
add_to_sets (lhs, newt, stmt, TMP_GEN (block),
AVAIL_OUT (block));
value_insert_into_set (EXP_GEN (block), newt);
/* If we can combine a conversion expression
with the expression for its operand just
record the value number for it. */
if (try_combine_conversion (&newt))
vn_add (lhs, newt);
else
{
tree val = vn_lookup_or_add (newt, stmt);
vn_add (lhs, val);
value_insert_into_set (EXP_GEN (block), newt);
}
bitmap_insert_into_set (TMP_GEN (block), lhs);
bitmap_value_insert_into_set (AVAIL_OUT (block), lhs);
continue;
}
}