[llvm-commits] [llvm] r67934 - in /llvm/trunk: include/llvm/Target/TargetLowering.h lib/CodeGen/SelectionDAG/TargetLowering.cpp test/CodeGen/X86/tailcall-i1.ll test/CodeGen/X86/tailcall-structret.ll

Arnold Schwaighofer arnold.schwaighofer at gmail.com
Sat Mar 28 01:33:28 PDT 2009


Author: arnolds
Date: Sat Mar 28 03:33:27 2009
New Revision: 67934

URL: http://llvm.org/viewvc/llvm-project?rev=67934&view=rev
Log:
Enable tail call optimization for functions that return a struct (bug 3664) and for functions that return types that need extending (e.g i1).

Added:
    llvm/trunk/test/CodeGen/X86/tailcall-i1.ll
    llvm/trunk/test/CodeGen/X86/tailcall-structret.ll
Modified:
    llvm/trunk/include/llvm/Target/TargetLowering.h
    llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Modified: llvm/trunk/include/llvm/Target/TargetLowering.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLowering.h?rev=67934&r1=67933&r2=67934&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLowering.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLowering.h Sat Mar 28 03:33:27 2009
@@ -1206,18 +1206,7 @@
   /// preceeds the RET node and whether the return uses the result of the node
   /// or is a void return. This function can be used by the target to determine
   /// eligiblity of tail call optimization.
-  static bool CheckTailCallReturnConstraints(CallSDNode *TheCall, SDValue Ret) {
-    unsigned NumOps = Ret.getNumOperands();
-    if ((NumOps == 1 &&
-       (Ret.getOperand(0) == SDValue(TheCall,1) ||
-        Ret.getOperand(0) == SDValue(TheCall,0))) ||
-      (NumOps > 1 &&
-       Ret.getOperand(0) == SDValue(TheCall,
-                                    TheCall->getNumValues()-1) &&
-       Ret.getOperand(1) == SDValue(TheCall,0)))
-      return true;
-    return false;
-  }
+  static bool CheckTailCallReturnConstraints(CallSDNode *TheCall, SDValue Ret); 
 
   /// GetPossiblePreceedingTailCall - Get preceeding TailCallNodeOpCode node if
   /// it exists. Skip a possible ISD::TokenFactor.

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=67934&r1=67933&r2=67934&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Sat Mar 28 03:33:27 2009
@@ -2571,3 +2571,27 @@
                        DAG.getConstant(magics.s-1, getShiftAmountTy()));
   }
 }
+
+bool TargetLowering::CheckTailCallReturnConstraints(CallSDNode *TheCall, SDValue Ret) {
+  unsigned NumOps = Ret.getNumOperands();
+  // Struct return.
+  if(NumOps >= 5&&
+      Ret.getOperand(1).getOpcode()==ISD::MERGE_VALUES &&
+      Ret.getOperand(1).getOperand(0) == SDValue(TheCall, 0))
+    return true;
+  if ((NumOps == 1 &&
+        (Ret.getOperand(0) == SDValue(TheCall,1) ||
+         Ret.getOperand(0) == SDValue(TheCall,0))) ||
+      (NumOps == 3 &&
+       Ret.getOperand(1).getOpcode() == ISD::ANY_EXTEND && 
+       Ret.getOperand(1).getNumOperands()>0 &&
+       Ret.getOperand(1).getOperand(0).getOpcode() == ISD::TRUNCATE &&
+       Ret.getOperand(1).getOperand(0).getNumOperands()>0 &&
+       Ret.getOperand(1).getOperand(0).getOperand(0) == SDValue(TheCall, 0)) ||
+      (NumOps > 1 &&
+       Ret.getOperand(0) == SDValue(TheCall,
+         TheCall->getNumValues()-1) &&
+       Ret.getOperand(1) == SDValue(TheCall,0)))
+    return true;
+  return false;
+}

Added: llvm/trunk/test/CodeGen/X86/tailcall-i1.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcall-i1.ll?rev=67934&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall-i1.ll (added)
+++ llvm/trunk/test/CodeGen/X86/tailcall-i1.ll Sat Mar 28 03:33:27 2009
@@ -0,0 +1,6 @@
+; RUN: llvm-as < %s | llc -march=x86 -tailcallopt | grep TAILCALL
+define fastcc i1 @i1test(i32, i32, i32, i32) {
+  entry:
+  %4 = tail call fastcc i1 @i1test( i32 %0, i32 %1, i32 %2, i32 %3)
+  ret i1 %4
+}

Added: llvm/trunk/test/CodeGen/X86/tailcall-structret.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcall-structret.ll?rev=67934&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall-structret.ll (added)
+++ llvm/trunk/test/CodeGen/X86/tailcall-structret.ll Sat Mar 28 03:33:27 2009
@@ -0,0 +1,6 @@
+; RUN: llvm-as < %s | llc -march=x86 -tailcallopt | grep TAILCALL
+define fastcc { { i8*, i8* }*, i8*} @init({ { i8*, i8* }*, i8*}, i32) {
+entry:
+      %2 = tail call fastcc { { i8*, i8* }*, i8* } @init({ { i8*, i8*}*, i8*} %0, i32 %1)
+      ret { { i8*, i8* }*, i8*} %2
+}





More information about the llvm-commits mailing list