[GlobalISel] LegalizationArtifactCombiner: Elide redundant G_AND

The legalizer currently generates lots of G_AND artifacts.
For example between boolean uses and defs there is always a G_AND with a mask of 1, but when the target uses ZeroOrOneBooleanContents, this is unnecessary.
Currently these artifacts have to be removed using post-legalize combines.
Omitting these artifacts at their source in the artifact combiner has a few advantages:
- We know that the emitted G_AND is very likely to be useless, so our KnownBits call is likely worth it.
- The G_AND and G_CONSTANT can interrupt e.g. G_UADDE/... sequences generated during legalization of wide adds which makes it harder to detect these sequences in the instruction selector (e.g. useful to prevent unnecessary reloading of AArch64 NZCV register).
- This cleans up a lot of legalizer output and even improves compilation-times.
AArch64 CTMark geomean: `O0` -5.6% size..text; `O0` and `O3` ~-0.9% compilation-time (instruction count).

Since this introduces KnownBits into code-paths used by `O0`, I reduced the default recursion depth.
This doesn't seem to make a difference in CTMark, but should prevent excessive recursive calls in the worst case.

Reviewed By: aemerson

Differential Revision: https://reviews.llvm.org/D159140

GitOrigin-RevId: 3686a0b611c65f0d7190345b8e3e73cdca9fa657
diff --git a/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h b/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
index eff87c5..ea75c2c 100644
--- a/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
+++ b/include/llvm/CodeGen/GlobalISel/GISelKnownBits.h
@@ -118,11 +118,7 @@
   GISelKnownBitsAnalysis() : MachineFunctionPass(ID) {
     initializeGISelKnownBitsAnalysisPass(*PassRegistry::getPassRegistry());
   }
-  GISelKnownBits &get(MachineFunction &MF) {
-    if (!Info)
-      Info = std::make_unique<GISelKnownBits>(MF);
-    return *Info.get();
-  }
+  GISelKnownBits &get(MachineFunction &MF);
   void getAnalysisUsage(AnalysisUsage &AU) const override;
   bool runOnMachineFunction(MachineFunction &MF) override;
   void releaseMemory() override { Info.reset(); }
diff --git a/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h b/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
index 7ccb99d..90b6277 100644
--- a/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
+++ b/include/llvm/CodeGen/GlobalISel/LegalizationArtifactCombiner.h
@@ -35,6 +35,7 @@
   MachineIRBuilder &Builder;
   MachineRegisterInfo &MRI;
   const LegalizerInfo &LI;
+  GISelKnownBits *KB;
 
   static bool isArtifactCast(unsigned Opc) {
     switch (Opc) {
@@ -50,8 +51,9 @@
 
 public:
   LegalizationArtifactCombiner(MachineIRBuilder &B, MachineRegisterInfo &MRI,
-                    const LegalizerInfo &LI)
-      : Builder(B), MRI(MRI), LI(LI) {}
+                               const LegalizerInfo &LI,
+                               GISelKnownBits *KB = nullptr)
+      : Builder(B), MRI(MRI), LI(LI), KB(KB) {}
 
   bool tryCombineAnyExt(MachineInstr &MI,
                         SmallVectorImpl<MachineInstr *> &DeadInsts,
@@ -131,13 +133,26 @@
       LLVM_DEBUG(dbgs() << ".. Combine MI: " << MI;);
       LLT SrcTy = MRI.getType(SrcReg);
       APInt MaskVal = APInt::getAllOnes(SrcTy.getScalarSizeInBits());
-      auto Mask = Builder.buildConstant(
-        DstTy, MaskVal.zext(DstTy.getScalarSizeInBits()));
       if (SextSrc && (DstTy != MRI.getType(SextSrc)))
         SextSrc = Builder.buildSExtOrTrunc(DstTy, SextSrc).getReg(0);
       if (TruncSrc && (DstTy != MRI.getType(TruncSrc)))
         TruncSrc = Builder.buildAnyExtOrTrunc(DstTy, TruncSrc).getReg(0);
-      Builder.buildAnd(DstReg, SextSrc ? SextSrc : TruncSrc, Mask);
+      APInt ExtMaskVal = MaskVal.zext(DstTy.getScalarSizeInBits());
+      Register AndSrc = SextSrc ? SextSrc : TruncSrc;
+      // Elide G_AND and mask constant if possible.
+      // The G_AND would also be removed by the post-legalize redundant_and
+      // combine, but in this very common case, eliding early and regardless of
+      // OptLevel results in significant compile-time and O0 code-size
+      // improvements. Inserting unnecessary instructions between a boolean def
+      // and use can also hinder ISel to detect e.g. that reloading a flags
+      // register is unnecessary.
+      if (KB && (KB->getKnownZeroes(AndSrc) | ExtMaskVal).isAllOnes()) {
+        replaceRegOrBuildCopy(DstReg, AndSrc, MRI, Builder, UpdatedDefs,
+                              Observer);
+      } else {
+        auto Mask = Builder.buildConstant(DstTy, ExtMaskVal);
+        Builder.buildAnd(DstReg, AndSrc, Mask);
+      }
       markInstAndDefDead(MI, *MRI.getVRegDef(SrcReg), DeadInsts);
       return true;
     }
diff --git a/lib/CodeGen/GlobalISel/GISelKnownBits.cpp b/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
index bbe82e2..ea8c20c 100644
--- a/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
+++ b/lib/CodeGen/GlobalISel/GISelKnownBits.cpp
@@ -19,6 +19,7 @@
 #include "llvm/CodeGen/TargetLowering.h"
 #include "llvm/CodeGen/TargetOpcodes.h"
 #include "llvm/IR/Module.h"
+#include "llvm/Target/TargetMachine.h"
 
 #define DEBUG_TYPE "gisel-known-bits"
 
@@ -773,3 +774,12 @@
 bool GISelKnownBitsAnalysis::runOnMachineFunction(MachineFunction &MF) {
   return false;
 }
+
+GISelKnownBits &GISelKnownBitsAnalysis::get(MachineFunction &MF) {
+  if (!Info) {
+    unsigned MaxDepth =
+        MF.getTarget().getOptLevel() == CodeGenOptLevel::None ? 2 : 6;
+    Info = std::make_unique<GISelKnownBits>(MF, MaxDepth);
+  }
+  return *Info.get();
+}
diff --git a/lib/CodeGen/GlobalISel/Legalizer.cpp b/lib/CodeGen/GlobalISel/Legalizer.cpp
index aecbe0b..6d75258 100644
--- a/lib/CodeGen/GlobalISel/Legalizer.cpp
+++ b/lib/CodeGen/GlobalISel/Legalizer.cpp
@@ -218,7 +218,7 @@
   // This will keep all the observers notified about new insertions/deletions.
   RAIIMFObsDelInstaller Installer(MF, WrapperObserver);
   LegalizerHelper Helper(MF, LI, WrapperObserver, MIRBuilder, KB);
-  LegalizationArtifactCombiner ArtCombiner(MIRBuilder, MRI, LI);
+  LegalizationArtifactCombiner ArtCombiner(MIRBuilder, MRI, LI, KB);
   bool Changed = false;
   SmallVector<MachineInstr *, 128> RetryList;
   do {
diff --git a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2.ll b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2.ll
index 0c52a8a..8806175 100644
--- a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2.ll
+++ b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2.ll
@@ -926,7 +926,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_monotonic:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -949,7 +948,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acquire:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -972,7 +970,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_release:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -995,7 +992,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acq_rel:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -1018,7 +1014,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_seq_cst:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -1306,7 +1301,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_monotonic:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1321,7 +1315,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acquire:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1336,7 +1329,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_release:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1351,7 +1343,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acq_rel:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1366,7 +1357,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_seq_cst:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1706,7 +1696,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_monotonic:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1728,7 +1717,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acquire:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1750,7 +1738,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_release:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1772,7 +1759,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acq_rel:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1794,7 +1780,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_seq_cst:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -2081,7 +2066,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
@@ -2095,7 +2079,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acquire:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acquire:
@@ -2109,7 +2092,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_release:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_release:
@@ -2123,7 +2105,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
@@ -2137,7 +2118,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
@@ -5392,9 +5372,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5415,9 +5393,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5438,9 +5414,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5461,9 +5435,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5484,9 +5456,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5507,9 +5477,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5529,9 +5497,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5551,9 +5517,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5573,9 +5537,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5595,9 +5557,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5616,9 +5576,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5636,9 +5594,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5656,9 +5612,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5676,9 +5630,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5696,9 +5648,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5716,9 +5666,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5736,9 +5684,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5756,9 +5702,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5776,9 +5720,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5796,9 +5738,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5816,15 +5756,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5850,15 +5786,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5884,15 +5816,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5918,15 +5846,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5952,15 +5876,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5987,9 +5907,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6010,9 +5928,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6033,9 +5949,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6056,9 +5970,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6079,9 +5991,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6102,9 +6012,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_monotonic:
@@ -6120,9 +6028,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acquire:
@@ -6138,9 +6044,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_release:
@@ -6156,9 +6060,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
@@ -6174,9 +6076,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
@@ -6191,9 +6091,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_monotonic:
@@ -6207,9 +6105,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acquire:
@@ -6223,9 +6119,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_release:
@@ -6239,9 +6133,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
@@ -6255,9 +6147,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
@@ -6271,9 +6161,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_monotonic:
@@ -6287,9 +6175,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acquire:
@@ -6303,9 +6189,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_release:
@@ -6319,9 +6203,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
@@ -6335,9 +6217,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
@@ -6351,15 +6231,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6377,15 +6253,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6403,15 +6275,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6429,15 +6297,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6455,15 +6319,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6482,9 +6342,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6505,9 +6363,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6528,9 +6384,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6551,9 +6405,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6574,9 +6426,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6597,9 +6447,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6619,9 +6467,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6641,9 +6487,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6663,9 +6507,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6685,9 +6527,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6706,9 +6546,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6726,9 +6564,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6746,9 +6582,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6766,9 +6600,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6786,9 +6618,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6806,9 +6636,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6826,9 +6654,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6846,9 +6672,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6866,9 +6690,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6886,9 +6708,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6906,15 +6726,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -6940,15 +6756,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -6974,15 +6786,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -7008,15 +6816,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -7042,15 +6846,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -7077,9 +6877,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7100,9 +6898,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7123,9 +6919,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7146,9 +6940,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7169,9 +6961,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7192,9 +6982,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_monotonic:
@@ -7210,9 +6998,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acquire:
@@ -7228,9 +7014,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_release:
@@ -7246,9 +7030,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
@@ -7264,9 +7046,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
@@ -7281,9 +7061,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_monotonic:
@@ -7297,9 +7075,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acquire:
@@ -7313,9 +7089,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_release:
@@ -7329,9 +7103,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
@@ -7345,9 +7117,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
@@ -7361,9 +7131,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_monotonic:
@@ -7377,9 +7145,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acquire:
@@ -7393,9 +7159,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_release:
@@ -7409,9 +7173,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
@@ -7425,9 +7187,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
@@ -7441,15 +7201,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7467,15 +7223,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7493,15 +7245,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7519,15 +7267,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7545,15 +7289,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7572,9 +7312,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7595,9 +7333,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7618,9 +7354,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7641,9 +7375,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7664,9 +7396,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7686,9 +7416,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_monotonic:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7707,9 +7435,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_acquire:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7728,9 +7454,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_release:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7749,9 +7473,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_acq_rel:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7770,9 +7492,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_seq_cst:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7791,9 +7511,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7811,9 +7529,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7831,9 +7547,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7851,9 +7565,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7871,9 +7583,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7891,9 +7601,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7911,9 +7619,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7931,9 +7637,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7951,9 +7655,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7971,9 +7673,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7991,15 +7691,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -8025,15 +7721,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8059,15 +7751,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -8093,15 +7781,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8127,15 +7811,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8162,9 +7842,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8185,9 +7863,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8208,9 +7884,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8231,9 +7905,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8254,9 +7926,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8276,9 +7946,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
@@ -8293,9 +7961,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acquire:
@@ -8310,9 +7976,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_release:
@@ -8327,9 +7991,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
@@ -8344,9 +8006,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
@@ -8361,9 +8021,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
@@ -8377,9 +8035,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acquire:
@@ -8393,9 +8049,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_release:
@@ -8409,9 +8063,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
@@ -8425,9 +8077,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
@@ -8441,9 +8091,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
@@ -8457,9 +8105,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acquire:
@@ -8473,9 +8119,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_release:
@@ -8489,9 +8133,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
@@ -8505,9 +8147,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
@@ -8521,15 +8161,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8547,15 +8183,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8573,15 +8205,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8599,15 +8227,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8625,15 +8249,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8652,9 +8272,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8675,9 +8293,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8698,9 +8314,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8721,9 +8335,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8744,9 +8356,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8766,9 +8376,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_monotonic:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8787,9 +8395,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_acquire:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8808,9 +8414,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_release:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8829,9 +8433,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_acq_rel:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8850,9 +8452,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_seq_cst:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8871,9 +8471,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8891,9 +8489,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8911,9 +8507,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8931,9 +8525,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8951,9 +8543,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8971,9 +8561,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -8991,9 +8579,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9011,9 +8597,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9031,9 +8615,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9051,9 +8633,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9071,15 +8651,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -9105,15 +8681,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9139,15 +8711,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -9173,15 +8741,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9207,15 +8771,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9242,9 +8802,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9265,9 +8823,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9288,9 +8844,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9311,9 +8865,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9334,9 +8886,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9356,9 +8906,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
@@ -9373,9 +8921,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acquire:
@@ -9390,9 +8936,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_release:
@@ -9407,9 +8951,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
@@ -9424,9 +8966,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
@@ -9441,9 +8981,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
@@ -9457,9 +8995,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acquire:
@@ -9473,9 +9009,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_release:
@@ -9489,9 +9023,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
@@ -9505,9 +9037,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
@@ -9521,9 +9051,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
@@ -9537,9 +9065,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acquire:
@@ -9553,9 +9079,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_release:
@@ -9569,9 +9093,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
@@ -9585,9 +9107,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
@@ -9601,15 +9121,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9627,15 +9143,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9653,15 +9165,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9679,15 +9187,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9705,15 +9209,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
diff --git a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2_lse128.ll b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2_lse128.ll
index 4b0371d..a1712a5 100644
--- a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2_lse128.ll
+++ b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-lse2_lse128.ll
@@ -511,7 +511,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_monotonic:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    casp x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -532,7 +531,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acquire:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    caspa x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -553,7 +551,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_release:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    caspl x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -574,7 +571,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acq_rel:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    caspal x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -595,7 +591,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_seq_cst:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    caspal x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -831,7 +826,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_monotonic:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -846,7 +840,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acquire:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -861,7 +854,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_release:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -876,7 +868,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acq_rel:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -891,7 +882,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_seq_cst:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1046,7 +1036,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_monotonic:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    casp x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1066,7 +1055,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acquire:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    caspa x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1086,7 +1074,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_release:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    caspl x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1106,7 +1093,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acq_rel:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    caspal x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1126,7 +1112,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_seq_cst:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    caspal x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1361,7 +1346,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
@@ -1375,7 +1359,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acquire:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acquire:
@@ -1389,7 +1372,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_release:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_release:
@@ -1403,7 +1385,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
@@ -1417,7 +1398,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
@@ -3951,15 +3931,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_monotonic:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    casp x0, x1, x2, x3, [x8]
@@ -3983,15 +3959,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acquire:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspa x0, x1, x2, x3, [x8]
@@ -4015,15 +3987,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_release:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspl x0, x1, x2, x3, [x8]
@@ -4047,15 +4015,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acq_rel:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -4079,15 +4043,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_seq_cst:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -4147,9 +4107,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_monotonic:
@@ -4165,9 +4123,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acquire:
@@ -4183,9 +4139,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_release:
@@ -4201,9 +4155,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
@@ -4219,9 +4171,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
@@ -4236,9 +4186,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_monotonic:
@@ -4252,9 +4200,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acquire:
@@ -4268,9 +4214,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_release:
@@ -4284,9 +4228,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
@@ -4300,9 +4242,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
@@ -4316,9 +4256,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_monotonic:
@@ -4332,9 +4270,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acquire:
@@ -4348,9 +4284,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_release:
@@ -4364,9 +4298,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
@@ -4380,9 +4312,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
@@ -4396,15 +4326,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4422,15 +4348,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4448,15 +4370,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4474,15 +4392,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4500,15 +4414,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4666,15 +4576,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_monotonic:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    casp x0, x1, x2, x3, [x8]
@@ -4698,15 +4604,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acquire:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspa x0, x1, x2, x3, [x8]
@@ -4730,15 +4632,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_release:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspl x0, x1, x2, x3, [x8]
@@ -4762,15 +4660,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acq_rel:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -4794,15 +4688,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_seq_cst:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -4862,9 +4752,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_monotonic:
@@ -4880,9 +4768,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acquire:
@@ -4898,9 +4784,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_release:
@@ -4916,9 +4800,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
@@ -4934,9 +4816,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
@@ -4951,9 +4831,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_monotonic:
@@ -4967,9 +4845,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acquire:
@@ -4983,9 +4859,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_release:
@@ -4999,9 +4873,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
@@ -5015,9 +4887,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
@@ -5031,9 +4901,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_monotonic:
@@ -5047,9 +4915,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acquire:
@@ -5063,9 +4929,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_release:
@@ -5079,9 +4943,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
@@ -5095,9 +4957,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
@@ -5111,15 +4971,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5137,15 +4993,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5163,15 +5015,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5189,15 +5037,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5215,15 +5059,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5381,15 +5221,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_monotonic:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    casp x0, x1, x2, x3, [x8]
@@ -5413,15 +5249,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acquire:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspa x0, x1, x2, x3, [x8]
@@ -5445,15 +5277,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_release:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspl x0, x1, x2, x3, [x8]
@@ -5477,15 +5305,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acq_rel:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -5509,15 +5333,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_seq_cst:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -5576,9 +5396,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
@@ -5593,9 +5411,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acquire:
@@ -5610,9 +5426,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_release:
@@ -5627,9 +5441,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
@@ -5644,9 +5456,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
@@ -5661,9 +5471,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
@@ -5677,9 +5485,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acquire:
@@ -5693,9 +5499,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_release:
@@ -5709,9 +5513,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
@@ -5725,9 +5527,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
@@ -5741,9 +5541,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
@@ -5757,9 +5555,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acquire:
@@ -5773,9 +5569,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_release:
@@ -5789,9 +5583,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
@@ -5805,9 +5597,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
@@ -5821,15 +5611,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5847,15 +5633,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5873,15 +5655,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5899,15 +5677,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5925,15 +5699,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6091,15 +5861,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_monotonic:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    casp x0, x1, x2, x3, [x8]
@@ -6123,15 +5889,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acquire:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspa x0, x1, x2, x3, [x8]
@@ -6155,15 +5917,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_release:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspl x0, x1, x2, x3, [x8]
@@ -6187,15 +5945,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acq_rel:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -6219,15 +5973,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_seq_cst:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -6286,9 +6036,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
@@ -6303,9 +6051,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acquire:
@@ -6320,9 +6066,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_release:
@@ -6337,9 +6081,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
@@ -6354,9 +6096,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
@@ -6371,9 +6111,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
@@ -6387,9 +6125,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acquire:
@@ -6403,9 +6139,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_release:
@@ -6419,9 +6153,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
@@ -6435,9 +6167,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
@@ -6451,9 +6181,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
@@ -6467,9 +6195,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acquire:
@@ -6483,9 +6209,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_release:
@@ -6499,9 +6223,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
@@ -6515,9 +6237,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
@@ -6531,15 +6251,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6557,15 +6273,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6583,15 +6295,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6609,15 +6317,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6635,15 +6339,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
diff --git a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-outline_atomics.ll b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-outline_atomics.ll
index 89d22c5..c660c13 100644
--- a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-outline_atomics.ll
+++ b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-outline_atomics.ll
@@ -556,7 +556,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_monotonic:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -579,7 +578,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acquire:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -602,7 +600,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_release:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -625,7 +622,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acq_rel:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -648,7 +644,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_seq_cst:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -886,7 +881,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_monotonic:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -901,7 +895,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acquire:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -916,7 +909,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_release:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -931,7 +923,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acq_rel:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -946,7 +937,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_seq_cst:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1181,7 +1171,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_monotonic:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1203,7 +1192,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acquire:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1225,7 +1213,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_release:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1247,7 +1234,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acq_rel:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1269,7 +1255,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_seq_cst:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1526,7 +1511,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
@@ -1540,7 +1524,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acquire:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acquire:
@@ -1554,7 +1537,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_release:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_release:
@@ -1568,7 +1550,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
@@ -1582,7 +1563,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
@@ -4257,9 +4237,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4280,9 +4258,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4303,9 +4279,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4326,9 +4300,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4349,9 +4321,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4372,9 +4342,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -4394,9 +4362,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -4416,9 +4382,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -4438,9 +4402,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -4460,9 +4422,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -4481,9 +4441,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -4501,9 +4459,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -4521,9 +4477,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -4541,9 +4495,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -4561,9 +4513,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -4581,9 +4531,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -4601,9 +4549,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -4621,9 +4567,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -4641,9 +4585,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -4661,9 +4603,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -4681,15 +4621,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -4715,15 +4651,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -4749,15 +4681,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -4783,15 +4711,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -4817,15 +4741,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -4852,9 +4772,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4875,9 +4793,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4898,9 +4814,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4921,9 +4835,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4944,9 +4856,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -4967,9 +4877,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_monotonic:
@@ -4985,9 +4893,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acquire:
@@ -5003,9 +4909,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_release:
@@ -5021,9 +4925,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
@@ -5039,9 +4941,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
@@ -5056,9 +4956,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_monotonic:
@@ -5072,9 +4970,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acquire:
@@ -5088,9 +4984,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_release:
@@ -5104,9 +4998,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
@@ -5120,9 +5012,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
@@ -5136,9 +5026,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_monotonic:
@@ -5152,9 +5040,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acquire:
@@ -5168,9 +5054,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_release:
@@ -5184,9 +5068,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
@@ -5200,9 +5082,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
@@ -5216,15 +5096,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5242,15 +5118,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5268,15 +5140,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5294,15 +5162,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5320,15 +5184,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5347,9 +5207,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5370,9 +5228,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5393,9 +5249,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5416,9 +5270,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5439,9 +5291,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5462,9 +5312,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5484,9 +5332,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5506,9 +5352,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5528,9 +5372,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5550,9 +5392,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5571,9 +5411,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5591,9 +5429,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5611,9 +5447,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5631,9 +5465,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5651,9 +5483,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5671,9 +5501,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5691,9 +5519,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5711,9 +5537,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5731,9 +5555,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5751,9 +5573,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5771,15 +5591,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5805,15 +5621,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5839,15 +5651,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5873,15 +5681,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5907,15 +5711,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5942,9 +5742,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5965,9 +5763,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5988,9 +5784,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6011,9 +5805,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6034,9 +5826,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6057,9 +5847,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_monotonic:
@@ -6075,9 +5863,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acquire:
@@ -6093,9 +5879,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_release:
@@ -6111,9 +5895,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
@@ -6129,9 +5911,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
@@ -6146,9 +5926,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_monotonic:
@@ -6162,9 +5940,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acquire:
@@ -6178,9 +5954,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_release:
@@ -6194,9 +5968,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
@@ -6210,9 +5982,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
@@ -6226,9 +5996,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_monotonic:
@@ -6242,9 +6010,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acquire:
@@ -6258,9 +6024,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_release:
@@ -6274,9 +6038,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
@@ -6290,9 +6052,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
@@ -6306,15 +6066,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6332,15 +6088,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6358,15 +6110,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6384,15 +6132,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6410,15 +6154,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6437,9 +6177,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6460,9 +6198,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6483,9 +6219,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6506,9 +6240,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6529,9 +6261,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6551,9 +6281,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_monotonic:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6572,9 +6300,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_acquire:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6593,9 +6319,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_release:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6614,9 +6338,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_acq_rel:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6635,9 +6357,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_seq_cst:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6656,9 +6376,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6676,9 +6394,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6696,9 +6412,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6716,9 +6430,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6736,9 +6448,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6756,9 +6466,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6776,9 +6484,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6796,9 +6502,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6816,9 +6520,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6836,9 +6538,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6856,15 +6556,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -6890,15 +6586,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -6924,15 +6616,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -6958,15 +6646,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -6992,15 +6676,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -7027,9 +6707,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7050,9 +6728,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7073,9 +6749,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7096,9 +6770,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7119,9 +6791,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7141,9 +6811,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
@@ -7158,9 +6826,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acquire:
@@ -7175,9 +6841,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_release:
@@ -7192,9 +6856,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
@@ -7209,9 +6871,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
@@ -7226,9 +6886,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
@@ -7242,9 +6900,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acquire:
@@ -7258,9 +6914,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_release:
@@ -7274,9 +6928,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
@@ -7290,9 +6942,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
@@ -7306,9 +6956,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
@@ -7322,9 +6970,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acquire:
@@ -7338,9 +6984,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_release:
@@ -7354,9 +6998,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
@@ -7370,9 +7012,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
@@ -7386,15 +7026,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7412,15 +7048,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7438,15 +7070,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7464,15 +7092,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7490,15 +7114,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7517,9 +7137,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7540,9 +7158,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7563,9 +7179,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7586,9 +7200,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7609,9 +7221,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7631,9 +7241,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_monotonic:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7652,9 +7260,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_acquire:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7673,9 +7279,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_release:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7694,9 +7298,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_acq_rel:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7715,9 +7317,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_seq_cst:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7736,9 +7336,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7756,9 +7354,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7776,9 +7372,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7796,9 +7390,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7816,9 +7408,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7836,9 +7426,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7856,9 +7444,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7876,9 +7462,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7896,9 +7480,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7916,9 +7498,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7936,15 +7516,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -7970,15 +7546,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8004,15 +7576,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -8038,15 +7606,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8072,15 +7636,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8107,9 +7667,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8130,9 +7688,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8153,9 +7709,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8176,9 +7730,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8199,9 +7751,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8221,9 +7771,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
@@ -8238,9 +7786,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acquire:
@@ -8255,9 +7801,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_release:
@@ -8272,9 +7816,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
@@ -8289,9 +7831,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
@@ -8306,9 +7846,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
@@ -8322,9 +7860,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acquire:
@@ -8338,9 +7874,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_release:
@@ -8354,9 +7888,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
@@ -8370,9 +7902,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
@@ -8386,9 +7916,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
@@ -8402,9 +7930,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acquire:
@@ -8418,9 +7944,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_release:
@@ -8434,9 +7958,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
@@ -8450,9 +7972,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
@@ -8466,15 +7986,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8492,15 +8008,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8518,15 +8030,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8544,15 +8052,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8570,15 +8074,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
diff --git a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc.ll b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc.ll
index bb6163f..4f9e520 100644
--- a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc.ll
+++ b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc.ll
@@ -926,7 +926,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_monotonic:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -949,7 +948,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acquire:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -972,7 +970,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_release:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -995,7 +992,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acq_rel:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -1018,7 +1014,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_seq_cst:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -1306,7 +1301,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_monotonic:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1321,7 +1315,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acquire:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1336,7 +1329,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_release:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1351,7 +1343,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acq_rel:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1366,7 +1357,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_seq_cst:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1706,7 +1696,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_monotonic:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1728,7 +1717,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acquire:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1750,7 +1738,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_release:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1772,7 +1759,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acq_rel:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1794,7 +1780,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_seq_cst:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -2081,7 +2066,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
@@ -2095,7 +2079,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acquire:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acquire:
@@ -2109,7 +2092,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_release:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_release:
@@ -2123,7 +2105,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
@@ -2137,7 +2118,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
@@ -5392,9 +5372,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5415,9 +5393,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5438,9 +5414,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5461,9 +5435,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5484,9 +5456,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5507,9 +5477,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5529,9 +5497,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5551,9 +5517,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5573,9 +5537,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5595,9 +5557,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5616,9 +5576,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5636,9 +5594,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5656,9 +5612,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5676,9 +5630,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5696,9 +5648,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5716,9 +5666,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5736,9 +5684,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5756,9 +5702,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5776,9 +5720,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5796,9 +5738,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5816,15 +5756,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5850,15 +5786,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5884,15 +5816,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5918,15 +5846,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5952,15 +5876,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5987,9 +5907,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6010,9 +5928,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6033,9 +5949,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6056,9 +5970,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6079,9 +5991,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6102,9 +6012,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_monotonic:
@@ -6120,9 +6028,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acquire:
@@ -6138,9 +6044,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_release:
@@ -6156,9 +6060,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
@@ -6174,9 +6076,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
@@ -6191,9 +6091,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_monotonic:
@@ -6207,9 +6105,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acquire:
@@ -6223,9 +6119,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_release:
@@ -6239,9 +6133,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
@@ -6255,9 +6147,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
@@ -6271,9 +6161,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_monotonic:
@@ -6287,9 +6175,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acquire:
@@ -6303,9 +6189,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_release:
@@ -6319,9 +6203,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
@@ -6335,9 +6217,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
@@ -6351,15 +6231,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6377,15 +6253,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6403,15 +6275,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6429,15 +6297,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6455,15 +6319,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6482,9 +6342,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6505,9 +6363,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6528,9 +6384,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6551,9 +6405,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6574,9 +6426,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6597,9 +6447,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6619,9 +6467,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6641,9 +6487,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6663,9 +6507,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6685,9 +6527,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6706,9 +6546,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6726,9 +6564,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6746,9 +6582,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6766,9 +6600,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6786,9 +6618,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6806,9 +6636,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6826,9 +6654,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6846,9 +6672,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6866,9 +6690,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6886,9 +6708,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6906,15 +6726,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -6940,15 +6756,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -6974,15 +6786,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -7008,15 +6816,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -7042,15 +6846,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -7077,9 +6877,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7100,9 +6898,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7123,9 +6919,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7146,9 +6940,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7169,9 +6961,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7192,9 +6982,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_monotonic:
@@ -7210,9 +6998,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acquire:
@@ -7228,9 +7014,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_release:
@@ -7246,9 +7030,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
@@ -7264,9 +7046,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
@@ -7281,9 +7061,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_monotonic:
@@ -7297,9 +7075,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acquire:
@@ -7313,9 +7089,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_release:
@@ -7329,9 +7103,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
@@ -7345,9 +7117,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
@@ -7361,9 +7131,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_monotonic:
@@ -7377,9 +7145,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acquire:
@@ -7393,9 +7159,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_release:
@@ -7409,9 +7173,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
@@ -7425,9 +7187,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
@@ -7441,15 +7201,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7467,15 +7223,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7493,15 +7245,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7519,15 +7267,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7545,15 +7289,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7572,9 +7312,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7595,9 +7333,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7618,9 +7354,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7641,9 +7375,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7664,9 +7396,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7686,9 +7416,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_monotonic:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7707,9 +7435,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_acquire:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7728,9 +7454,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_release:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7749,9 +7473,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_acq_rel:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7770,9 +7492,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_seq_cst:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7791,9 +7511,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7811,9 +7529,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7831,9 +7547,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7851,9 +7565,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7871,9 +7583,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7891,9 +7601,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7911,9 +7619,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7931,9 +7637,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7951,9 +7655,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7971,9 +7673,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7991,15 +7691,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -8025,15 +7721,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8059,15 +7751,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -8093,15 +7781,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8127,15 +7811,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8162,9 +7842,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8185,9 +7863,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8208,9 +7884,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8231,9 +7905,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8254,9 +7926,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8276,9 +7946,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
@@ -8293,9 +7961,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acquire:
@@ -8310,9 +7976,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_release:
@@ -8327,9 +7991,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
@@ -8344,9 +8006,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
@@ -8361,9 +8021,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
@@ -8377,9 +8035,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acquire:
@@ -8393,9 +8049,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_release:
@@ -8409,9 +8063,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
@@ -8425,9 +8077,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
@@ -8441,9 +8091,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
@@ -8457,9 +8105,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acquire:
@@ -8473,9 +8119,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_release:
@@ -8489,9 +8133,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
@@ -8505,9 +8147,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
@@ -8521,15 +8161,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8547,15 +8183,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8573,15 +8205,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8599,15 +8227,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8625,15 +8249,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8652,9 +8272,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8675,9 +8293,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8698,9 +8314,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8721,9 +8335,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8744,9 +8356,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8766,9 +8376,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_monotonic:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8787,9 +8395,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_acquire:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8808,9 +8414,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_release:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8829,9 +8433,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_acq_rel:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8850,9 +8452,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_seq_cst:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8871,9 +8471,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8891,9 +8489,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8911,9 +8507,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8931,9 +8525,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8951,9 +8543,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8971,9 +8561,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -8991,9 +8579,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9011,9 +8597,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9031,9 +8615,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9051,9 +8633,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9071,15 +8651,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -9105,15 +8681,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9139,15 +8711,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -9173,15 +8741,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9207,15 +8771,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9242,9 +8802,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9265,9 +8823,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9288,9 +8844,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9311,9 +8865,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9334,9 +8886,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9356,9 +8906,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
@@ -9373,9 +8921,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acquire:
@@ -9390,9 +8936,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_release:
@@ -9407,9 +8951,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
@@ -9424,9 +8966,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
@@ -9441,9 +8981,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
@@ -9457,9 +8995,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acquire:
@@ -9473,9 +9009,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_release:
@@ -9489,9 +9023,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
@@ -9505,9 +9037,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
@@ -9521,9 +9051,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
@@ -9537,9 +9065,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acquire:
@@ -9553,9 +9079,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_release:
@@ -9569,9 +9093,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
@@ -9585,9 +9107,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
@@ -9601,15 +9121,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9627,15 +9143,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9653,15 +9165,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9679,15 +9187,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9705,15 +9209,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
diff --git a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc3.ll b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc3.ll
index 635620b..3437ccc 100644
--- a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc3.ll
+++ b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-rcpc3.ll
@@ -926,7 +926,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_monotonic:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -949,7 +948,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acquire:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -972,7 +970,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_release:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -995,7 +992,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acq_rel:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -1018,7 +1014,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_seq_cst:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -1306,7 +1301,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_monotonic:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1321,7 +1315,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acquire:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1336,7 +1329,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_release:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1351,7 +1343,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acq_rel:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1366,7 +1357,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_seq_cst:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1706,7 +1696,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_monotonic:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1728,7 +1717,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acquire:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1750,7 +1738,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_release:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1772,7 +1759,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acq_rel:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1794,7 +1780,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_seq_cst:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -2081,7 +2066,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
@@ -2095,7 +2079,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acquire:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acquire:
@@ -2109,7 +2092,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_release:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_release:
@@ -2123,7 +2105,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
@@ -2137,7 +2118,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
@@ -5392,9 +5372,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5415,9 +5393,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5438,9 +5414,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5461,9 +5435,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5484,9 +5456,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5507,9 +5477,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5529,9 +5497,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5551,9 +5517,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5573,9 +5537,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5595,9 +5557,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5616,9 +5576,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5636,9 +5594,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5656,9 +5612,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5676,9 +5630,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5696,9 +5648,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5716,9 +5666,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5736,9 +5684,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5756,9 +5702,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5776,9 +5720,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5796,9 +5738,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5816,15 +5756,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5850,15 +5786,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5884,15 +5816,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5918,15 +5846,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5952,15 +5876,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5987,9 +5907,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6010,9 +5928,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6033,9 +5949,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6056,9 +5970,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6079,9 +5991,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6102,9 +6012,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_monotonic:
@@ -6120,9 +6028,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acquire:
@@ -6138,9 +6044,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_release:
@@ -6156,9 +6060,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
@@ -6174,9 +6076,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
@@ -6191,9 +6091,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_monotonic:
@@ -6207,9 +6105,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acquire:
@@ -6223,9 +6119,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_release:
@@ -6239,9 +6133,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
@@ -6255,9 +6147,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
@@ -6271,9 +6161,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_monotonic:
@@ -6287,9 +6175,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acquire:
@@ -6303,9 +6189,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_release:
@@ -6319,9 +6203,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
@@ -6335,9 +6217,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
@@ -6351,15 +6231,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6377,15 +6253,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6403,15 +6275,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6429,15 +6297,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6455,15 +6319,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6482,9 +6342,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6505,9 +6363,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6528,9 +6384,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6551,9 +6405,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6574,9 +6426,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6597,9 +6447,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6619,9 +6467,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6641,9 +6487,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6663,9 +6507,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6685,9 +6527,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6706,9 +6546,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6726,9 +6564,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6746,9 +6582,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6766,9 +6600,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6786,9 +6618,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6806,9 +6636,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6826,9 +6654,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6846,9 +6672,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6866,9 +6690,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6886,9 +6708,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6906,15 +6726,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -6940,15 +6756,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -6974,15 +6786,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -7008,15 +6816,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -7042,15 +6846,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -7077,9 +6877,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7100,9 +6898,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7123,9 +6919,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7146,9 +6940,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7169,9 +6961,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7192,9 +6982,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_monotonic:
@@ -7210,9 +6998,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acquire:
@@ -7228,9 +7014,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_release:
@@ -7246,9 +7030,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
@@ -7264,9 +7046,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
@@ -7281,9 +7061,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_monotonic:
@@ -7297,9 +7075,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acquire:
@@ -7313,9 +7089,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_release:
@@ -7329,9 +7103,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
@@ -7345,9 +7117,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
@@ -7361,9 +7131,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_monotonic:
@@ -7377,9 +7145,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acquire:
@@ -7393,9 +7159,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_release:
@@ -7409,9 +7173,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
@@ -7425,9 +7187,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
@@ -7441,15 +7201,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7467,15 +7223,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7493,15 +7245,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7519,15 +7267,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7545,15 +7289,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -7572,9 +7312,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7595,9 +7333,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7618,9 +7354,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7641,9 +7375,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7664,9 +7396,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_aligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -7686,9 +7416,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_monotonic:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7707,9 +7435,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_acquire:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7728,9 +7454,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_release:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7749,9 +7473,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_acq_rel:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7770,9 +7492,7 @@
 define dso_local i16 @atomicrmw_umax_i16_aligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_aligned_seq_cst:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -7791,9 +7511,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7811,9 +7529,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7831,9 +7547,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7851,9 +7565,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7871,9 +7583,7 @@
 define dso_local i32 @atomicrmw_umax_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, hi
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -7891,9 +7601,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7911,9 +7619,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7931,9 +7637,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7951,9 +7655,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7971,9 +7673,7 @@
 define dso_local i64 @atomicrmw_umax_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, hi
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -7991,15 +7691,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -8025,15 +7721,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8059,15 +7751,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -8093,15 +7781,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8127,15 +7811,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -8162,9 +7842,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8185,9 +7863,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8208,9 +7884,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8231,9 +7905,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8254,9 +7926,7 @@
 ; -O0-LABEL: atomicrmw_umax_i8_unaligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, hi
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8276,9 +7946,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
@@ -8293,9 +7961,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acquire:
@@ -8310,9 +7976,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_release:
@@ -8327,9 +7991,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
@@ -8344,9 +8006,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
@@ -8361,9 +8021,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
@@ -8377,9 +8035,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acquire:
@@ -8393,9 +8049,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_release:
@@ -8409,9 +8063,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
@@ -8425,9 +8077,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
@@ -8441,9 +8091,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
@@ -8457,9 +8105,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acquire:
@@ -8473,9 +8119,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_release:
@@ -8489,9 +8133,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
@@ -8505,9 +8147,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
@@ -8521,15 +8161,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8547,15 +8183,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8573,15 +8205,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8599,15 +8227,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8625,15 +8249,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -8652,9 +8272,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8675,9 +8293,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8698,9 +8314,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8721,9 +8335,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8744,9 +8356,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_aligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -8766,9 +8376,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_monotonic:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8787,9 +8395,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_acquire:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8808,9 +8414,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_release:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8829,9 +8433,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_acq_rel:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8850,9 +8452,7 @@
 define dso_local i16 @atomicrmw_umin_i16_aligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_aligned_seq_cst:
 ; -O0:    subs w10, w10, w9, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -8871,9 +8471,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8891,9 +8489,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8911,9 +8507,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8931,9 +8525,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8951,9 +8543,7 @@
 define dso_local i32 @atomicrmw_umin_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, ls
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -8971,9 +8561,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -8991,9 +8579,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9011,9 +8597,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9031,9 +8615,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9051,9 +8633,7 @@
 define dso_local i64 @atomicrmw_umin_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, ls
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -9071,15 +8651,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -9105,15 +8681,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9139,15 +8711,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -9173,15 +8741,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9207,15 +8771,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -9242,9 +8802,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_monotonic:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9265,9 +8823,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_acquire:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9288,9 +8844,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_release:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9311,9 +8865,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_acq_rel:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9334,9 +8886,7 @@
 ; -O0-LABEL: atomicrmw_umin_i8_unaligned_seq_cst:
 ; -O0:    and w9, w10, #0xff
 ; -O0:    subs w9, w9, w8, uxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, ls
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -9356,9 +8906,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
@@ -9373,9 +8921,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acquire:
@@ -9390,9 +8936,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_release:
@@ -9407,9 +8951,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
@@ -9424,9 +8966,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
@@ -9441,9 +8981,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
@@ -9457,9 +8995,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acquire:
@@ -9473,9 +9009,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_release:
@@ -9489,9 +9023,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
@@ -9505,9 +9037,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
@@ -9521,9 +9051,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
@@ -9537,9 +9065,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acquire:
@@ -9553,9 +9079,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_release:
@@ -9569,9 +9093,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
@@ -9585,9 +9107,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
@@ -9601,15 +9121,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9627,15 +9143,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9653,15 +9165,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9679,15 +9187,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -9705,15 +9209,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
diff --git a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8_1a.ll b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8_1a.ll
index 7fc733a..ee5fbe3 100644
--- a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8_1a.ll
+++ b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8_1a.ll
@@ -546,7 +546,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_monotonic:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    casp x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -567,7 +566,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acquire:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    caspa x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -588,7 +586,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_release:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    caspl x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -609,7 +606,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acq_rel:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    caspal x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -630,7 +626,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_seq_cst:
 ; -O0:    adds x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    caspal x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
@@ -866,7 +861,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_monotonic:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -881,7 +875,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acquire:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -896,7 +889,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_release:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -911,7 +903,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acq_rel:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -926,7 +917,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_seq_cst:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1081,7 +1071,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_monotonic:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    casp x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1101,7 +1090,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acquire:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    caspa x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1121,7 +1109,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_release:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    caspl x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1141,7 +1128,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acq_rel:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    caspal x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1161,7 +1147,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_seq_cst:
 ; -O0:    subs x2, x9, x11
-; -O0:    and w11, w9, #0x1
 ; -O0:    caspal x0, x1, x2, x3, [x8]
 ; -O0:    eor x8, x10, x8
 ; -O0:    eor x11, x9, x11
@@ -1396,7 +1381,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
@@ -1410,7 +1394,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acquire:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acquire:
@@ -1424,7 +1407,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_release:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_release:
@@ -1438,7 +1420,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
@@ -1452,7 +1433,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
@@ -4076,15 +4056,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_monotonic:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    casp x0, x1, x2, x3, [x8]
@@ -4108,15 +4084,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acquire:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspa x0, x1, x2, x3, [x8]
@@ -4140,15 +4112,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_release:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspl x0, x1, x2, x3, [x8]
@@ -4172,15 +4140,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acq_rel:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -4204,15 +4168,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_seq_cst:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -4272,9 +4232,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_monotonic:
@@ -4290,9 +4248,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acquire:
@@ -4308,9 +4264,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_release:
@@ -4326,9 +4280,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
@@ -4344,9 +4296,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
@@ -4361,9 +4311,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_monotonic:
@@ -4377,9 +4325,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acquire:
@@ -4393,9 +4339,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_release:
@@ -4409,9 +4353,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
@@ -4425,9 +4367,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
@@ -4441,9 +4381,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_monotonic:
@@ -4457,9 +4395,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acquire:
@@ -4473,9 +4409,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_release:
@@ -4489,9 +4423,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
@@ -4505,9 +4437,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
@@ -4521,15 +4451,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4547,15 +4473,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4573,15 +4495,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4599,15 +4517,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4625,15 +4539,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -4791,15 +4701,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_monotonic:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    casp x0, x1, x2, x3, [x8]
@@ -4823,15 +4729,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acquire:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspa x0, x1, x2, x3, [x8]
@@ -4855,15 +4757,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_release:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspl x0, x1, x2, x3, [x8]
@@ -4887,15 +4785,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_acq_rel:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -4919,15 +4813,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_seq_cst:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -4987,9 +4877,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_monotonic:
@@ -5005,9 +4893,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acquire:
@@ -5023,9 +4909,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_release:
@@ -5041,9 +4925,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_acq_rel:
@@ -5059,9 +4941,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i16_unaligned_seq_cst:
@@ -5076,9 +4956,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_monotonic:
@@ -5092,9 +4970,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acquire:
@@ -5108,9 +4984,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_release:
@@ -5124,9 +4998,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_acq_rel:
@@ -5140,9 +5012,7 @@
 define dso_local i32 @atomicrmw_min_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i32_unaligned_seq_cst:
@@ -5156,9 +5026,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_monotonic:
@@ -5172,9 +5040,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acquire:
@@ -5188,9 +5054,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_release:
@@ -5204,9 +5068,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_acq_rel:
@@ -5220,9 +5082,7 @@
 define dso_local i64 @atomicrmw_min_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, le
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_min_i64_unaligned_seq_cst:
@@ -5236,15 +5096,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5262,15 +5118,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5288,15 +5140,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5314,15 +5162,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5340,15 +5184,11 @@
 define dso_local i128 @atomicrmw_min_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5506,15 +5346,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_monotonic:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    casp x0, x1, x2, x3, [x8]
@@ -5538,15 +5374,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acquire:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspa x0, x1, x2, x3, [x8]
@@ -5570,15 +5402,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_release:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspl x0, x1, x2, x3, [x8]
@@ -5602,15 +5430,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_acq_rel:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -5634,15 +5458,11 @@
 define dso_local i128 @atomicrmw_umax_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_aligned_seq_cst:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -5701,9 +5521,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_monotonic:
@@ -5718,9 +5536,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acquire:
@@ -5735,9 +5551,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_release:
@@ -5752,9 +5566,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_acq_rel:
@@ -5769,9 +5581,7 @@
 define dso_local i16 @atomicrmw_umax_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i16_unaligned_seq_cst:
@@ -5786,9 +5596,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_monotonic:
@@ -5802,9 +5610,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acquire:
@@ -5818,9 +5624,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_release:
@@ -5834,9 +5638,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_acq_rel:
@@ -5850,9 +5652,7 @@
 define dso_local i32 @atomicrmw_umax_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i32_unaligned_seq_cst:
@@ -5866,9 +5666,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_monotonic:
@@ -5882,9 +5680,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acquire:
@@ -5898,9 +5694,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_release:
@@ -5914,9 +5708,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_acq_rel:
@@ -5930,9 +5722,7 @@
 define dso_local i64 @atomicrmw_umax_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, hi
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umax_i64_unaligned_seq_cst:
@@ -5946,15 +5736,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5972,15 +5758,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -5998,15 +5780,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6024,15 +5802,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6050,15 +5824,11 @@
 define dso_local i128 @atomicrmw_umax_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umax_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6216,15 +5986,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_monotonic:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    casp x0, x1, x2, x3, [x8]
@@ -6248,15 +6014,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acquire:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspa x0, x1, x2, x3, [x8]
@@ -6280,15 +6042,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_release:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspl x0, x1, x2, x3, [x8]
@@ -6312,15 +6070,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_acq_rel:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -6344,15 +6098,11 @@
 define dso_local i128 @atomicrmw_umin_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_aligned_seq_cst:
 ; -O0:    subs x9, x9, x10
-; -O0:    subs x9, x9, x10
 ; -O0:    subs x9, x9, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w9, w9, w11, ne
-; -O0:    and w13, w9, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x2, x11, x12, ne
-; -O0:    and w11, w9, #0x1
+; -O0:    subs x13, x13, x10
+; -O0:    csel w11, w9, w11, eq
+; -O0:    ands w13, w11, #0x1
+; -O0:    csel x2, x9, x12, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x9, x9, x10, ne
 ; -O0:    caspal x0, x1, x2, x3, [x8]
@@ -6411,9 +6161,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_monotonic(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_monotonic:
@@ -6428,9 +6176,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acquire(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acquire:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acquire:
@@ -6445,9 +6191,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_release(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_release:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_release:
@@ -6462,9 +6206,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_acq_rel(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_acq_rel:
@@ -6479,9 +6221,7 @@
 define dso_local i16 @atomicrmw_umin_i16_unaligned_seq_cst(ptr %ptr, i16 %value) {
 ; -O0-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
 ; -O0:    subs w10, w10, w8, uxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i16_unaligned_seq_cst:
@@ -6496,9 +6236,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_monotonic:
@@ -6512,9 +6250,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acquire:
@@ -6528,9 +6264,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_release:
@@ -6544,9 +6278,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_acq_rel:
@@ -6560,9 +6292,7 @@
 define dso_local i32 @atomicrmw_umin_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i32_unaligned_seq_cst:
@@ -6576,9 +6306,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_monotonic:
@@ -6592,9 +6320,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acquire:
@@ -6608,9 +6334,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_release:
@@ -6624,9 +6348,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_acq_rel:
@@ -6640,9 +6362,7 @@
 define dso_local i64 @atomicrmw_umin_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, ls
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_umin_i64_unaligned_seq_cst:
@@ -6656,15 +6376,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6682,15 +6398,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6708,15 +6420,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6734,15 +6442,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6760,15 +6464,11 @@
 define dso_local i128 @atomicrmw_umin_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_umin_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
diff --git a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8a.ll b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8a.ll
index 0ea04d1..2473147 100644
--- a/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8a.ll
+++ b/test/CodeGen/AArch64/Atomics/aarch64-atomicrmw-v8a.ll
@@ -926,7 +926,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_monotonic:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -949,7 +948,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acquire:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -972,7 +970,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_release:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -995,7 +992,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_acq_rel:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -1018,7 +1014,6 @@
 define dso_local i128 @atomicrmw_add_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_aligned_seq_cst:
 ; -O0:    adds x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    subs w10, w10, #1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
@@ -1306,7 +1301,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_monotonic:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1321,7 +1315,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acquire:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1336,7 +1329,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_release:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1351,7 +1343,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_acq_rel:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1366,7 +1357,6 @@
 define dso_local i128 @atomicrmw_add_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_add_i128_unaligned_seq_cst:
 ; -O0:    adds x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    subs w11, w11, #1
 ; -O0:    bl __atomic_compare_exchange
 ;
@@ -1706,7 +1696,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_monotonic:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1728,7 +1717,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acquire:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1750,7 +1738,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_release:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1772,7 +1759,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_acq_rel:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -1794,7 +1780,6 @@
 define dso_local i128 @atomicrmw_sub_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_aligned_seq_cst:
 ; -O0:    subs x14, x8, x10
-; -O0:    and w10, w8, #0x1
 ; -O0:    ldaxp x10, x9, [x11]
 ; -O0:    cmp x10, x12
 ; -O0:    cmp x9, x13
@@ -2081,7 +2066,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_monotonic:
@@ -2095,7 +2079,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acquire:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acquire:
@@ -2109,7 +2092,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_release:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_release:
@@ -2123,7 +2105,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_acq_rel:
@@ -2137,7 +2118,6 @@
 define dso_local i128 @atomicrmw_sub_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
 ; -O0:    subs x9, x8, x9
-; -O0:    and w11, w8, #0x1
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_sub_i128_unaligned_seq_cst:
@@ -5392,9 +5372,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5415,9 +5393,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5438,9 +5414,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5461,9 +5435,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5484,9 +5456,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -5507,9 +5477,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5529,9 +5497,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5551,9 +5517,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5573,9 +5537,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5595,9 +5557,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -5616,9 +5576,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5636,9 +5594,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5656,9 +5612,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5676,9 +5630,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5696,9 +5648,7 @@
 define dso_local i32 @atomicrmw_max_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, gt
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -5716,9 +5666,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5736,9 +5684,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5756,9 +5702,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5776,9 +5720,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5796,9 +5738,7 @@
 define dso_local i64 @atomicrmw_max_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, gt
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -5816,15 +5756,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5850,15 +5786,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acquire:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5884,15 +5816,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_release:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldxp x10, x9, [x11]
@@ -5918,15 +5846,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_acq_rel:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5952,15 +5876,11 @@
 define dso_local i128 @atomicrmw_max_i128_aligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_aligned_seq_cst:
 ; -O0:    subs x8, x8, x9
-; -O0:    subs x8, x8, x9
 ; -O0:    subs x8, x8, x12
-; -O0:    and w13, w13, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel w8, w8, w10, ne
-; -O0:    and w13, w8, #0x1
-; -O0:    ands w13, w13, #0x1
-; -O0:    csel x14, x10, x12, ne
-; -O0:    and w10, w8, #0x1
+; -O0:    subs x13, x13, x9
+; -O0:    csel w10, w8, w10, eq
+; -O0:    ands w13, w10, #0x1
+; -O0:    csel x14, x8, x12, ne
 ; -O0:    ands w10, w10, #0x1
 ; -O0:    csel x15, x8, x9, ne
 ; -O0:    ldaxp x10, x9, [x11]
@@ -5987,9 +5907,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6010,9 +5928,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6033,9 +5949,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6056,9 +5970,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6079,9 +5991,7 @@
 ; -O0-LABEL: atomicrmw_max_i8_unaligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, gt
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6102,9 +6012,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_monotonic:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_monotonic:
@@ -6120,9 +6028,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acquire:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acquire:
@@ -6138,9 +6044,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_release:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_release:
@@ -6156,9 +6060,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_acq_rel:
@@ -6174,9 +6076,7 @@
 ; -O0-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
 ; -O0:    sxth w10, w9
 ; -O0:    subs w10, w10, w8, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i16_unaligned_seq_cst:
@@ -6191,9 +6091,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_monotonic:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_monotonic:
@@ -6207,9 +6105,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acquire:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acquire:
@@ -6223,9 +6119,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_release:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_release:
@@ -6239,9 +6133,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_acq_rel:
@@ -6255,9 +6147,7 @@
 define dso_local i32 @atomicrmw_max_i32_unaligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
 ; -O0:    subs w10, w9, w8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w8, w9, w8, ne
+; -O0:    csel w8, w9, w8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i32_unaligned_seq_cst:
@@ -6271,9 +6161,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_monotonic:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_monotonic:
@@ -6287,9 +6175,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acquire:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acquire:
@@ -6303,9 +6189,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_release:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_release:
@@ -6319,9 +6203,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_acq_rel:
@@ -6335,9 +6217,7 @@
 define dso_local i64 @atomicrmw_max_i64_unaligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
 ; -O0:    subs x10, x9, x8
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x8, x9, x8, ne
+; -O0:    csel x8, x9, x8, gt
 ; -O0:    bl __atomic_compare_exchange
 ;
 ; -O1-LABEL: atomicrmw_max_i64_unaligned_seq_cst:
@@ -6351,15 +6231,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_monotonic:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6377,15 +6253,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acquire(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acquire:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6403,15 +6275,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_release(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_release:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6429,15 +6297,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_acq_rel(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_acq_rel:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6455,15 +6319,11 @@
 define dso_local i128 @atomicrmw_max_i128_unaligned_seq_cst(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_max_i128_unaligned_seq_cst:
 ; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x10
-; -O0:    subs x8, x8, x11
-; -O0:    and w12, w12, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel w8, w8, w9, ne
-; -O0:    and w12, w8, #0x1
-; -O0:    ands w12, w12, #0x1
-; -O0:    csel x9, x9, x11, ne
-; -O0:    and w11, w8, #0x1
+; -O0:    subs x8, x8, x9
+; -O0:    subs x12, x12, x10
+; -O0:    csel w11, w8, w11, eq
+; -O0:    ands w12, w11, #0x1
+; -O0:    csel x9, x8, x9, ne
 ; -O0:    ands w11, w11, #0x1
 ; -O0:    csel x8, x8, x10, ne
 ; -O0:    bl __atomic_compare_exchange
@@ -6482,9 +6342,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_monotonic:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6505,9 +6363,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acquire:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6528,9 +6384,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_release:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6551,9 +6405,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_acq_rel:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6574,9 +6426,7 @@
 ; -O0-LABEL: atomicrmw_min_i8_aligned_seq_cst:
 ; -O0:    sxtb w9, w10
 ; -O0:    subs w9, w9, w8, sxtb
-; -O0:    and w9, w9, #0x1
-; -O0:    ands w9, w9, #0x1
-; -O0:    csel w12, w10, w8, ne
+; -O0:    csel w12, w10, w8, le
 ; -O0:    ldaxrb w9, [x11]
 ; -O0:    cmp w9, w10, uxtb
 ; -O0:    stlxrb w8, w12, [x11]
@@ -6597,9 +6447,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_monotonic:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6619,9 +6467,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acquire:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6641,9 +6487,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_release:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6663,9 +6507,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_acq_rel:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6685,9 +6527,7 @@
 ; -O0-LABEL: atomicrmw_min_i16_aligned_seq_cst:
 ; -O0:    sxth w10, w8
 ; -O0:    subs w10, w10, w9, sxth
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxrh w9, [x11]
 ; -O0:    cmp w9, w8, uxth
 ; -O0:    stlxrh w10, w12, [x11]
@@ -6706,9 +6546,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_monotonic(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_monotonic:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6726,9 +6564,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acquire(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acquire:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6746,9 +6582,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_release(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_release:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6766,9 +6600,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_acq_rel(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_acq_rel:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6786,9 +6618,7 @@
 define dso_local i32 @atomicrmw_min_i32_aligned_seq_cst(ptr %ptr, i32 %value) {
 ; -O0-LABEL: atomicrmw_min_i32_aligned_seq_cst:
 ; -O0:    subs w10, w8, w9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel w12, w8, w9, ne
+; -O0:    csel w12, w8, w9, le
 ; -O0:    ldaxr w9, [x11]
 ; -O0:    cmp w9, w8
 ; -O0:    stlxr w10, w12, [x11]
@@ -6806,9 +6636,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_monotonic(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_monotonic:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6826,9 +6654,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acquire(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acquire:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6846,9 +6672,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_release(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_release:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6866,9 +6690,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_acq_rel(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_acq_rel:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6886,9 +6708,7 @@
 define dso_local i64 @atomicrmw_min_i64_aligned_seq_cst(ptr %ptr, i64 %value) {
 ; -O0-LABEL: atomicrmw_min_i64_aligned_seq_cst:
 ; -O0:    subs x10, x8, x9
-; -O0:    and w10, w10, #0x1
-; -O0:    ands w10, w10, #0x1
-; -O0:    csel x12, x8, x9, ne
+; -O0:    csel x12, x8, x9, le
 ; -O0:    ldaxr x9, [x11]
 ; -O0:    cmp x9, x8
 ; -O0:    stlxr w10, x12, [x11]
@@ -6906,15 +6726,11 @@
 define dso_local i128 @atomicrmw_min_i128_aligned_monotonic(ptr %ptr, i128 %value) {
 ; -O0-LABEL: atomicrmw_min_i128_aligned_monotonic:
 ; -O0:    subs x8, x8, x9