On 11/25/2015 04:00 PM, Jakub Jelinek wrote:
nonfreeing_call_p is one necessary condition (if that is true, it means the call could mean that the first access does not trap while the second one does). But I agree that we need a predicate for nonbarrier_call_p or similar. Some atomic builtins are not barriers though and IMHO should not be treated as such, at least relaxed atomic loads/stores and pehraps even other relaxed atomics. And it would be nice to have IPA discovery of nonbarrier_call_p calls, like we have for nonfreeing_fn.
So here's a very basic version which I think is appropriate for the current stage, and can be extended later. Ok if it passes testing?
Bernd
diff --git a/gcc/gimple.c b/gcc/gimple.c index 2764df8..bf552a7 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -2636,6 +2636,18 @@ nonfreeing_call_p (gimple *call) return n->nonfreeing_fn; } +/* Return true when CALL is a call stmt that definitely need not + be considered to be a memory barrier. */ +bool +nonbarrier_call_p (gimple *call) +{ + if (gimple_call_flags (call) & (ECF_PURE | ECF_CONST)) + return true; + /* Should extend this to have a nonbarrier_fn flag, just as above in + the nonfreeing case. */ + return false; +} + /* Callback for walk_stmt_load_store_ops. Return TRUE if OP will dereference the tree stored in DATA, FALSE diff --git a/gcc/gimple.h b/gcc/gimple.h index 6eb22de..0b04804 100644 --- a/gcc/gimple.h +++ b/gcc/gimple.h @@ -1507,6 +1507,7 @@ extern bool gimple_call_builtin_p (const gimple *, enum built_in_function); extern bool gimple_asm_clobbers_memory_p (const gasm *); extern void dump_decl_set (FILE *, bitmap); extern bool nonfreeing_call_p (gimple *); +extern bool nonbarrier_call_p (gimple *); extern bool infer_nonnull_range (gimple *, tree); extern bool infer_nonnull_range_by_dereference (gimple *, tree); extern bool infer_nonnull_range_by_attribute (gimple *, tree); diff --git a/gcc/tree-ssa-phiopt.c b/gcc/tree-ssa-phiopt.c index 02d5aa0..56b3732 100644 --- a/gcc/tree-ssa-phiopt.c +++ b/gcc/tree-ssa-phiopt.c @@ -1519,7 +1519,10 @@ nontrapping_dom_walker::before_dom_children (basic_block bb) { gimple *stmt = gsi_stmt (gsi); - if (is_gimple_call (stmt) && !nonfreeing_call_p (stmt)) + if (gimple_code (stmt) == GIMPLE_ASM + || (is_gimple_call (stmt) + && (!nonfreeing_call_p (stmt) + || !nonbarrier_call_p (stmt)))) nt_call_phase++; else if (gimple_assign_single_p (stmt) && !gimple_has_volatile_ops (stmt)) {