[llvm-commits] [llvm] r94937 - in /llvm/trunk: lib/Transforms/Scalar/TailRecursionElimination.cpp test/Transforms/TailCallElim/no-return-calls.ll

Chris Lattner clattner at apple.com
Tue Feb 2 10:19:53 PST 2010


On Feb 2, 2010, at 10:07 AM, Evan Cheng wrote:

> I'll deal with this later. To me if the call isn't before a proper  
> function epilogue I don't see it as a "tail call". But if that's the  
> definition, I'll move the check elsewhere.

It seems legal and profitable (though potentially not worth the  
trouble to implement) to turn:

void bar(int a) {
   call foo(a)
   unreachable
}

into:

bar:
   jmp foo

instead of handling the prolog and call shuffling.  Please do revert  
the middle end change when possible, codegen should decide whether it  
is possible to do these sorts of things based on its constraints.

-Chris

>
> Evan
>
> On Feb 1, 2010, at 9:36 PM, Chris Lattner wrote:
>
>>
>> On Jan 30, 2010, at 4:59 PM, Evan Cheng wrote:
>>
>>> Author: evancheng
>>> Date: Sat Jan 30 18:59:31 2010
>>> New Revision: 94937
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=94937&view=rev
>>> Log:
>>> Do not mark no-return calls tail calls. It'll screw up special  
>>> calls like longjmp and it doesn't make much sense for performance  
>>> reason. If my logic is faulty, please let me know.
>>
>> Hey Evan,
>>
>> This isn't the right patch.  The 'tail' flag means that the callee  
>> doesn't access the caller's stack, not that it satisfies all the  
>> arbitrary requirements that codegen has for tailcalls.  If codegen  
>> doesn't handling this form of tailcall, it should be the one that  
>> avoids transforming it.
>>
>> -Chris
>>
>>>
>>> Added:
>>>  llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll
>>> Modified:
>>>  llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp
>>>
>>> Modified: llvm/trunk/lib/Transforms/Scalar/ 
>>> TailRecursionElimination.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp?rev=94937&r1=94936&r2=94937&view=diff
>>>
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> ====================================================================
>>> --- llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp  
>>> (original)
>>> +++ llvm/trunk/lib/Transforms/Scalar/TailRecursionElimination.cpp  
>>> Sat Jan 30 18:59:31 2010
>>> @@ -184,10 +184,11 @@
>>> if (!FunctionContainsEscapingAllocas)
>>>   for (Function::iterator BB = F.begin(), E = F.end(); BB != E; + 
>>> +BB)
>>>     for (BasicBlock::iterator I = BB->begin(), E = BB->end(); I !=  
>>> E; ++I)
>>> -        if (CallInst *CI = dyn_cast<CallInst>(I)) {
>>> -          CI->setTailCall();
>>> -          MadeChange = true;
>>> -        }
>>> +        if (CallInst *CI = dyn_cast<CallInst>(I))
>>> +          if (!CI->doesNotReturn()) {
>>> +            CI->setTailCall();
>>> +            MadeChange = true;
>>> +          }
>>>
>>> return MadeChange;
>>> }
>>>
>>> Added: llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll?rev=94937&view=auto
>>>
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> = 
>>> ====================================================================
>>> --- llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll  
>>> (added)
>>> +++ llvm/trunk/test/Transforms/TailCallElim/no-return-calls.ll Sat  
>>> Jan 30 18:59:31 2010
>>> @@ -0,0 +1,12 @@
>>> +; RUN: opt < %s -tailcallelim -S | FileCheck %s
>>> +
>>> +define void @t() nounwind ssp {
>>> +entry:
>>> +; CHECK: entry:
>>> +; CHECK: %0 = call i32 @foo()
>>> +; CHECK: ret void
>>> +  %0 = call i32 @foo() nounwind noreturn
>>> +  ret void
>>> +}
>>> +
>>> +declare i32 @foo()
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>>
>




More information about the llvm-commits mailing list