[PATCH] D64759: [CodeGen] Don't resolve the stack protector frame accesses until PEI

Francis Visoiu Mistrih via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 23 10:48:39 PDT 2019


thegameg updated this revision to Diff 211332.
thegameg added a comment.
Herald added subscribers: jsji, MaskRay, nemanjai.

- Rebase
- Update tests added in r366371 <https://reviews.llvm.org/rL366371>
- Update `stack_guard_remat.ll`


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

https://reviews.llvm.org/D64759

Files:
  llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
  llvm/test/CodeGen/AArch64/stack-guard-reassign.ll
  llvm/test/CodeGen/ARM/stack-guard-reassign.ll
  llvm/test/CodeGen/PowerPC/stack-guard-reassign.ll
  llvm/test/CodeGen/Thumb/stack_guard_remat.ll


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
@@ -3,6 +3,7 @@
 ; RUN: llc < %s -mtriple=thumb-apple-darwin -relocation-model=dynamic-no-pic -no-integrated-as | FileCheck %s  -check-prefix=NO-PIC -check-prefix=DYNAMIC-NO-PIC
 
 ;PIC:   foo2
+;PIC:   ldr {{r[0-9]+}}, {{LCPI[0-9_]+}}
 ;PIC:   ldr [[R0:r[0-9]+]], [[LABEL0:LCPI[0-9_]+]]
 ;PIC: [[LABEL1:LPC[0-9_]+]]:
 ;PIC:   add [[R0]], pc
@@ -13,9 +14,10 @@
 ;PIC-NEXT:   .long L___stack_chk_guard$non_lazy_ptr-([[LABEL1]]+4)
 
 ;NO-PIC:   foo2
+;NO-PIC:   ldr {{r[0-9]+}}, {{LCPI[0-9_]+}}
 ;NO-PIC:   ldr [[R0:r[0-9]+]], [[LABEL0:LCPI[0-9_]+]]
 ;NO-PIC-NOT: LPC
-;NO-PIC:   ldr {{r[0-9]+}}, {{\[}}[[R0]]{{\]}}
+;NO-PIC:   ldr [[R1:r[0-9]+]], {{\[}}[[R0]]{{\]}}
 
 ;STATIC:      [[LABEL0]]:
 ;STATIC-NEXT:   .long ___stack_chk_guard
Index: llvm/test/CodeGen/PowerPC/stack-guard-reassign.ll
===================================================================
--- llvm/test/CodeGen/PowerPC/stack-guard-reassign.ll
+++ llvm/test/CodeGen/PowerPC/stack-guard-reassign.ll
@@ -9,9 +9,8 @@
 ; CHECK-NEXT: ori 0, 0, 65488
 ; CHECK-NEXT: stwux 1, 1, 0
 ; CHECK-NEXT: subf 0, 0, 1
-; CHECK-NEXT: lis 4, 1
-; CHECK-NEXT: ori 4, 4, 44
-; CHECK-NEXT: add 4, 1, 4
-; CHECK-NEXT: lis 5, __stack_chk_guard at ha
-; CHECK-NEXT: lwz 6, __stack_chk_guard at l(5)
-; CHECK-NEXT: stw 6, 0(4)
+; CHECK-NEXT: lis 4, __stack_chk_guard at ha
+; CHECK-NEXT: lwz 5, __stack_chk_guard at l(4)
+; CHECK-NEXT: lis 6, 1
+; CHECK-NEXT: ori 6, 6, 44
+; CHECK-NEXT: stwx 5, 1, 6
Index: llvm/test/CodeGen/ARM/stack-guard-reassign.ll
===================================================================
--- llvm/test/CodeGen/ARM/stack-guard-reassign.ll
+++ llvm/test/CodeGen/ARM/stack-guard-reassign.ll
@@ -5,10 +5,9 @@
 ; CHECK-LABEL: fn:
 ; CHECK:      sub sp, sp, #32
 ; CHECK-NEXT: sub sp, sp, #65536
+; CHECK-NEXT: ldr r1, .LCPI0_0
+; CHECK-NEXT: ldr r2, [r1]
 ; CHECK-NEXT: add lr, sp, #65536
-; CHECK-NEXT: add r1, lr, #28
-; CHECK-NEXT: ldr r2, .LCPI0_0
-; CHECK-NEXT: ldr r3, [r2]
-; CHECK-NEXT: str r3, [r1]
+; CHECK-NEXT: str r2, [lr, #28]
 ; CHECK: .LCPI0_0:
 ; CHECK-NEXT: .long __stack_chk_guard
Index: llvm/test/CodeGen/AArch64/stack-guard-reassign.ll
===================================================================
--- llvm/test/CodeGen/AArch64/stack-guard-reassign.ll
+++ llvm/test/CodeGen/AArch64/stack-guard-reassign.ll
@@ -3,7 +3,6 @@
 ; Verify that the offset assigned to the stack protector is at the top of the
 ; frame, covering the locals.
 ; CHECK-LABEL: fn:
-; CHECK:      sub x8, x29, #24
-; CHECK-NEXT: adrp x9, __stack_chk_guard
-; CHECK-NEXT: ldr x9, [x9, :lo12:__stack_chk_guard]
-; CHECK-NEXT: str x9, [x8]
+; CHECK:      adrp x8, __stack_chk_guard
+; CHECK-NEXT: ldr x8, [x8, :lo12:__stack_chk_guard]
+; CHECK-NEXT: stur x8, [x29, #-24]
Index: llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
===================================================================
--- llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
+++ llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
@@ -351,6 +351,14 @@
     assert(MFI.isObjectPreAllocated(FrameIdx) &&
            "Only pre-allocated locals expected!");
 
+    // We need to keep the references to the stack protector slot through frame
+    // index operands so that it gets resolved by PEI rather than this pass.
+    // This avoids accesses to the stack protector though virtual base
+    // registers, and forces PEI to address it using fp/sp/bp.
+    if (MFI.hasStackProtectorIndex() &&
+        FrameIdx == MFI.getStackProtectorIndex())
+      continue;
+
     LLVM_DEBUG(dbgs() << "Considering: " << MI);
 
     unsigned idx = 0;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64759.211332.patch
Type: text/x-patch
Size: 3773 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190723/d00714ed/attachment.bin>


More information about the llvm-commits mailing list