[PATCH] D74454: Use SETNE directly rather than SUB/SETNE 0 for stack guard check

James Clarke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 18 05:23:07 PST 2020


This revision was automatically updated to reflect the committed changes.
Closed by commit rGb3cd44f80b8d: Use SETNE directly rather than SUB/SETNE 0 for stack guard check (authored by jrtc27).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74454/new/

https://reviews.llvm.org/D74454

Files:
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/test/CodeGen/SystemZ/stack-guard.ll
  llvm/test/CodeGen/Thumb/stack_guard_remat.ll
  llvm/test/CodeGen/WebAssembly/stack-protector.ll


Index: llvm/test/CodeGen/WebAssembly/stack-protector.ll
===================================================================
--- llvm/test/CodeGen/WebAssembly/stack-protector.ll
+++ 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
Index: llvm/test/CodeGen/Thumb/stack_guard_remat.ll
===================================================================
--- llvm/test/CodeGen/Thumb/stack_guard_remat.ll
+++ 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
Index: llvm/test/CodeGen/SystemZ/stack-guard.ll
===================================================================
--- llvm/test/CodeGen/SystemZ/stack-guard.ll
+++ 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:
Index: llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ 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()));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74454.245133.patch
Type: text/x-patch
Size: 3308 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200218/40ee1068/attachment.bin>


More information about the llvm-commits mailing list