diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -2596,17 +2596,13 @@ MachineMemOperand::MOVolatile); } - // Perform the comparison via a subtract/getsetcc. - EVT VT = Guard.getValueType(); - SDValue Sub = DAG.getNode(ISD::SUB, dl, VT, Guard, GuardVal); - + // Perform the comparison via a getsetcc. SDValue Cmp = DAG.getSetCC(dl, TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), - Sub.getValueType()), - Sub, DAG.getConstant(0, dl, VT), ISD::SETNE); + Guard.getValueType()), + Guard, GuardVal, ISD::SETNE); - // If the sub is not 0, then we know the guard/stackslot do not equal, so - // branch to failure MBB. + // If the guard/stackslot do not equal, branch to failure MBB. SDValue BrCond = DAG.getNode(ISD::BRCOND, dl, MVT::Other, GuardVal.getOperand(0), Cmp, DAG.getBasicBlock(SPD.getFailureMBB())); diff --git a/llvm/test/CodeGen/SystemZ/stack-guard.ll b/llvm/test/CodeGen/SystemZ/stack-guard.ll --- a/llvm/test/CodeGen/SystemZ/stack-guard.ll +++ b/llvm/test/CodeGen/SystemZ/stack-guard.ll @@ -11,7 +11,7 @@ ; CHECK: sllg [[REG2]], [[REG2]], 32 ; CHECK: ear [[REG2]], %a1 ; CHECK: lg [[REG2]], 40([[REG2]]) -; CHECK: sg [[REG2]], {{[0-9]*}}(%r15) +; CHECK: cg [[REG2]], {{[0-9]*}}(%r15) define i32 @test_stack_guard() #0 { entry: diff --git a/llvm/test/CodeGen/Thumb/stack_guard_remat.ll b/llvm/test/CodeGen/Thumb/stack_guard_remat.ll --- a/llvm/test/CodeGen/Thumb/stack_guard_remat.ll +++ b/llvm/test/CodeGen/Thumb/stack_guard_remat.ll @@ -11,7 +11,7 @@ ;PIC-NEXT: add [[ORIGINAL_GUARD]], pc ;PIC-NEXT: ldr [[ORIGINAL_GUARD]], {{\[}}[[ORIGINAL_GUARD]]{{\]}} ;PIC-NEXT: ldr [[ORIGINAL_GUARD]], {{\[}}[[ORIGINAL_GUARD]]{{\]}} -;PIC-NEXT: subs {{r[0-9]+}}, [[ORIGINAL_GUARD]], [[SAVED_GUARD]] +;PIC-NEXT: cmp [[ORIGINAL_GUARD]], [[SAVED_GUARD]] ;PIC: [[GUARD_STACK_OFFSET]]: ;PIC-NEXT: .long 1028 @@ -26,7 +26,7 @@ ;NO-PIC-NOT: LPC ;NO-PIC-NEXT: ldr [[ORIGINAL_GUARD]], {{\[}}[[ORIGINAL_GUARD]]{{\]}} ;DYNAMIC-NO-PIC-NEXT: ldr [[ORIGINAL_GUARD]], {{\[}}[[ORIGINAL_GUARD]]{{\]}} -;NO-PIC-NEXT: subs {{r[0-9]+}}, [[ORIGINAL_GUARD]], [[SAVED_GUARD]] +;NO-PIC-NEXT: cmp [[ORIGINAL_GUARD]], [[SAVED_GUARD]] ;STATIC: [[GUARD_STACK_OFFSET]]: ;STATIC-NEXT: .long 1028 diff --git a/llvm/test/CodeGen/WebAssembly/stack-protector.ll b/llvm/test/CodeGen/WebAssembly/stack-protector.ll --- a/llvm/test/CodeGen/WebAssembly/stack-protector.ll +++ b/llvm/test/CodeGen/WebAssembly/stack-protector.ll @@ -1,7 +1,7 @@ ; RUN: llc -verify-machineinstrs -mtriple=wasm32-unknown-unknown < %s | FileCheck -check-prefix=WASM32 %s ; WASM32: i32.load 28 -; WASM32-NEXT: i32.sub +; WASM32-NEXT: i32.ne ; WASM32-NEXT: br_if 0 ; WASM32: __stack_chk_fail