* imported qemu/hotfix-glibc-2.41.patch
[t2sde.git] / package / develop / gcc / hotfix-revert-atomics.patch.microblaze
blobb91d36b21e96fc53f13ef28e972c104477e3dbc2
1 # --- T2-COPYRIGHT-NOTE-BEGIN ---
2 # T2 SDE: package/*/gcc/hotfix-revert-atomics.patch.microblaze
3 # Copyright (C) 2024 The T2 SDE Project
4
5 # This Copyright note is generated by scripts/Create-CopyPatch,
6 # more information can be found in the files COPYING and README.
7
8 # This patch file is dual-licensed. It is available under the license the
9 # patched project is licensed under, as long as it is an OpenSource license
10 # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
11 # of the GNU General Public License version 2 as used by the T2 SDE.
12 # --- T2-COPYRIGHT-NOTE-END ---
14 diff --git a/gcc/builtins.cc b/gcc/builtins.cc
15 index 40dfd36a319..6e4274bb2a4 100644
16 --- a/gcc/builtins.cc
17 +++ b/gcc/builtins.cc
18 @@ -8387,10 +8387,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode,
19        break;
21      case BUILT_IN_ATOMIC_TEST_AND_SET:
22 -      target = expand_builtin_atomic_test_and_set (exp, target);
23 -      if (target)
24 -       return target;
25 -      break;
26 +      return expand_builtin_atomic_test_and_set (exp, target);
28      case BUILT_IN_ATOMIC_CLEAR:
29        return expand_builtin_atomic_clear (exp);
30 diff --git a/gcc/optabs.cc b/gcc/optabs.cc
31 index e1898da2280..8b96f23aec0 100644
32 --- a/gcc/optabs.cc
33 +++ b/gcc/optabs.cc
34 @@ -7080,17 +7080,25 @@ expand_atomic_test_and_set (rtx target, rtx mem, enum memmodel model)
35    /* Recall that the legacy lock_test_and_set optab was allowed to do magic
36       things with the value 1.  Thus we try again without trueval.  */
37    if (!ret && targetm.atomic_test_and_set_trueval != 1)
38 +    ret = maybe_emit_sync_lock_test_and_set (subtarget, mem, const1_rtx, model);
40 +  /* Failing all else, assume a single threaded environment and simply
41 +     perform the operation.  */
42 +  if (!ret)
43      {
44 -      ret = maybe_emit_sync_lock_test_and_set (subtarget, mem, const1_rtx, model);
45 +      /* If the result is ignored skip the move to target.  */
46 +      if (subtarget != const0_rtx)
47 +        emit_move_insn (subtarget, mem);
49 -      if (ret)
50 -       {
51 -         /* Rectify the not-one trueval.  */
52 -         ret = emit_store_flag_force (target, NE, ret, const0_rtx, mode, 0, 1);
53 -         gcc_assert (ret);
54 -       }
55 +      emit_move_insn (mem, trueval);
56 +      ret = subtarget;
57      }
59 +  /* Recall that have to return a boolean value; rectify if trueval
60 +     is not exactly one.  */
61 +  if (targetm.atomic_test_and_set_trueval != 1)
62 +    ret = emit_store_flag_force (target, NE, ret, const0_rtx, mode, 0, 1);
63 +  
64    return ret;
65  }