builtins.c (expand_builtin_compare_and_swap): If target is const0, don't pass the...
authorRichard Henderson <rth@redhat.com>
Sat, 12 Nov 2011 17:17:54 +0000 (09:17 -0800)
committerRichard Henderson <rth@gcc.gnu.org>
Sat, 12 Nov 2011 17:17:54 +0000 (09:17 -0800)
        * builtins.c (expand_builtin_compare_and_swap): If target is const0,
        don't pass the target to expand_atomic_compare_and_swap.
        (expand_builtin_atomic_compare_exchange): Likewise.

From-SVN: r181323

gcc/ChangeLog
gcc/builtins.c

index 4a9a5d346d2dcc6a04eeb055d9375039223601a2..3f72d60cd2dbacf66c48b2e623a14d504ce1345d 100644 (file)
@@ -1,5 +1,9 @@
 2011-11-12  Richard Henderson  <rth@redhat.com>
 
+       * builtins.c (expand_builtin_compare_and_swap): If target is const0,
+       don't pass the target to expand_atomic_compare_and_swap.
+       (expand_builtin_atomic_compare_exchange): Likewise.
+
        * config/sh/linux.h (TARGET_INIT_LIBFUNCS): New.
        * config/sh/sh.c (sh_init_sync_libfuncs): New.
 
index 98dc63604e7c3fe0b161554d8e9f119143a1a847..9dc68cc341f069d964996cff612e9cb54c76b0d8 100644 (file)
@@ -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);