This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Allow to switch off thread-unsafe if-conversion optimizations

Followup of the discussion currently running on
(-fno-tree-cselim not working?).

The option name may need to be changed for a better one.

2007-10-27  Samuel Tardieu  <>

	* common.opt: New option -fthread-unsafe-if-conversion
	* ifcvt.c (noce_process_if_block): Do not allow if conversion of
	a test without a else part when -fthread-unsafe-if-conversion is
	set as an unnecessary read+write memory access may introduce a
	race condition.

diff --git a/gcc/common.opt b/gcc/common.opt
index c468b3b..44cfcbd 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -1148,6 +1148,11 @@ funsafe-loop-optimizations
 Common Report Var(flag_unsafe_loop_optimizations) Optimization
 Allow loop optimizations to assume that the loops behave in normal way
+Common Report Var(flag_thread_unsafe_if_conversion) Init(1) Optimization
+Allow the compiler to convert some tests in a way that may be unsafe in
+multi-threaded programs.
 Common Report Var(flag_associative_math)
 Allow optimization for floating-point arithmetic which may change the
diff --git a/gcc/ifcvt.c b/gcc/ifcvt.c
index 7810d7e..07dc4d8 100644
--- a/gcc/ifcvt.c
+++ b/gcc/ifcvt.c
@@ -2319,6 +2319,13 @@ noce_process_if_block (struct noce_if_info *if_info)
     goto success;
   if (! HAVE_conditional_execution)
+      /* If the test to convert has no else part, it is potentially
+	 thread-unsafe as it may introduce an extra read+write of an
+	 otherwise unreferenced variable. Do not convert if the user
+	 asked us not do to so.  */
+      if (if_info->insn_b == NULL_RTX && ! flag_thread_unsafe_if_conversion)
+	return FALSE;
       if (noce_try_store_flag_constants (if_info))
 	goto success;
       if (noce_try_addcc (if_info))

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]