+2017-05-03 Jeff Law <law@redhat.com>
+
+ PR tree-optimization/78496
+ * tree-vrp.c (simplify_cond_using_ranges_1): Renamed
+ from simplify_cond_using_ranges. Split off code to walk
+ backwards through casts into ...
+ (simplify_cond_using_ranges_2): New function.
+ (simplify_stmt_using_ranges): Call simplify_cond_using_ranges_1.
+ (execute_vrp): After identifying jump threads, call
+ simplify_cond_using_ranges_2.
+
2017-05-03 Jan Hubicka <hubicka@ucw.cz>
PR bootstrap/80609
--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-vrp1" } */
+
+/* We should thread the if (!in_loop) completely leaving
+ just two conditionals. */
+/* { dg-final { scan-tree-dump-times "if \\(" 2 "vrp1" } } */
+
+
+union tree_node;
+typedef union tree_node *tree;
+
+enum size_type_kind
+{
+ SIZETYPE,
+ SSIZETYPE,
+ BITSIZETYPE,
+ SBITSIZETYPE,
+ TYPE_KIND_LAST
+};
+extern tree size_int_kind (long, enum size_type_kind);
+
+
+
+typedef struct
+{
+
+ tree base, step;
+
+} affine_iv;
+
+struct loop
+{
+
+ int num;
+};
+extern unsigned char simple_iv ();
+
+unsigned char
+dr_analyze_innermost (struct loop *loop, tree poffset)
+{
+ affine_iv offset_iv;
+ unsigned char in_loop = (loop && loop->num);
+
+
+ if (in_loop)
+ simple_iv ();
+
+ if (!in_loop)
+ offset_iv.step = size_int_kind (0, SSIZETYPE);
+
+}
the original conditional. */
static bool
-simplify_cond_using_ranges (gcond *stmt)
+simplify_cond_using_ranges_1 (gcond *stmt)
{
tree op0 = gimple_cond_lhs (stmt);
tree op1 = gimple_cond_rhs (stmt);
}
}
}
+ return false;
+}
+
+/* STMT is a conditional at the end of a basic block.
+
+ If the conditional is of the form SSA_NAME op constant and the SSA_NAME
+ was set via a type conversion, try to replace the SSA_NAME with the RHS
+ of the type conversion. Doing so makes the conversion dead which helps
+ subsequent passes. */
+
+static void
+simplify_cond_using_ranges_2 (gcond *stmt)
+{
+ tree op0 = gimple_cond_lhs (stmt);
+ tree op1 = gimple_cond_rhs (stmt);
+ enum tree_code cond_code = gimple_cond_code (stmt);
/* If we have a comparison of an SSA_NAME (OP0) against a constant,
see if OP0 was set by a type conversion where the source of
if (!is_gimple_assign (def_stmt)
|| !CONVERT_EXPR_CODE_P (gimple_assign_rhs_code (def_stmt)))
- return false;
+ return;
innerop = gimple_assign_rhs1 (def_stmt);
tree newconst = fold_convert (TREE_TYPE (innerop), op1);
gimple_cond_set_lhs (stmt, innerop);
gimple_cond_set_rhs (stmt, newconst);
- return true;
+ update_stmt (stmt);
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Folded into: ");
+ print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
+ fprintf (dump_file, "\n");
+ }
}
}
}
-
- return false;
}
/* Simplify a switch statement using the value range of the switch
}
}
else if (gimple_code (stmt) == GIMPLE_COND)
- return simplify_cond_using_ranges (as_a <gcond *> (stmt));
+ return simplify_cond_using_ranges_1 (as_a <gcond *> (stmt));
else if (gimple_code (stmt) == GIMPLE_SWITCH)
return simplify_switch_using_ranges (as_a <gswitch *> (stmt));
else if (is_gimple_call (stmt)
the datastructures built by VRP. */
identify_jump_threads ();
+ /* A comparison of an SSA_NAME against a constant where the SSA_NAME
+ was set by a type conversion can often be rewritten to use the
+ RHS of the type conversion.
+
+ However, doing so inhibits jump threading through the comparison.
+ So that transformation is not performed until after jump threading
+ is complete. */
+ basic_block bb;
+ FOR_EACH_BB_FN (bb, cfun)
+ {
+ gimple *last = last_stmt (bb);
+ if (last && gimple_code (last) == GIMPLE_COND)
+ simplify_cond_using_ranges_2 (as_a <gcond *> (last));
+ }
+
vrp_free_lattice ();
free_numbers_of_iterations_estimates (cfun);