[Analysis] Attribute noundef should not prevent tail call optimization
authorDávid Bolvanský <david.bolvansky@gmail.com>
Mon, 31 Jan 2022 12:45:07 +0000 (13:45 +0100)
committerDávid Bolvanský <david.bolvansky@gmail.com>
Mon, 31 Jan 2022 14:13:52 +0000 (15:13 +0100)
Very similar to https://reviews.llvm.org/D101230
Fixes https://github.com/llvm/llvm-project/issues/53501

llvm/lib/CodeGen/Analysis.cpp
llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
llvm/test/CodeGen/X86/tail-calls-compatible-attrs.ll

index e8fef50..cdf5586 100644 (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);
   }
index ff57725..cdd51bb 100644 (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())
index e7f38a7..ab876f4 100644 (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
+}