Skip to content

Commit 2e39ea7

Browse files
committed
Revert "Revert rG6078f2fedcac5797ac39ee5ef3fd7a35ef1202d5 - "[AArch64][GlobalISel]: Support @llvm.{return,frame}address selection.""
The original change wasn't constraining the operand regclasses which broke EXPENSIVE_CHECKS.
1 parent 082962d commit 2e39ea7

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

llvm/lib/Target/AArch64/AArch64InstructionSelector.cpp

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4091,7 +4091,7 @@ bool AArch64InstructionSelector::selectIntrinsic(
40914091
switch (IntrinID) {
40924092
default:
40934093
break;
4094-
case Intrinsic::aarch64_crypto_sha1h:
4094+
case Intrinsic::aarch64_crypto_sha1h: {
40954095
Register DstReg = I.getOperand(0).getReg();
40964096
Register SrcReg = I.getOperand(2).getReg();
40974097

@@ -4130,6 +4130,46 @@ bool AArch64InstructionSelector::selectIntrinsic(
41304130
I.eraseFromParent();
41314131
return true;
41324132
}
4133+
case Intrinsic::frameaddress:
4134+
case Intrinsic::returnaddress: {
4135+
MachineFunction &MF = *I.getParent()->getParent();
4136+
MachineFrameInfo &MFI = MF.getFrameInfo();
4137+
4138+
unsigned Depth = I.getOperand(2).getImm();
4139+
Register DstReg = I.getOperand(0).getReg();
4140+
RBI.constrainGenericRegister(DstReg, AArch64::GPR64RegClass, MRI);
4141+
4142+
if (Depth == 0 && IntrinID == Intrinsic::returnaddress) {
4143+
MFI.setReturnAddressIsTaken(true);
4144+
MF.addLiveIn(AArch64::LR, &AArch64::GPR64spRegClass);
4145+
I.getParent()->addLiveIn(AArch64::LR);
4146+
MIRBuilder.buildCopy({DstReg}, {Register(AArch64::LR)});
4147+
I.eraseFromParent();
4148+
return true;
4149+
}
4150+
4151+
MFI.setFrameAddressIsTaken(true);
4152+
Register FrameAddr(AArch64::FP);
4153+
while (Depth--) {
4154+
Register NextFrame = MRI.createVirtualRegister(&AArch64::GPR64spRegClass);
4155+
auto Ldr =
4156+
MIRBuilder.buildInstr(AArch64::LDRXui, {NextFrame}, {FrameAddr})
4157+
.addImm(0);
4158+
constrainSelectedInstRegOperands(*Ldr, TII, TRI, RBI);
4159+
FrameAddr = NextFrame;
4160+
}
4161+
4162+
if (IntrinID == Intrinsic::frameaddress)
4163+
MIRBuilder.buildCopy({DstReg}, {FrameAddr});
4164+
else {
4165+
MFI.setReturnAddressIsTaken(true);
4166+
MIRBuilder.buildInstr(AArch64::LDRXui, {DstReg}, {FrameAddr}).addImm(1);
4167+
}
4168+
4169+
I.eraseFromParent();
4170+
return true;
4171+
}
4172+
}
41334173
return false;
41344174
}
41354175

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; RUN: llc -mtriple=arm64-apple-ios -global-isel -o - %s | FileCheck %s
2+
3+
define i8* @rt0(i32 %x) nounwind readnone {
4+
entry:
5+
; CHECK-LABEL: rt0:
6+
; CHECK: mov x0, x29
7+
%0 = tail call i8* @llvm.frameaddress(i32 0)
8+
ret i8* %0
9+
}
10+
11+
define i8* @rt2() nounwind readnone {
12+
entry:
13+
; CHECK-LABEL: rt2:
14+
; CHECK: ldr x[[reg:[0-9]+]], [x29]
15+
; CHECK: ldr x0, [x[[reg]]]
16+
%0 = tail call i8* @llvm.frameaddress(i32 2)
17+
ret i8* %0
18+
}
19+
20+
declare i8* @llvm.frameaddress(i32) nounwind readnone
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
; RUN: llc -mtriple=arm64-apple-ios -global-isel -o - %s | FileCheck %s
2+
3+
define i8* @rt0(i32 %x) nounwind readnone {
4+
entry:
5+
; CHECK-LABEL: rt0:
6+
; CHECK-NOT: stp
7+
; CHECK: mov x0, x30
8+
%0 = tail call i8* @llvm.returnaddress(i32 0)
9+
ret i8* %0
10+
}
11+
12+
define i8* @rt2() nounwind readnone {
13+
entry:
14+
; CHECK-LABEL: rt2:
15+
; CHECK: ldr x[[reg:[0-9]+]], [x29]
16+
; CHECK: ldr x[[reg]], [x[[reg]]]
17+
; CHECK: ldr x0, [x[[reg]], #8]
18+
%0 = tail call i8* @llvm.returnaddress(i32 2)
19+
ret i8* %0
20+
}
21+
22+
declare i8* @llvm.returnaddress(i32) nounwind readnone

0 commit comments

Comments
 (0)