diff options
author | James Clarke <jrtc27@jrtc27.com> | 2020-02-18 13:21:23 +0000 |
---|---|---|
committer | James Clarke <jrtc27@jrtc27.com> | 2020-02-18 13:21:26 +0000 |
commit | b3cd44f80b8d6de76d41f1c78241d782c77cd193 (patch) | |
tree | 0b4819c94db98a386d7ad454b448794500debdf9 /llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | |
parent | d6fe253653b7e760f94ca21d0a7ebbfeeee28777 (diff) | |
download | llvm-b3cd44f80b8d6de76d41f1c78241d782c77cd193.zip llvm-b3cd44f80b8d6de76d41f1c78241d782c77cd193.tar.gz llvm-b3cd44f80b8d6de76d41f1c78241d782c77cd193.tar.bz2 |
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
Diffstat (limited to 'llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index f1ca734..e3c2139 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -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())); |