===================================================================
@@ -3039,6 +3039,20 @@ inhibit_phi_insertion (basic_block bb, pre_expr ex
return false;
}
+static void
+insert_into_pred_update_location (edge pred, gimple_seq stmts)
+{
+ gimple_stmt_iterator gsi;
+ gimple stmt = last_stmt (pred->src);
+ location_t location = stmt ? gimple_location (stmt)
+ : UNKNOWN_LOCATION;
+ if (location != UNKNOWN_LOCATION)
+ for (gsi = gsi_start (stmts); !gsi_end_p (gsi); gsi_next (&gsi))
+ if (gimple_location (gsi_stmt (gsi)) == UNKNOWN_LOCATION)
+ gimple_set_location (gsi_stmt (gsi), location);
+ gsi_insert_seq_on_edge (pred, stmts);
+}
+
/* Insert the to-be-made-available values of expression EXPRNUM for each
predecessor, stored in AVAIL, into the predecessors of BLOCK, and
merge the result with a phi node, given the same value number as
@@ -3094,7 +3108,7 @@ insert_into_preds_of_block (basic_block block, uns
builtexpr = create_expression_by_pieces (bprime, eprime,
&stmts, type);
gcc_assert (!(pred->flags & EDGE_ABNORMAL));
- gsi_insert_seq_on_edge (pred, stmts);
+ insert_into_pred_update_location (pred, stmts);
VEC_replace (pre_expr, avail, pred->dest_idx,
get_or_alloc_expr_for_name (builtexpr));
insertions = true;
@@ -3132,7 +3146,7 @@ insert_into_preds_of_block (basic_block block, uns
SSA_NAME_VERSION (lhs));
gimple_set_plf (stmt, NECESSARY, false);
}
- gsi_insert_seq_on_edge (pred, stmts);
+ insert_into_pred_update_location (pred, stmts);
}
VEC_replace (pre_expr, avail, pred->dest_idx,
get_or_alloc_expr_for_name (forcedexpr));
@@ -3177,7 +3191,7 @@ insert_into_preds_of_block (basic_block block, uns
bitmap_set_bit (inserted_exprs, SSA_NAME_VERSION (lhs));
gimple_set_plf (stmt, NECESSARY, false);
}
- gsi_insert_seq_on_edge (pred, stmts);
+ insert_into_pred_update_location (pred, stmts);
}
VEC_replace (pre_expr, avail, pred->dest_idx,
get_or_alloc_expr_for_name (forcedexpr));
===================================================================
@@ -0,0 +1,18 @@
+// This test makes sure PRE will not optimize the debug info away.
+// { dg-do compile { target { i?86-*-* x86_64-*-* } } }
+// { dg-options "-O2 -g -dA" }
+extern int x;
+
+int abc (int *a)
+{
+ int ret = 0;
+
+ if (x > 0)
+ ret += *a;
+ else
+ a++;
+
+ ret += *a;
+ return ret;
+}
+// { dg-final { scan-assembler "pre.c:13" } }