aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-pre.c
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2008-11-02 15:26:04 +0000
committerRichard Biener <rguenth@gcc.gnu.org>2008-11-02 15:26:04 +0000
commit40f64141b31a3e5e8102eed09e3c58c6ea7d3ac8 (patch)
tree7d774c5ca44289be14a3e90d232870e60aa071e5 /gcc/tree-ssa-pre.c
parent15fe850fe4e170adc06c9231173a55fd10b12b2d (diff)
downloadgcc-40f64141b31a3e5e8102eed09e3c58c6ea7d3ac8.zip
gcc-40f64141b31a3e5e8102eed09e3c58c6ea7d3ac8.tar.gz
gcc-40f64141b31a3e5e8102eed09e3c58c6ea7d3ac8.tar.bz2
re PR tree-optimization/37542 (PRE doesn't simplify during phi-translation)
2008-11-02 Richard Guenther <rguenther@suse.de> PR tree-optimization/37542 * tree-ssa-pre.c (fully_constant_expression): Handle more cases. * tree-ssa-sccvn.c (vn_get_expr_for): Fix typo. (vn_nary_op_lookup_stmt): Adjust for unary reference trees. (vn_nary_op_insert_stmt): Likewise. (visit_use): Likewise. * gcc.dg/tree-ssa/ssa-pre-22.c: New testcase. * gcc.c-torture/compile/20081101-1.c: Likewise. From-SVN: r141534
Diffstat (limited to 'gcc/tree-ssa-pre.c')
-rw-r--r--gcc/tree-ssa-pre.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/gcc/tree-ssa-pre.c b/gcc/tree-ssa-pre.c
index dc576c5..d881bf3 100644
--- a/gcc/tree-ssa-pre.c
+++ b/gcc/tree-ssa-pre.c
@@ -1088,47 +1088,59 @@ fully_constant_expression (pre_expr e)
vn_nary_op_t nary = PRE_EXPR_NARY (e);
switch (TREE_CODE_CLASS (nary->opcode))
{
+ case tcc_expression:
+ if (nary->opcode == TRUTH_NOT_EXPR)
+ goto do_unary;
+ if (nary->opcode != TRUTH_AND_EXPR
+ && nary->opcode != TRUTH_OR_EXPR
+ && nary->opcode != TRUTH_XOR_EXPR)
+ return e;
+ /* Fallthrough. */
case tcc_binary:
+ case tcc_comparison:
{
/* We have to go from trees to pre exprs to value ids to
constants. */
tree naryop0 = nary->op[0];
tree naryop1 = nary->op[1];
- tree const0, const1, result;
- if (is_gimple_min_invariant (naryop0))
- const0 = naryop0;
- else
+ tree result;
+ if (!is_gimple_min_invariant (naryop0))
{
pre_expr rep0 = get_or_alloc_expr_for (naryop0);
unsigned int vrep0 = get_expr_value_id (rep0);
- const0 = get_constant_for_value_id (vrep0);
+ tree const0 = get_constant_for_value_id (vrep0);
+ if (const0)
+ naryop0 = fold_convert (TREE_TYPE (naryop0), const0);
}
- if (is_gimple_min_invariant (naryop1))
- const1 = naryop1;
- else
+ if (!is_gimple_min_invariant (naryop1))
{
pre_expr rep1 = get_or_alloc_expr_for (naryop1);
unsigned int vrep1 = get_expr_value_id (rep1);
- const1 = get_constant_for_value_id (vrep1);
- }
- result = NULL;
- if (const0 && const1)
- {
- tree type1 = TREE_TYPE (nary->op[0]);
- tree type2 = TREE_TYPE (nary->op[1]);
- const0 = fold_convert (type1, const0);
- const1 = fold_convert (type2, const1);
- result = fold_binary (nary->opcode, nary->type, const0,
- const1);
+ tree const1 = get_constant_for_value_id (vrep1);
+ if (const1)
+ naryop1 = fold_convert (TREE_TYPE (naryop1), const1);
}
+ result = fold_binary (nary->opcode, nary->type,
+ naryop0, naryop1);
if (result && is_gimple_min_invariant (result))
return get_or_alloc_expr_for_constant (result);
+ /* We might have simplified the expression to a
+ SSA_NAME for example from x_1 * 1. But we cannot
+ insert a PHI for x_1 unconditionally as x_1 might
+ not be available readily. */
return e;
}
+ case tcc_reference:
+ if (nary->opcode != REALPART_EXPR
+ && nary->opcode != IMAGPART_EXPR
+ && nary->opcode != VIEW_CONVERT_EXPR)
+ return e;
+ /* Fallthrough. */
case tcc_unary:
+do_unary:
{
- /* We have to go from trees to pre exprs to value ids to
- constants. */
+ /* We have to go from trees to pre exprs to value ids to
+ constants. */
tree naryop0 = nary->op[0];
tree const0, result;
if (is_gimple_min_invariant (naryop0))
@@ -1146,7 +1158,6 @@ fully_constant_expression (pre_expr e)
const0 = fold_convert (type1, const0);
result = fold_unary (nary->opcode, nary->type, const0);
}
-
if (result && is_gimple_min_invariant (result))
return get_or_alloc_expr_for_constant (result);
return e;