--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-phiopt1-details-stats" } */
+/* PR tree-optimization/122155 */
+
+void f(int *a, int b, int c)
+{
+ if (c)
+ *a = b;
+ else
+ *a = b;
+}
+
+/* When commonalizing a store with the same rhs, a PHI does not need to be created. */
+/* { dg-final { scan-tree-dump "if-then-else store replacement: 1" "phiopt1" } } */
+/* { dg-final { scan-tree-dump-not "to use phi:" "phiopt1" } } */
+/* { dg-final { scan-tree-dump-not "PHI <" "phiopt1" } } */
tree lhs_base, lhs, then_rhs, else_rhs, name;
location_t then_locus, else_locus;
gimple_stmt_iterator gsi;
- gphi *newphi;
+ gphi *newphi = nullptr;
gassign *new_stmt;
- bool empty_constructor = false;
if (then_assign == NULL
|| !gimple_assign_single_p (then_assign)
/* Currently only handle commoning of `= {}`. */
if (TREE_CODE (then_rhs) != CONSTRUCTOR)
return false;
- empty_constructor = true;
}
if (dump_file && (dump_flags & TDF_DETAILS))
/* 2) Create a PHI node at the join block, with one argument
holding the old RHS, and the other holding the temporary
where we stored the old memory contents. */
- if (empty_constructor)
- name = unshare_expr (then_rhs);
+ if (operand_equal_p (then_rhs, else_rhs))
+ name = then_rhs;
else
{
name = make_temp_ssa_name (TREE_TYPE (lhs), NULL, "cstore");
update_stmt (vphi);
if (dump_file && (dump_flags & TDF_DETAILS))
{
- if (!empty_constructor)
+ if (newphi)
{
fprintf(dump_file, "to use phi:\n");
print_gimple_stmt (dump_file, newphi, 0,