diff mbox

[0/4,CFT] Handle legacy __sync libcalls

Message ID 4EBE9748.5040300@redhat.com
State New
Headers show

Commit Message

Richard Henderson Nov. 12, 2011, 3:56 p.m. UTC
On 11/11/2011 07:39 PM, Kaz Kojima wrote:
> It seems that expand_builtin sets "target" variable to
> const0_trx when "ignore" argument is set and this causes
> the above ICE.  I'm trying a patch ...

I think the fix belongs in expand_builtin_compare_and_swap.
I'm testing the following.


r~

Comments

Richard Henderson Nov. 12, 2011, 5:22 p.m. UTC | #1
On 11/12/2011 07:56 AM, Richard Henderson wrote:
> On 11/11/2011 07:39 PM, Kaz Kojima wrote:
>> It seems that expand_builtin sets "target" variable to
>> const0_trx when "ignore" argument is set and this causes
>> the above ICE.  I'm trying a patch ...
> 
> I think the fix belongs in expand_builtin_compare_and_swap.
> I'm testing the following.

Full test completed on x86_64-linux.  I verified that the test
you mentioned no longer ICEs on sh4-linux.

Committed.


r~
Kaz Kojima Nov. 13, 2011, 12:24 a.m. UTC | #2
Richard Henderson <rth@redhat.com> wrote:
>> I think the fix belongs in expand_builtin_compare_and_swap.
>> I'm testing the following.
> 
> Full test completed on x86_64-linux.  I verified that the test
> you mentioned no longer ICEs on sh4-linux.
> 
> Committed.

Thanks!

Regards,
	kaz
diff mbox

Patch

diff --git a/gcc/builtins.c b/gcc/builtins.c
index 98dc636..9dc68cc 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -5144,7 +5144,6 @@  expand_builtin_sync_operation (enum machine_mode mode, tree exp,
 	case BUILT_IN_SYNC_FETCH_AND_NAND_4:
 	case BUILT_IN_SYNC_FETCH_AND_NAND_8:
 	case BUILT_IN_SYNC_FETCH_AND_NAND_16:
-
 	  if (warned_f_a_n)
 	    break;
 
@@ -5158,7 +5157,6 @@  expand_builtin_sync_operation (enum machine_mode mode, tree exp,
 	case BUILT_IN_SYNC_NAND_AND_FETCH_4:
 	case BUILT_IN_SYNC_NAND_AND_FETCH_8:
 	case BUILT_IN_SYNC_NAND_AND_FETCH_16:
-
 	  if (warned_n_a_f)
 	    break;
 
@@ -5190,16 +5188,24 @@  expand_builtin_compare_and_swap (enum machine_mode mode, tree exp,
 				 bool is_bool, rtx target)
 {
   rtx old_val, new_val, mem;
+  rtx *pbool, *poval;
 
   /* Expand the operands.  */
   mem = get_builtin_sync_mem (CALL_EXPR_ARG (exp, 0), mode);
   old_val = expand_expr_force_mode (CALL_EXPR_ARG (exp, 1), mode);
   new_val = expand_expr_force_mode (CALL_EXPR_ARG (exp, 2), mode);
 
-  if (!expand_atomic_compare_and_swap ((is_bool ? &target : NULL),
-				       (is_bool ? NULL : &target),
-				       mem, old_val, new_val, false,
-				       MEMMODEL_SEQ_CST, MEMMODEL_SEQ_CST))
+  pbool = poval = NULL;
+  if (target != const0_rtx)
+    {
+      if (is_bool)
+	pbool = &target;
+      else
+	poval = &target;
+    }
+  if (!expand_atomic_compare_and_swap (pbool, poval, mem, old_val, new_val,
+				       false, MEMMODEL_SEQ_CST,
+				       MEMMODEL_SEQ_CST))
     return NULL_RTX;
 
   return target;
@@ -5338,8 +5344,9 @@  expand_builtin_atomic_compare_exchange (enum machine_mode mode, tree exp,
 
   oldval = copy_to_reg (gen_rtx_MEM (mode, expect));
 
-  if (!expand_atomic_compare_and_swap (&target, &oldval, mem, oldval,
-				       desired, is_weak, success, failure))
+  if (!expand_atomic_compare_and_swap ((target == const0_rtx ? NULL : &target),
+				       &oldval, mem, oldval, desired,
+				       is_weak, success, failure))
     return NULL_RTX;
 
   emit_move_insn (gen_rtx_MEM (mode, expect), oldval);