[llvm] d6cc7a5 - [FastISel] Respect musttail over "disable-tail-calls"

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 23 08:55:53 PDT 2022


Author: Arthur Eubanks
Date: 2022-08-23T08:55:40-07:00
New Revision: d6cc7a5b462bb290d281c3429af9fa0bad283b3d

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

LOG: [FastISel] Respect musttail over "disable-tail-calls"

musttail should be honored even in the presence of attributes like "disable-tail-calls". SelectionDAG properly handles this.

Update LangRef to explicitly mention that this is the semantics of musttail.

Reviewed By: rnk

Differential Revision: https://reviews.llvm.org/D132193

Added: 
    llvm/test/CodeGen/X86/fast-isel-disable-tail-calls.ll

Modified: 
    llvm/docs/LangRef.rst
    llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/LangRef.rst b/llvm/docs/LangRef.rst
index a8ce27b58dda2..c60abadf39d81 100644
--- a/llvm/docs/LangRef.rst
+++ b/llvm/docs/LangRef.rst
@@ -11657,7 +11657,8 @@ This instruction requires several arguments:
    should perform tail call optimization. The ``tail`` marker is a hint that
    `can be ignored <CodeGenerator.html#sibcallopt>`_. The ``musttail`` marker
    means that the call must be tail call optimized in order for the program to
-   be correct. The ``musttail`` marker provides these guarantees:
+   be correct. This is true even in the presence of attributes like
+   "disable-tail-calls". The ``musttail`` marker provides these guarantees:
 
    #. The call will not cause unbounded stack growth if it is part of a
       recursive cycle in the call graph.

diff  --git a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
index ff5779967e220..dc8688bd3cd3c 100644
--- a/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/FastISel.cpp
@@ -1139,9 +1139,8 @@ bool FastISel::lowerCall(const CallInst *CI) {
   bool IsTailCall = CI->isTailCall();
   if (IsTailCall && !isInTailCallPosition(*CI, TM))
     IsTailCall = false;
-  if (IsTailCall && MF->getFunction()
-                            .getFnAttribute("disable-tail-calls")
-                            .getValueAsBool())
+  if (IsTailCall && !CI->isMustTailCall() &&
+      MF->getFunction().getFnAttribute("disable-tail-calls").getValueAsBool())
     IsTailCall = false;
 
   CallLoweringInfo CLI;

diff  --git a/llvm/test/CodeGen/X86/fast-isel-disable-tail-calls.ll b/llvm/test/CodeGen/X86/fast-isel-disable-tail-calls.ll
new file mode 100644
index 0000000000000..c0aac5e1bd316
--- /dev/null
+++ b/llvm/test/CodeGen/X86/fast-isel-disable-tail-calls.ll
@@ -0,0 +1,9 @@
+; RUN: llc -O0 -fast-isel -mtriple=x86_64-unknown-unknown < %s | FileCheck %s
+
+; CHECK-NOT: retq
+; CHECK: jmpq
+
+define void @f(ptr %this) "disable-tail-calls"="true" {
+  musttail call void %this(ptr %this)
+  ret void
+}


        


More information about the llvm-commits mailing list