--- /dev/null
+/* { dg-do compile } */
+/* { dg-options "-Os -fdump-tree-pre-stats -fdump-tree-optimized" } */
+
+void foo(void);
+static int c = 76, f, g;
+static int *h, *j, *k = &g;
+static int **i = &h;
+static short a;
+static signed char(l)(signed char b) {
+ if (!(((b) >= 77) && ((b) <= 77))) {
+ __builtin_unreachable();
+ }
+ return 0;
+}
+static short(m)(short d, short e) { return d + e; }
+static short n(signed char) {
+ j = *i;
+ if (j == 0)
+ ;
+ else
+ *i = 0;
+ *k = 0;
+ return 0;
+}
+static signed char o() {
+ l(0);
+ return 0;
+}
+static signed char p(int ad) {
+ a = m(!0, ad);
+ l(a);
+ if (f) {
+ *i &&n(o());
+ *i = 0;
+ } else
+ n(0);
+ if (h == &f || h == 0)
+ ;
+ else
+ foo();
+ return 0;
+}
+int main() {
+ p(c);
+ c = 8;
+}
+
+/* Even with main being cold we should optimize the redundant load of h
+ which is available on all incoming edges (but none considered worth
+ optimizing for speed) when doing that doesn't needlessly increase
+ code size. */
+
+/* { dg-final { scan-tree-dump "Insertions: 1" "pre" } } */
+/* { dg-final { scan-tree-dump "HOIST inserted: 1" "pre" } } */
+/* { dg-final { scan-tree-dump "Eliminated: 3" "pre" } } */
+/* { dg-final { scan-tree-dump-not "foo" "optimized" } } */
bool by_some = false;
bool cant_insert = false;
bool all_same = true;
+ unsigned num_inserts = 0;
+ unsigned num_const = 0;
pre_expr first_s = NULL;
edge pred;
basic_block bprime;
{
avail[pred->dest_idx] = eprime;
all_same = false;
+ num_inserts++;
}
else
{
avail[pred->dest_idx] = edoubleprime;
by_some = true;
+ if (edoubleprime->kind == CONSTANT)
+ num_const++;
/* We want to perform insertions to remove a redundancy on
a path in the CFG we want to optimize for speed. */
if (optimize_edge_for_speed_p (pred))
partially redundant. */
if (!cant_insert && !all_same && by_some)
{
+ /* If the expression is redundant on all edges and we need
+ to at most insert one copy from a constant do the PHI
+ insertion even when not optimizing a path that's to be
+ optimized for speed. */
+ if (num_inserts == 0 && num_const <= 1)
+ do_insertion = true;
if (!do_insertion)
{
if (dump_file && (dump_flags & TDF_DETAILS))