# --- T2-COPYRIGHT-NOTE-BEGIN --- # T2 SDE: package/*/gcc/hotfix-revert-atomics.patch.microblaze # Copyright (C) 2024 The T2 SDE Project # # This Copyright note is generated by scripts/Create-CopyPatch, # more information can be found in the files COPYING and README. # # This patch file is dual-licensed. It is available under the license the # patched project is licensed under, as long as it is an OpenSource license # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms # of the GNU General Public License version 2 as used by the T2 SDE. # --- T2-COPYRIGHT-NOTE-END --- diff --git a/gcc/builtins.cc b/gcc/builtins.cc index 40dfd36a319..6e4274bb2a4 100644 --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -8387,10 +8387,7 @@ expand_builtin (tree exp, rtx target, rtx subtarget, machine_mode mode, break; case BUILT_IN_ATOMIC_TEST_AND_SET: - target = expand_builtin_atomic_test_and_set (exp, target); - if (target) - return target; - break; + return expand_builtin_atomic_test_and_set (exp, target); case BUILT_IN_ATOMIC_CLEAR: return expand_builtin_atomic_clear (exp); diff --git a/gcc/optabs.cc b/gcc/optabs.cc index e1898da2280..8b96f23aec0 100644 --- a/gcc/optabs.cc +++ b/gcc/optabs.cc @@ -7080,17 +7080,25 @@ expand_atomic_test_and_set (rtx target, rtx mem, enum memmodel model) /* Recall that the legacy lock_test_and_set optab was allowed to do magic things with the value 1. Thus we try again without trueval. */ if (!ret && targetm.atomic_test_and_set_trueval != 1) + ret = maybe_emit_sync_lock_test_and_set (subtarget, mem, const1_rtx, model); + + /* Failing all else, assume a single threaded environment and simply + perform the operation. */ + if (!ret) { - ret = maybe_emit_sync_lock_test_and_set (subtarget, mem, const1_rtx, model); + /* If the result is ignored skip the move to target. */ + if (subtarget != const0_rtx) + emit_move_insn (subtarget, mem); - if (ret) - { - /* Rectify the not-one trueval. */ - ret = emit_store_flag_force (target, NE, ret, const0_rtx, mode, 0, 1); - gcc_assert (ret); - } + emit_move_insn (mem, trueval); + ret = subtarget; } + /* Recall that have to return a boolean value; rectify if trueval + is not exactly one. */ + if (targetm.atomic_test_and_set_trueval != 1) + ret = emit_store_flag_force (target, NE, ret, const0_rtx, mode, 0, 1); + return ret; }