OSDN Git Service

[Hexagon] Allow tail-call optimization when mixing C and fast calling conv
authorKrzysztof Parzyszek <kparzysz@codeaurora.org>
Fri, 19 Aug 2016 15:02:18 +0000 (15:02 +0000)
committerKrzysztof Parzyszek <kparzysz@codeaurora.org>
Fri, 19 Aug 2016 15:02:18 +0000 (15:02 +0000)
Patch by Arnold Schwaighofer.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@279251 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Hexagon/HexagonISelLowering.cpp
test/CodeGen/Hexagon/tailcall_fastcc_ccc.ll [new file with mode: 0644]

index 2714a19..fad6c98 100644 (file)
@@ -3143,9 +3143,15 @@ bool HexagonTargetLowering::IsEligibleForTailCallOptimization(
     return false;
   }
 
-  // Do not optimize if the calling conventions do not match.
-  if (!CCMatch)
-    return false;
+  // Do not optimize if the calling conventions do not match and the conventions
+  // used are not C or Fast.
+  if (!CCMatch) {
+    bool R = (CallerCC == CallingConv::C || CallerCC == CallingConv::Fast);
+    bool E = (CalleeCC == CallingConv::C || CalleeCC == CallingConv::Fast);
+    // If R & E, then ok.
+    if (!R || !E)
+      return false;
+  }
 
   // Do not tail call optimize vararg calls.
   if (isVarArg)
diff --git a/test/CodeGen/Hexagon/tailcall_fastcc_ccc.ll b/test/CodeGen/Hexagon/tailcall_fastcc_ccc.ll
new file mode 100644 (file)
index 0000000..479fc15
--- /dev/null
@@ -0,0 +1,22 @@
+; RUN: llc -march=hexagon < %s | FileCheck %s
+
+target triple = "hexagon"
+
+declare hidden fastcc void @callee(i32, i32) #0
+declare hidden void @callee2(i32, i32) #0
+
+; CHECK: jump callee
+define void @caller(i32 %pp) #0 {
+entry:
+  tail call fastcc void @callee(i32 %pp, i32 0)
+  ret void
+}
+
+; CHECK: jump callee2
+define void @caller2(i32 %pp) #0 {
+entry:
+  tail call fastcc void @callee2(i32 %pp, i32 0)
+  ret void
+}
+
+attributes #0 = { nounwind }