[Analysis] Attribute noundef should not prevent tail call optimization

Very similar to https://reviews.llvm.org/D101230
Fixes https://github.com/llvm/llvm-project/issues/53501
This commit is contained in:
Dávid Bolvanský 2022-01-31 13:45:07 +01:00
parent 7ec8fc2932
commit ae990a3cbd
3 changed files with 19 additions and 2 deletions

View File

@ -585,7 +585,7 @@ bool llvm::attributesPermitTailCall(const Function *F, const Instruction *I,
// goes, they shouldn't affect whether the call is a tail call.
for (const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,
Attribute::DereferenceableOrNull, Attribute::NoAlias,
Attribute::NonNull}) {
Attribute::NonNull, Attribute::NoUndef}) {
CallerAttrs.removeAttribute(Attr);
CalleeAttrs.removeAttribute(Attr);
}

View File

@ -63,7 +63,7 @@ bool TargetLowering::isInTailCallPosition(SelectionDAG &DAG, SDNode *Node,
AttrBuilder CallerAttrs(F.getContext(), F.getAttributes().getRetAttrs());
for (const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,
Attribute::DereferenceableOrNull, Attribute::NoAlias,
Attribute::NonNull})
Attribute::NonNull, Attribute::NoUndef})
CallerAttrs.removeAttribute(Attr);
if (CallerAttrs.hasAttributes())

View File

@ -50,3 +50,20 @@ define i8* @test6() nounwind {
%ret = tail call align 8 i8* @foo()
ret i8* %ret
}
define noundef i8* @test7() nounwind {
; CHECK-LABEL: test7:
; CHECK: # %bb.0:
; CHECK-NEXT: jmp foo # TAILCALL
%ret = tail call i8* @foo()
ret i8* %ret
}
define i8* @test8() nounwind {
; CHECK-LABEL: test8:
; CHECK: # %bb.0:
; CHECK-NEXT: jmp foo # TAILCALL
%ret = tail call noundef i8* @foo()
ret i8* %ret
}