@jyknight I created an alternative implementation trying to mimic LLVM’s BuildLibCall.h. That is, a single standalone function that decides how to emit a generic compare-exchange instruction taking target information into account.
As you may see there is a lot more complexity than bitcasting and type-size. Please let me know what you think.