Skip to content

Commit 78e621a

Browse files
andreisfrgerekon
authored andcommitted
[Xtensa] Fix vararg lowering.
1 parent e22126c commit 78e621a

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

llvm/lib/Target/Xtensa/XtensaISelLowering.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,12 +1007,21 @@ SDValue XtensaTargetLowering::LowerFormalArguments(
10071007
// which is a value necessary to VASTART.
10081008
int FI = MFI.CreateFixedObject(RegSize, VaArgOffset, true);
10091009
XtensaFI->setVarArgsInRegsFrameIndex(FI);
1010+
Register FrameReg = Subtarget.getRegisterInfo()->getFrameRegister(MF);
10101011

10111012
// Copy the integer registers that may have been used for passing varargs
10121013
// to the vararg save area.
10131014
for (unsigned I = Idx; I < ArgRegsNum; ++I, VaArgOffset += RegSize) {
10141015
const Register Reg = RegInfo.createVirtualRegister(RC);
1015-
RegInfo.addLiveIn(IntRegs[I], Reg);
1016+
1017+
// Argument passed in FrameReg we save in A8 (in emitPrologue),
1018+
// so load argument from A8
1019+
if (IntRegs[I] == FrameReg) {
1020+
RegInfo.addLiveIn(Xtensa::A8, Reg);
1021+
XtensaFI->setSaveFrameRegister();
1022+
} else {
1023+
RegInfo.addLiveIn(IntRegs[I], Reg);
1024+
}
10161025

10171026
SDValue ArgValue = DAG.getCopyFromReg(Chain, DL, Reg, RegTy);
10181027
FI = MFI.CreateFixedObject(RegSize, VaArgOffset, true);

llvm/test/CodeGen/Xtensa/vararg.ll

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,3 +543,24 @@ entry:
543543
call void @llvm.va_end(ptr %list)
544544
ret void
545545
}
546+
547+
define dso_local void @f0(i32 noundef %a, ...) #0 {
548+
; CHECK-LABEL: f0:
549+
; CHECK: .cfi_startproc
550+
; CHECK-NEXT: # %bb.0:
551+
; CHECK-NEXT: addi a8, a1, -32
552+
; CHECK-NEXT: or a1, a8, a8
553+
; CHECK-NEXT: .cfi_def_cfa_offset 32
554+
; CHECK-NEXT: s32i a7, a1, 20
555+
; CHECK-NEXT: s32i a6, a1, 16
556+
; CHECK-NEXT: s32i a5, a1, 12
557+
; CHECK-NEXT: s32i a4, a1, 8
558+
; CHECK-NEXT: s32i a3, a1, 4
559+
; CHECK-NEXT: s32i a2, a1, 0
560+
; CHECK-NEXT: addi a8, a1, 32
561+
; CHECK-NEXT: or a1, a8, a8
562+
; CHECK-NEXT: ret
563+
%b = alloca i32, align 4
564+
store i32 %a, ptr %b, align 4
565+
ret void
566+
}

0 commit comments

Comments
 (0)