[llvm-branch-commits] [llvm-branch] r329634 - Merging r326376:

Tom Stellard via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Mon Apr 9 15:47:00 PDT 2018


Author: tstellar
Date: Mon Apr  9 15:47:00 2018
New Revision: 329634

URL: http://llvm.org/viewvc/llvm-project?rev=329634&view=rev
Log:
Merging r326376:

------------------------------------------------------------------------
r326376 | jdevlieghere | 2018-02-28 14:28:44 -0800 (Wed, 28 Feb 2018) | 12 lines

[GlobalOpt] don't change CC of musttail calle(e|r)

When the function has musttail call - its cc is fixed to be equal to the
cc of the musttail callee. In such case (and in the case of the musttail
callee), GlobalOpt should not change the cc to fastcc as it will break
the invariant.

This fixes PR36546

Patch by: Fedor Indutny (indutny)

Differential revision: https://reviews.llvm.org/D43859
------------------------------------------------------------------------

Added:
    llvm/branches/release_60/test/Transforms/GlobalOpt/musttail_cc.ll
Modified:
    llvm/branches/release_60/lib/Transforms/IPO/GlobalOpt.cpp

Modified: llvm/branches/release_60/lib/Transforms/IPO/GlobalOpt.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/lib/Transforms/IPO/GlobalOpt.cpp?rev=329634&r1=329633&r2=329634&view=diff
==============================================================================
--- llvm/branches/release_60/lib/Transforms/IPO/GlobalOpt.cpp (original)
+++ llvm/branches/release_60/lib/Transforms/IPO/GlobalOpt.cpp Mon Apr  9 15:47:00 2018
@@ -2099,8 +2099,31 @@ static void RemoveNestAttribute(Function
 /// GHC, or anyregcc.
 static bool isProfitableToMakeFastCC(Function *F) {
   CallingConv::ID CC = F->getCallingConv();
+
   // FIXME: Is it worth transforming x86_stdcallcc and x86_fastcallcc?
-  return CC == CallingConv::C || CC == CallingConv::X86_ThisCall;
+  if (CC != CallingConv::C && CC != CallingConv::X86_ThisCall)
+    return false;
+
+  // FIXME: Change CC for the whole chain of musttail calls when possible.
+  //
+  // Can't change CC of the function that either has musttail calls, or is a
+  // musttail callee itself
+  for (User *U : F->users()) {
+    if (isa<BlockAddress>(U))
+      continue;
+    CallInst* CI = dyn_cast<CallInst>(U);
+    if (!CI)
+      continue;
+
+    if (CI->isMustTailCall())
+      return false;
+  }
+
+  for (BasicBlock &BB : *F)
+    if (BB.getTerminatingMustTailCall())
+      return false;
+
+  return true;
 }
 
 static bool

Added: llvm/branches/release_60/test/Transforms/GlobalOpt/musttail_cc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_60/test/Transforms/GlobalOpt/musttail_cc.ll?rev=329634&view=auto
==============================================================================
--- llvm/branches/release_60/test/Transforms/GlobalOpt/musttail_cc.ll (added)
+++ llvm/branches/release_60/test/Transforms/GlobalOpt/musttail_cc.ll Mon Apr  9 15:47:00 2018
@@ -0,0 +1,34 @@
+; RUN: opt < %s -globalopt -S | FileCheck %s
+; PR36546
+
+; Check that musttail callee preserves its calling convention
+
+define i32 @test(i32 %a) {
+  ; CHECK: %ca = musttail call i32 @foo(i32 %a)
+  %ca = musttail call i32 @foo(i32 %a)
+  ret i32 %ca
+}
+
+; CHECK-LABEL: define internal i32 @foo(i32 %a)
+define internal i32 @foo(i32 %a) {
+  ret i32 %a
+}
+
+; Check that musttail caller preserves its calling convention
+
+define i32 @test2(i32 %a) {
+  %ca = call i32 @foo1(i32 %a)
+  ret i32 %ca
+}
+
+; CHECK-LABEL: define internal i32 @foo1(i32 %a)
+define internal i32 @foo1(i32 %a) {
+  ; CHECK: %ca = musttail call i32 @foo2(i32 %a)
+  %ca = musttail call i32 @foo2(i32 %a)
+  ret i32 %ca
+}
+
+; CHECK-LABEL: define internal i32 @foo2(i32 %a)
+define internal i32 @foo2(i32 %a) {
+  ret i32 %a
+}




More information about the llvm-branch-commits mailing list