[llvm-commits] [llvm] r43630 - in /llvm/trunk: lib/Target/X86/X86ISelLowering.cpp test/CodeGen/X86/2007-11-01-ISelCrash.ll

Evan Cheng evan.cheng at apple.com
Thu Nov 1 18:26:22 PDT 2007


Author: evancheng
Date: Thu Nov  1 20:26:22 2007
New Revision: 43630

URL: http://llvm.org/viewvc/llvm-project?rev=43630&view=rev
Log:
Missing a getNumOperands check.

Added:
    llvm/trunk/test/CodeGen/X86/2007-11-01-ISelCrash.ll
Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=43630&r1=43629&r2=43630&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Thu Nov  1 20:26:22 2007
@@ -1451,42 +1451,45 @@
 }
 
 /// IsEligibleForTailCallElimination - Check to see whether the next instruction
-// following the call is a return. A function is eligible if caller/callee
-// calling conventions match, currently only fastcc supports tail calls, and the
-// function CALL is immediatly followed by a RET.
+/// following the call is a return. A function is eligible if caller/callee
+/// calling conventions match, currently only fastcc supports tail calls, and
+/// the function CALL is immediatly followed by a RET.
 bool X86TargetLowering::IsEligibleForTailCallOptimization(SDOperand Call,
                                                       SDOperand Ret,
                                                       SelectionDAG& DAG) const {
-  bool IsEligible = false;
+  if (!PerformTailCallOpt)
+    return false;
 
   // Check whether CALL node immediatly preceeds the RET node and whether the
   // return uses the result of the node or is a void return.
-  if ((Ret.getNumOperands() == 1 && 
-       (Ret.getOperand(0)== SDOperand(Call.Val,1) ||
-        Ret.getOperand(0)== SDOperand(Call.Val,0))) ||
-      (Ret.getOperand(0)== SDOperand(Call.Val,Call.Val->getNumValues()-1) &&
-       Ret.getOperand(1)== SDOperand(Call.Val,0))) {
+  unsigned NumOps = Ret.getNumOperands();
+  if ((NumOps == 1 && 
+       (Ret.getOperand(0) == SDOperand(Call.Val,1) ||
+        Ret.getOperand(0) == SDOperand(Call.Val,0))) ||
+      (NumOps == 2 &&
+       Ret.getOperand(0) == SDOperand(Call.Val,Call.Val->getNumValues()-1) &&
+       Ret.getOperand(1) == SDOperand(Call.Val,0))) {
     MachineFunction &MF = DAG.getMachineFunction();
     unsigned CallerCC = MF.getFunction()->getCallingConv();
     unsigned CalleeCC = cast<ConstantSDNode>(Call.getOperand(1))->getValue();
     if (CalleeCC == CallingConv::Fast && CallerCC == CalleeCC) {
       SDOperand Callee = Call.getOperand(4);
       // On elf/pic %ebx needs to be livein.
-      if(getTargetMachine().getRelocationModel() == Reloc::PIC_ &&
-         Subtarget->isPICStyleGOT()) {
-        // Can only do local tail calls with PIC.
-        GlobalValue * GV = 0;
-        GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
-        if(G != 0 &&
-           (GV = G->getGlobal()) &&
-           (GV->hasHiddenVisibility() || GV->hasProtectedVisibility()))
-          IsEligible=true;
-      } else {
-        IsEligible=true;
-      }
+      if (getTargetMachine().getRelocationModel() != Reloc::PIC_ ||
+          !Subtarget->isPICStyleGOT())
+        return true;
+
+      // Can only do local tail calls with PIC.
+      GlobalValue * GV = 0;
+      GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
+      if(G != 0 &&
+         (GV = G->getGlobal()) &&
+         (GV->hasHiddenVisibility() || GV->hasProtectedVisibility()))
+        return true;
     }
   }
-  return IsEligible;
+
+  return false;
 }
 
 SDOperand X86TargetLowering::LowerX86_TailCallTo(SDOperand Op, 

Added: llvm/trunk/test/CodeGen/X86/2007-11-01-ISelCrash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/2007-11-01-ISelCrash.ll?rev=43630&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/2007-11-01-ISelCrash.ll (added)
+++ llvm/trunk/test/CodeGen/X86/2007-11-01-ISelCrash.ll Thu Nov  1 20:26:22 2007
@@ -0,0 +1,10 @@
+        %"struct.K::JL" = type <{ i8 }>
+        %struct.jv = type { i64 }
+
+declare fastcc i64 @f(i32, %"struct.K::JL"*, i8*, i8*, %struct.jv*)
+
+define void @t(%"struct.K::JL"* %obj, i8* %name, i8* %sig, %struct.jv* %args) {
+entry:
+        %tmp5 = tail call fastcc i64 @f( i32 1, %"struct.K::JL"* %obj, i8* %name, i8* %sig, %struct.jv* %args )         ; <i64> [#uses=0]
+        ret void
+}





More information about the llvm-commits mailing list