https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109930

            Bug ID: 109930
           Summary: transform atomic exchange to unconditional store when
                    old value is unused?
           Product: gcc
           Version: 13.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Simon.Richter at hogyros dot de
  Target Milestone: ---

I'm not sure if that is a valid substitution, but...

I have a state machine that has a few transitions where I already know the old
state, so I can simply do an unconditional store, but I'd also like to have an
assertion on the old state in my debug version:

    std::atomic<uint32_t> x;

    /* ... */

    auto old_value = x.exchange(5);
    assert(old_value == 3);

with NDEBUG set, the assert is omitted, and no one is interested in the old
value, so the load-with-reserve can be omitted and the store-conditional
replaced with a regular store, and this should still be semantically
equivalent.

Reply via email to