There are a few issues with the code we generate for atomic operations and the way we generate it:
- Hard coded CR0 for compares
- Order of operands for compares not conducive to emitting compare-immediate or for CSE of compares
- Missing MachineMemOperand for st[bhwd]cx intrinsics
- A missing intrinsic property for the same
- Unnecessary blocks with store conditional instructions to clear reservation (which ends up hindering performance)
- Move from CR instructions just to compare the result of a store conditional with zero (even though it is a record-form)
This patch aims to resolve all of those issues.