<div dir="ltr"><div><div><div>I've already posted a patch (<a href="https://reviews.llvm.org/D41791">https://reviews.llvm.org/D41791</a>) to do this, but here's a bit of a background.<br><br></div>When the operands of an ISD::ATOMIC_CMP_SWAP{_WITH_SUCCESS} are legalized by promoting to a larger type, they're extended without specifying whether it's a sign or zero extension. However, an analogous node (SETCC) is legalized by zero-extending when the comparison code is for an equality comparison.<br><br></div>The current legalization scheme leads to a bug in the PPC back end when the input is a negative constant. Namely, the unspecified extension causes the constant to be materialized with a sign-extending instruction. However, the atomic load instruction is a zero-extending instruction. Then the comparison is done on a wider register, leading to a bug. Of course, this can be fixed in the PPC codegen, but I think it makes more sense to change how this is legalized since the underlying comparison is indeed an equality comparison.<br><br></div>Please let me know what you think. Also, if this is a direction we want to go in, I would appreciate it if people can review the changed test cases.<br></div>