[llvm] 7a56dc7 - [Clang] Attribute NoFPClass should not prevent tail call optimization. (#116741)

via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 22 17:28:49 PST 2024


Author: FĂ©lix-Antoine Constantin
Date: 2024-11-22T17:28:45-08:00
New Revision: 7a56dc724594691efce13d771902478544696182

URL: https://github.com/llvm/llvm-project/commit/7a56dc724594691efce13d771902478544696182
DIFF: https://github.com/llvm/llvm-project/commit/7a56dc724594691efce13d771902478544696182.diff

LOG: [Clang] Attribute NoFPClass should not prevent tail call optimization. (#116741)

Fixes #111950

Added: 
    llvm/test/CodeGen/X86/tailcall-nofpclass.ll

Modified: 
    llvm/lib/CodeGen/Analysis.cpp
    llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp
index f77b733c6c8f69..e7b9417de8c9f7 100644
--- a/llvm/lib/CodeGen/Analysis.cpp
+++ b/llvm/lib/CodeGen/Analysis.cpp
@@ -596,10 +596,10 @@ bool llvm::attributesPermitTailCall(const Function *F, const Instruction *I,
 
   // Following attributes are completely benign as far as calling convention
   // 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::NoUndef, Attribute::Range}) {
+  for (const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,
+                           Attribute::DereferenceableOrNull, Attribute::NoAlias,
+                           Attribute::NonNull, Attribute::NoUndef,
+                           Attribute::Range, Attribute::NoFPClass}) {
     CallerAttrs.removeAttribute(Attr);
     CalleeAttrs.removeAttribute(Attr);
   }

diff  --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index 8fbab337cab6f0..bd4bcadb57d7a9 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -61,10 +61,10 @@ bool TargetLowering::isInTailCallPosition(SelectionDAG &DAG, SDNode *Node,
   // the return. Ignore following attributes because they don't affect the
   // call sequence.
   AttrBuilder CallerAttrs(F.getContext(), F.getAttributes().getRetAttrs());
-  for (const auto &Attr :
-       {Attribute::Alignment, Attribute::Dereferenceable,
-        Attribute::DereferenceableOrNull, Attribute::NoAlias,
-        Attribute::NonNull, Attribute::NoUndef, Attribute::Range})
+  for (const auto &Attr : {Attribute::Alignment, Attribute::Dereferenceable,
+                           Attribute::DereferenceableOrNull, Attribute::NoAlias,
+                           Attribute::NonNull, Attribute::NoUndef,
+                           Attribute::Range, Attribute::NoFPClass})
     CallerAttrs.removeAttribute(Attr);
 
   if (CallerAttrs.hasAttributes())

diff  --git a/llvm/test/CodeGen/X86/tailcall-nofpclass.ll b/llvm/test/CodeGen/X86/tailcall-nofpclass.ll
new file mode 100644
index 00000000000000..fd085bb1244fb7
--- /dev/null
+++ b/llvm/test/CodeGen/X86/tailcall-nofpclass.ll
@@ -0,0 +1,13 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=x86_64-linux < %s | FileCheck %s
+
+; Ensures that taillcall optimization can still be
+; performed when nofpclass is used.
+
+define noundef nofpclass(nan inf) float @_Z3foof(float noundef nofpclass(nan inf) %0) {
+; CHECK-LABEL: _Z3foof:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    jmp expf at PLT # TAILCALL
+  %2 = tail call float @llvm.exp.f32(float %0)
+  ret float %2
+}


        


More information about the llvm-commits mailing list