1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-01-31 12:41:49 +01:00

Use SETNE directly rather than SUB/SETNE 0 for stack guard check

Summary:
Backends should fold the subtraction into the comparison, but not all
seem to. Moreover, on targets where pointers are not integers, such as
CHERI, an integer subtraction is not appropriate. Instead we should just
compare the two pointers directly, as this should work everywhere and
potentially generate more efficient code.

Reviewers: bogner, lebedev.ri, efriedma, t.p.northover, uweigand, sunfish

Reviewed By: lebedev.ri

Subscribers: dschuff, sbc100, arichardson, jgravelle-google, hiraditya, aheejin, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D74454
This commit is contained in:
James Clarke 2020-02-18 13:21:23 +00:00
parent 7d153b6b68
commit 38b58c28d1
4 changed files with 8 additions and 12 deletions

View File

@ -2596,17 +2596,13 @@ void SelectionDAGBuilder::visitSPDescriptorParent(StackProtectorDescriptor &SPD,
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()));

View File

@ -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:

View File

@ -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

View File

@ -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