This fixes https://bugs.llvm.org/show_bug.cgi?id=35812.
As it turns out, the PPC back end has a long-standing bug where the atomic compare and swap operation on sub-word sizes will do the wrong thing if the old value (and the comparand) is negative. The issue is that the old value we load will be zero-extended and the value we're comparing it to might be sign or zero extended. This is broken both with the old way of loading/masking the value as well as with the new way (using the lharx/lbarx that were introduced in ISA 2.07).
This patch simply zero extends the input value if it isn't already guaranteed to be zero extended.
I initially posted a fix for this in legalization, but there was at least one target that preferred that this be handled separately in each target rather than in target-independent legalization.