-/* { dg-options "-Os -fdump-tree-pre-details -fdisable-tree-evrp -fno-tree-dse" } */
+/* { dg-options "-Os -fgimple -fdump-tree-pre-details -fdisable-tree-evrp -fno-tree-dse" } */
+#if __SIZEOF_INT__ == 2
+#define unsigned __UINT32_TYPE__
+#define int __INT32_TYPE__
+#endif
+
+unsigned a;
+int b, c;
+
+void __GIMPLE(ssa, startwith("pre")) fn2 ()
+{
+ int b_lsm6;
+ int j;
+ int c0_1;
+ int iftmp2_8;
+
+ __BB(2):
+ a = _Literal (unsigned)30;
+ c0_1 = c;
+ b_lsm6_9 = b;
+ goto __BB7;
+
+ __BB(3):
+ if (j_6(D) != 2147483647)
+ goto __BB4;
+ else
+ goto __BB5;
+
+ __BB(4):
+ iftmp2_8 = j_6(D) + 1;
+ goto __BB5;
+
+ __BB(5):
+ b_lsm6_10 = 2147483647;
+ goto __BB6;
+
+ __BB(6):
+ if (c0_1 != 0)
+ goto __BB3;
+ else
+ goto __BB8;
+
+ __BB(8):
+ goto __BB7;
+
+ __BB(7):
+ goto __BB6;
+
+}
+
+#if 0
+/* This used to be a C based testcase but ccp3 would now would remove
+ the setting of iftmp2_8 (in the above gimple) which would cause PRE
+ not to test what PRE was doing incorrectly. The original code is below. */
/* Disable tree-evrp because the new version of evrp sees
<bb 3> :
if (j_8(D) != 2147483647)
/* Likewise disable DSE which also elides the tail merging "opportunity". */
-#if __SIZEOF_INT__ == 2
-#define unsigned __UINT32_TYPE__
-#define int __INT32_TYPE__
-#endif
-
-unsigned a;
-int b, c;
-
static int
fn1 (int p1, int p2)
{
for (; c; b = fn1 (j, 1))
;
}
+#endif
/* { dg-final { scan-tree-dump-times "(?n)find_duplicates: <bb .*> duplicate of <bb .*>" 1 "pre" } } */
/* { dg-do compile { target i?86-*-* x86_64-*-* powerpc*-*-* aarch64*-*-* } } */
/* { dg-options "-O2 -fdump-tree-optimized -fcompare-debug" } */
/* { dg-additional-options "-march=i686" { target ia32 } } */
-/* { dg-final { scan-tree-dump-not "__atomic_fetch_" "optimized" } } */
-/* { dg-final { scan-tree-dump-not "__sync_fetch_and_" "optimized" } } */
+/* Note the choice between __atomic_fetch_and_* and __atomic_and_*_fetch
+ if the result is not used does not matter. so check if make sure we don't
+ have __atomic_fetch_ with an assignment */
+/* { dg-final { scan-tree-dump-not "= __atomic_fetch_" "optimized" } } */
+/* { dg-final { scan-tree-dump-not "= __sync_fetch_and_" "optimized" } } */
typedef signed char schar;
typedef unsigned long ulong;
#include "cfgloop.h"
#include "tree-cfgcleanup.h"
#include "cfganal.h"
+#include "tree-ssa-dce.h"
/* This file implements a generic value propagation engine based on
the same propagation used by the SSA-CCP algorithm [1].
long num_const_prop;
long num_copy_prop;
long num_stmts_folded;
- long num_dce;
};
static struct prop_stats_d prop_stats;
something_changed (false),
substitute_and_fold_engine (engine)
{
- stmts_to_remove.create (0);
+ dceworklist = BITMAP_ALLOC (NULL);
stmts_to_fixup.create (0);
need_eh_cleanup = BITMAP_ALLOC (NULL);
need_ab_cleanup = BITMAP_ALLOC (NULL);
}
~substitute_and_fold_dom_walker ()
{
- stmts_to_remove.release ();
+ BITMAP_FREE (dceworklist);
stmts_to_fixup.release ();
BITMAP_FREE (need_eh_cleanup);
BITMAP_FREE (need_ab_cleanup);
}
bool something_changed;
- vec<gimple *> stmts_to_remove;
+ bitmap dceworklist;
vec<gimple *> stmts_to_fixup;
bitmap need_eh_cleanup;
bitmap need_ab_cleanup;
print_generic_expr (dump_file, sprime);
fprintf (dump_file, "\n");
}
- stmts_to_remove.safe_push (phi);
+ bitmap_set_bit (dceworklist, SSA_NAME_VERSION (res));
continue;
}
}
print_generic_expr (dump_file, sprime);
fprintf (dump_file, "\n");
}
- stmts_to_remove.safe_push (stmt);
+ bitmap_set_bit (dceworklist, SSA_NAME_VERSION (lhs));
continue;
}
}
substitute_and_fold_dom_walker walker (CDI_DOMINATORS, this);
walker.walk (block ? block : ENTRY_BLOCK_PTR_FOR_FN (cfun));
- /* We cannot remove stmts during the BB walk, especially not release
- SSA names there as that destroys the lattice of our callers.
- Remove stmts in reverse order to make debug stmt creation possible. */
- while (!walker.stmts_to_remove.is_empty ())
- {
- gimple *stmt = walker.stmts_to_remove.pop ();
- if (dump_file && dump_flags & TDF_DETAILS)
- {
- fprintf (dump_file, "Removing dead stmt ");
- print_gimple_stmt (dump_file, stmt, 0);
- fprintf (dump_file, "\n");
- }
- prop_stats.num_dce++;
- gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
- if (gimple_code (stmt) == GIMPLE_PHI)
- remove_phi_node (&gsi, true);
- else
- {
- unlink_stmt_vdef (stmt);
- gsi_remove (&gsi, true);
- release_defs (stmt);
- }
- }
-
+ simple_dce_from_worklist (walker.dceworklist, walker.need_eh_cleanup);
if (!bitmap_empty_p (walker.need_eh_cleanup))
gimple_purge_all_dead_eh_edges (walker.need_eh_cleanup);
if (!bitmap_empty_p (walker.need_ab_cleanup))
prop_stats.num_copy_prop);
statistics_counter_event (cfun, "Statements folded",
prop_stats.num_stmts_folded);
- statistics_counter_event (cfun, "Statements deleted",
- prop_stats.num_dce);
return walker.something_changed;
}