https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80080
--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> --- I think it depends on what (success, old_reg) = compare-and-swap(mem, old_reg, new_reg) sets if success is true. Is there a guarantee that old_reg will be assigned whatever has been passed as the second argument in that case on all targets? If yes, then it can work. If not, then it will return a different value. So I think you need to analyze all targets that have HW compare-and-swap and verify that.