diff options
author | Kai Luo <lkail@cn.ibm.com> | 2020-07-22 04:13:18 +0000 |
---|---|---|
committer | Hans Wennborg <hans@chromium.org> | 2020-07-22 15:58:00 +0200 |
commit | e95e071b6b68929527570cb830e5f3bc8b992e04 (patch) | |
tree | d212e564a63443cb751f2dcc8a849509480661d0 | |
parent | ba5bbd4bd00f8aacf379cdcb738b149a1f63166a (diff) | |
download | llvm-e95e071b6b68929527570cb830e5f3bc8b992e04.zip llvm-e95e071b6b68929527570cb830e5f3bc8b992e04.tar.gz llvm-e95e071b6b68929527570cb830e5f3bc8b992e04.tar.bz2 |
[PowerPC] Fix wrong codegen when stack pointer has to realign in prologue
Current powerpc backend generates wrong code sequence if stack pointer
has to realign if -fstack-clash-protection enabled. When probing in
prologue, backend should generate a subtraction instruction rather
than a `stux` instruction to realign the stack pointer.
This patch is part of fix of
https://bugs.llvm.org/show_bug.cgi?id=46759.
Differential Revision: https://reviews.llvm.org/D84218
(cherry picked from commit 8912252252c87d8ef6623ecf9fdde444560ee4b9)
-rw-r--r-- | llvm/lib/Target/PowerPC/PPCFrameLowering.cpp | 7 | ||||
-rw-r--r-- | llvm/test/CodeGen/PowerPC/pr46759.ll | 2 |
2 files changed, 4 insertions, 5 deletions
diff --git a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp index bd9174c..2ee394e 100644 --- a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp +++ b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp @@ -1466,11 +1466,10 @@ void PPCFrameLowering::inlineStackProbe(MachineFunction &MF, .addImm(0) .addImm(32 - Log2(MaxAlign)) .addImm(31); - BuildMI(PrologMBB, {MI}, DL, TII.get(isPPC64 ? PPC::STDUX : PPC::STWUX), + BuildMI(PrologMBB, {MI}, DL, TII.get(isPPC64 ? PPC::SUBFC8 : PPC::SUBFC), SPReg) - .addReg(FPReg) - .addReg(SPReg) - .addReg(ScratchReg); + .addReg(ScratchReg) + .addReg(SPReg); } // Probe residual part. if (NegResidualSize) { diff --git a/llvm/test/CodeGen/PowerPC/pr46759.ll b/llvm/test/CodeGen/PowerPC/pr46759.ll index 2c0af89..4d3e8ca 100644 --- a/llvm/test/CodeGen/PowerPC/pr46759.ll +++ b/llvm/test/CodeGen/PowerPC/pr46759.ll @@ -12,7 +12,7 @@ define void @foo(i32 %vla_size) #0 { ; CHECK-LE-NEXT: mr r12, r1 ; CHECK-LE-NEXT: .cfi_def_cfa r12, 0 ; CHECK-LE-NEXT: clrldi r0, r12, 53 -; CHECK-LE-NEXT: stdux r12, r1, r0 +; CHECK-LE-NEXT: subc r1, r1, r0 ; CHECK-LE-NEXT: stdu r12, -2048(r1) ; CHECK-LE-NEXT: stdu r12, -4096(r1) ; CHECK-LE-NEXT: .cfi_def_cfa_register r1 |