diff --git a/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp b/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp index 484bcb7cccd..44d9e3875b8 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeIntegerTypes.cpp @@ -225,10 +225,9 @@ SDValue DAGTypeLegalizer::PromoteIntRes_AtomicCmpSwap(AtomicSDNode *N, N->getOpcode(), SDLoc(N), N->getMemoryVT(), VTs, N->getChain(), N->getBasePtr(), Op2, Op3, N->getMemOperand(), N->getSuccessOrdering(), N->getFailureOrdering(), N->getSynchScope()); - // Legalized the chain result - switch anything that used the old chain to - // use the new one. - unsigned ChainOp = N->getNumValues() - 1; - ReplaceValueWith(SDValue(N, ChainOp), Res.getValue(ChainOp)); + // Update the use to N with the newly created Res. + for (unsigned i = 1, NumResults = N->getNumValues(); i < NumResults; ++i) + ReplaceValueWith(SDValue(N, i), Res.getValue(i)); return Res; } diff --git a/test/CodeGen/ARM/atomic-cmpxchg.ll b/test/CodeGen/ARM/atomic-cmpxchg.ll new file mode 100644 index 00000000000..4b79fa25145 --- /dev/null +++ b/test/CodeGen/ARM/atomic-cmpxchg.ll @@ -0,0 +1,50 @@ +; RUN: llc < %s -mtriple=arm-linux-gnueabi -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-ARM +; RUN: llc < %s -mtriple=thumb-linux-gnueabi -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-THUMB + +; RUN: llc < %s -mtriple=armv7-linux-gnueabi -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-ARMV7 +; RUN: llc < %s -mtriple=thumbv7-linux-gnueabi -verify-machineinstrs | FileCheck %s -check-prefix=CHECK-THUMBV7 + +define zeroext i1 @test_cmpxchg_res_i8(i8* %addr, i8 %desired, i8 zeroext %new) { +entry: + %0 = cmpxchg i8* %addr, i8 %desired, i8 %new monotonic monotonic + %1 = extractvalue { i8, i1 } %0, 1 + ret i1 %1 +} + +; CHECK-ARM-LABEL: test_cmpxchg_res_i8 +; CHECK-ARM: bl __sync_val_compare_and_swap_1 +; CHECK-ARM: mov [[REG:r[0-9]+]], #0 +; CHECK-ARM: cmp r0, {{r[0-9]+}} +; CHECK-ARM: moveq [[REG]], #1 +; CHECK-ARM: mov r0, [[REG]] + +; CHECK-THUMB-LABEL: test_cmpxchg_res_i8 +; CHECK-THUMB: bl __sync_val_compare_and_swap_1 +; CHECK-THUMB: mov [[R1:r[0-9]+]], r0 +; CHECK-THUMB: movs r0, #1 +; CHECK-THUMB: movs [[R2:r[0-9]+]], #0 +; CHECK-THUMB: cmp [[R1]], {{r[0-9]+}} +; CHECK-THU