Skip to content

Commit 8912252

Browse files
author
Kai Luo
committed
[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
1 parent e9f5ca0 commit 8912252

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

llvm/lib/Target/PowerPC/PPCFrameLowering.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1466,11 +1466,10 @@ void PPCFrameLowering::inlineStackProbe(MachineFunction &MF,
14661466
.addImm(0)
14671467
.addImm(32 - Log2(MaxAlign))
14681468
.addImm(31);
1469-
BuildMI(PrologMBB, {MI}, DL, TII.get(isPPC64 ? PPC::STDUX : PPC::STWUX),
1469+
BuildMI(PrologMBB, {MI}, DL, TII.get(isPPC64 ? PPC::SUBFC8 : PPC::SUBFC),
14701470
SPReg)
1471-
.addReg(FPReg)
1472-
.addReg(SPReg)
1473-
.addReg(ScratchReg);
1471+
.addReg(ScratchReg)
1472+
.addReg(SPReg);
14741473
}
14751474
// Probe residual part.
14761475
if (NegResidualSize) {

llvm/test/CodeGen/PowerPC/pr46759.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ define void @foo(i32 %vla_size) #0 {
1212
; CHECK-LE-NEXT: mr r12, r1
1313
; CHECK-LE-NEXT: .cfi_def_cfa r12, 0
1414
; CHECK-LE-NEXT: clrldi r0, r12, 53
15-
; CHECK-LE-NEXT: stdux r12, r1, r0
15+
; CHECK-LE-NEXT: subc r1, r1, r0
1616
; CHECK-LE-NEXT: stdu r12, -2048(r1)
1717
; CHECK-LE-NEXT: stdu r12, -4096(r1)
1818
; CHECK-LE-NEXT: .cfi_def_cfa_register r1

0 commit comments

Comments
 (0)