We only generate LOCKed versions of add/sub when the result is unused. It often happens that the result is used, but only by a comparison. We can optimize those out by reusing EFLAGS, which lets us use the proper instructions, instead of having to fallback to LXADD.
Instead of doing this as an MI peephole (as we do for the other non-LOCKed (really, non-MR) forms), do it in ISel. It becomes quite tricky later.
This also makes it possible to stop expanding and/or/xor if the only user is an icmp. I'm a little uncomfortable with the coupling, but I can send a patch if there are no objections?
Note that this builds on several local patches that I can commit right now if desired: I moved the LOCK isel from DAGToDAG to ISelLowering and tablegen. I added the atomic-eflags-update.ll file and split it out to make it easier to review; I'll squash it when committing.
Also, I locally added a combine to canonicalize (LSUB x, c) to (LADD x, -c), but only if c is 1 (to simplify matching INC/DEC). Any objections to generalizing that to any constant? (we do the same for ISD::SUB).