Skip to content

Commit 3c8c557

Browse files
committed
Merging r368164:
------------------------------------------------------------------------ r368164 | s.desmalen | 2019-08-07 14:41:38 +0200 (Wed, 07 Aug 2019) | 13 lines [AArch64][WinCFI] Do not pair callee-save instructions in LoadStoreOptimizer Prevent the LoadStoreOptimizer from pairing any load/store instructions with instructions from the prologue/epilogue if the CFI information has encoded the operations as separate instructions. This would otherwise lead to a mismatch of the actual prologue size from the size as recorded in the Windows CFI. Reviewers: efriedma, mstorsjo, ssijaric Reviewed By: efriedma Differential Revision: https://reviews.llvm.org/D65817 ------------------------------------------------------------------------ llvm-svn: 370438
1 parent 16d2d31 commit 3c8c557

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "llvm/CodeGen/TargetSubtargetInfo.h"
3333
#include "llvm/IR/DebugLoc.h"
3434
#include "llvm/IR/GlobalValue.h"
35+
#include "llvm/MC/MCAsmInfo.h"
3536
#include "llvm/MC/MCInst.h"
3637
#include "llvm/MC/MCInstrDesc.h"
3738
#include "llvm/Support/Casting.h"
@@ -1928,6 +1929,17 @@ bool AArch64InstrInfo::isCandidateToMergeOrPair(const MachineInstr &MI) const {
19281929
if (isLdStPairSuppressed(MI))
19291930
return false;
19301931

1932+
// Do not pair any callee-save store/reload instructions in the
1933+
// prologue/epilogue if the CFI information encoded the operations as separate
1934+
// instructions, as that will cause the size of the actual prologue to mismatch
1935+
// with the prologue size recorded in the Windows CFI.
1936+
const MCAsmInfo *MAI = MI.getMF()->getTarget().getMCAsmInfo();
1937+
bool NeedsWinCFI = MAI->usesWindowsCFI() &&
1938+
MI.getMF()->getFunction().needsUnwindTableEntry();
1939+
if (NeedsWinCFI && (MI.getFlag(MachineInstr::FrameSetup) ||
1940+
MI.getFlag(MachineInstr::FrameDestroy)))
1941+
return false;
1942+
19311943
// On some CPUs quad load/store pairs are slower than two single load/stores.
19321944
if (Subtarget.isPaired128Slow()) {
19331945
switch (MI.getOpcode()) {

llvm/test/CodeGen/AArch64/wineh1.mir

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# RUN: llc -o - %s -mtriple=aarch64-windows -start-after=prologepilog -filetype=obj \
22
# RUN: | llvm-readobj --unwind | FileCheck %s
3+
# RUN: llc -o - %s -mtriple=aarch64-windows -run-pass=aarch64-ldst-opt \
4+
# RUN: | FileCheck %s --check-prefix=CHECK-LDSTOPT
35
# This test case checks the basic validity of the .xdata section. It's
46
# documented at:
57
# https://docs.microsoft.com/en-us/cpp/build/arm64-exception-handling
68

79
# We expect to see the following in the .xdata section:
810

911
# CHECK: ExceptionData {
10-
# CHECK-NEXT: FunctionLength: 92
12+
# CHECK-NEXT: FunctionLength: 96
1113
# CHECK-NEXT: Version: 0
1214
# CHECK-NEXT: ExceptionData: No
1315
# CHECK-NEXT: EpiloguePacked: No
@@ -24,7 +26,7 @@
2426
# CHECK-NEXT: ]
2527
# CHECK-NEXT: EpilogueScopes [
2628
# CHECK-NEXT: EpilogueScope {
27-
# CHECK-NEXT: StartOffset: 15
29+
# CHECK-NEXT: StartOffset: 16
2830
# CHECK-NEXT: EpilogueStartIndex: 13
2931
# CHECK-NEXT: Opcodes [
3032
# CHECK-NEXT: 0xc808 ; ldp x19, x20, [sp, #64]
@@ -39,6 +41,12 @@
3941
# CHECK-NEXT: }
4042
# CHECK-NEXT: ]
4143
# CHECK-NEXT: }
44+
45+
# Check that the load-store optimizer does not merge the two
46+
# callee-saved stores in the prologue.
47+
# CHECK-LDSTOPT: name: test
48+
# CHECK-LDSTOPT: frame-setup STRXui killed $x21, $sp, 6
49+
# CHECK-LDSTOPT: frame-setup STRXui killed $x22, $sp, 7
4250
...
4351
---
4452
name: test

llvm/test/CodeGen/AArch64/wineh2.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Test that the pre/post increment save of a flating point register is correct.
44

55
# CHECK: ExceptionData {
6-
# CHECK-NEXT: FunctionLength: 136
6+
# CHECK-NEXT: FunctionLength: 144
77
# CHECK-NEXT: Version: 0
88
# CHECK-NEXT: ExceptionData: No
99
# CHECK-NEXT: EpiloguePacked: No
@@ -23,7 +23,7 @@
2323
# CHECK-NEXT: ]
2424
# CHECK-NEXT: EpilogueScopes [
2525
# CHECK-NEXT: EpilogueScope {
26-
# CHECK-NEXT: StartOffset: 25
26+
# CHECK-NEXT: StartOffset: 26
2727
# CHECK-NEXT: EpilogueStartIndex: 19
2828
# CHECK-NEXT: Opcodes [
2929
# CHECK-NEXT: 0xc80e ; ldp x19, x20, [sp, #112]

llvm/test/DebugInfo/COFF/AArch64/arm64-register-variables.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
; OBJ: OffsetInParent: 0
2929
; OBJ: BasePointerOffset: 12
3030
; OBJ: LocalVariableAddrRange {
31-
; OBJ: OffsetStart: .text+0x10
31+
; OBJ: OffsetStart: .text+0x14
3232
; OBJ: ISectStart: 0x0
33-
; OBJ: Range: 0x2C
33+
; OBJ: Range: 0x30
3434
; OBJ: }
3535
; OBJ: }
3636

0 commit comments

Comments
 (0)