Skip to content

[StatepointLowering] Take return attributes of gc.result into account #68439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion llvm/include/llvm/CodeGen/TargetLowering.h
Original file line number Diff line number Diff line change
@@ -4397,8 +4397,14 @@ class TargetLowering : public TargetLoweringBase {
}

CallLoweringInfo &setCallee(CallingConv::ID CC, Type *ResultType,
SDValue Target, ArgListTy &&ArgsList) {
SDValue Target, ArgListTy &&ArgsList,
AttributeSet ResultAttrs = {}) {
RetTy = ResultType;
IsInReg = ResultAttrs.hasAttribute(Attribute::InReg);
RetSExt = ResultAttrs.hasAttribute(Attribute::SExt);
RetZExt = ResultAttrs.hasAttribute(Attribute::ZExt);
NoMerge = ResultAttrs.hasAttribute(Attribute::NoMerge);

Callee = Target;
CallConv = CC;
NumFixedArgs = ArgsList.size();
7 changes: 4 additions & 3 deletions llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Original file line number Diff line number Diff line change
@@ -9728,7 +9728,7 @@ SDValue SelectionDAGBuilder::lowerRangeToAssertZExt(SelectionDAG &DAG,
void SelectionDAGBuilder::populateCallLoweringInfo(
TargetLowering::CallLoweringInfo &CLI, const CallBase *Call,
unsigned ArgIdx, unsigned NumArgs, SDValue Callee, Type *ReturnTy,
bool IsPatchPoint) {
AttributeSet RetAttrs, bool IsPatchPoint) {
TargetLowering::ArgListTy Args;
Args.reserve(NumArgs);

@@ -9749,7 +9749,8 @@ void SelectionDAGBuilder::populateCallLoweringInfo(

CLI.setDebugLoc(getCurSDLoc())
.setChain(getRoot())
.setCallee(Call->getCallingConv(), ReturnTy, Callee, std::move(Args))
.setCallee(Call->getCallingConv(), ReturnTy, Callee, std::move(Args),
RetAttrs)
.setDiscardResult(Call->use_empty())
.setIsPatchPoint(IsPatchPoint)
.setIsPreallocated(
@@ -9898,7 +9899,7 @@ void SelectionDAGBuilder::visitPatchpoint(const CallBase &CB,

TargetLowering::CallLoweringInfo CLI(DAG);
populateCallLoweringInfo(CLI, &CB, NumMetaOpers, NumCallArgs, Callee,
ReturnTy, true);
ReturnTy, CB.getAttributes().getRetAttrs(), true);
std::pair<SDValue, SDValue> Result = lowerInvokable(CLI, EHPadBB);

SDNode *CallEnd = Result.second.getNode();
3 changes: 2 additions & 1 deletion llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.h
Original file line number Diff line number Diff line change
@@ -426,7 +426,8 @@ class SelectionDAGBuilder {
void populateCallLoweringInfo(TargetLowering::CallLoweringInfo &CLI,
const CallBase *Call, unsigned ArgIdx,
unsigned NumArgs, SDValue Callee,
Type *ReturnTy, bool IsPatchPoint);
Type *ReturnTy, AttributeSet RetAttrs,
bool IsPatchPoint);

std::pair<SDValue, SDValue>
lowerInvokable(TargetLowering::CallLoweringInfo &CLI,
12 changes: 8 additions & 4 deletions llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
Original file line number Diff line number Diff line change
@@ -1033,10 +1033,16 @@ SelectionDAGBuilder::LowerStatepoint(const GCStatepointInst &I,
ActualCallee = Callee;
}

const auto GCResultLocality = getGCResultLocality(I);
AttributeSet retAttrs;
if (GCResultLocality.first)
retAttrs = GCResultLocality.first->getAttributes().getRetAttrs();

StatepointLoweringInfo SI(DAG);
populateCallLoweringInfo(SI.CLI, &I, GCStatepointInst::CallArgsBeginPos,
I.getNumCallArgs(), ActualCallee,
I.getActualReturnType(), false /* IsPatchPoint */);
I.getActualReturnType(), retAttrs,
/*IsPatchPoint=*/false);

// There may be duplication in the gc.relocate list; such as two copies of
// each relocation on normal and exceptional path for an invoke. We only
@@ -1092,8 +1098,6 @@ SelectionDAGBuilder::LowerStatepoint(const GCStatepointInst &I,
SDValue ReturnValue = LowerAsSTATEPOINT(SI);

// Export the result value if needed
const auto GCResultLocality = getGCResultLocality(I);

if (!GCResultLocality.first && !GCResultLocality.second) {
// The return value is not needed, just generate a poison value.
// Note: This covers the void return case.
@@ -1138,7 +1142,7 @@ void SelectionDAGBuilder::LowerCallSiteWithDeoptBundleImpl(
populateCallLoweringInfo(
SI.CLI, Call, ArgBeginIndex, Call->arg_size(), Callee,
ForceVoidReturnTy ? Type::getVoidTy(*DAG.getContext()) : Call->getType(),
false);
Call->getAttributes().getRetAttrs(), /*IsPatchPoint=*/false);
if (!VarArgDisallowed)
SI.CLI.IsVarArg = Call->getFunctionType()->isVarArg();

3 changes: 0 additions & 3 deletions llvm/test/CodeGen/AArch64/statepoint-call-lowering.ll
Original file line number Diff line number Diff line change
@@ -23,7 +23,6 @@ define i1 @test_i1_return() gc "statepoint-example" {
; CHECK-NEXT: .cfi_offset w30, -16
; CHECK-NEXT: bl return_i1
; CHECK-NEXT: .Ltmp0:
; CHECK-NEXT: and w0, w0, #0x1
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
; CHECK-NEXT: ret
; This is just checking that a i1 gets lowered normally when there's no extra
@@ -106,7 +105,6 @@ define i1 @test_relocate(ptr addrspace(1) %a) gc "statepoint-example" {
; CHECK-NEXT: .cfi_offset w30, -16
; CHECK-NEXT: bl return_i1
; CHECK-NEXT: .Ltmp5:
; CHECK-NEXT: and w0, w0, #0x1
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
; CHECK-NEXT: ret
; Check that an ununsed relocate has no code-generation impact
@@ -145,7 +143,6 @@ define i1 @test_i1_return_patchable() gc "statepoint-example" {
; CHECK-NEXT: .cfi_offset w30, -16
; CHECK-NEXT: nop
; CHECK-NEXT: .Ltmp7:
; CHECK-NEXT: and w0, w0, #0x1
; CHECK-NEXT: ldr x30, [sp], #16 // 8-byte Folded Reload
; CHECK-NEXT: ret
; A patchable variant of test_i1_return
21 changes: 18 additions & 3 deletions llvm/test/CodeGen/X86/statepoint-call-lowering.ll
Original file line number Diff line number Diff line change
@@ -247,8 +247,6 @@ define i8 @test_signext_return(ptr) gc "statepoint-example" {
; CHECK-NEXT: .cfi_def_cfa_offset 16
; CHECK-NEXT: callq signext_return_i1@PLT
; CHECK-NEXT: .Ltmp10:
; CHECK-NEXT: andb $1, %al
; CHECK-NEXT: negb %al
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: .cfi_def_cfa_offset 8
; CHECK-NEXT: retq
@@ -266,7 +264,6 @@ define i8 @test_zeroext_return() gc "statepoint-example" {
; CHECK-NEXT: .cfi_def_cfa_offset 16
; CHECK-NEXT: callq return_i1@PLT
; CHECK-NEXT: .Ltmp11:
; CHECK-NEXT: andb $1, %al
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: .cfi_def_cfa_offset 8
; CHECK-NEXT: retq
@@ -277,6 +274,24 @@ entry:
ret i8 %ext
}

define signext i1 @test_noext_signext_return() gc "statepoint-example" {
; CHECK-LABEL: test_noext_signext_return:
; CHECK: # %bb.0: # %entry
; CHECK-NEXT: pushq %rax
; CHECK-NEXT: .cfi_def_cfa_offset 16
; CHECK-NEXT: callq return_i1@PLT
; CHECK-NEXT: .Ltmp12:
; CHECK-NEXT: andb $1, %al
; CHECK-NEXT: negb %al
; CHECK-NEXT: popq %rcx
; CHECK-NEXT: .cfi_def_cfa_offset 8
; CHECK-NEXT: retq
entry:
%safepoint_token = tail call token (i64, i32, ptr, i32, i32, ...) @llvm.experimental.gc.statepoint.p0(i64 0, i32 0, ptr elementtype(i1 ()) @return_i1, i32 0, i32 0, i32 0, i32 0)
%call1 = call i1 @llvm.experimental.gc.result.i1(token %safepoint_token)
ret i1 %call1
}

declare token @llvm.experimental.gc.statepoint.p0(i64, i32, ptr, i32, i32, ...)
declare i1 @llvm.experimental.gc.result.i1(token)