@@ -669,9 +669,9 @@ void CISA_IR_Builder::LinkTimeOptimization(
669
669
for (auto & it : sgInvokeList)
670
670
{
671
671
bool inlining = ( options & (1U << Linker_Inline) ) && sgInvokeList.size () == 1 ;
672
- bool removeArgRet = ( options & (1U << Linker_RemoveArgRet) ) && sgInvokeList. size () == 1 ;
673
- bool removeStackArg = ( options & (1U << Linker_RemoveStackArg) ) && sgInvokeList. size () == 1 ;
674
- bool removeStackFrame = ( options & (1U << Linker_RemoveStackFrame) ) && sgInvokeList. size () == 1 ;
672
+ bool removeArgRet = ( options & (1U << Linker_RemoveArgRet) );
673
+ bool removeStackArg = ( options & (1U << Linker_RemoveStackArg) );
674
+ bool removeStackFrame = ( options & (1U << Linker_RemoveStackFrame) );
675
675
G4_INST* fcall = *it;
676
676
assert (fcall->opcode () == G4_pseudo_fcall);
677
677
@@ -843,7 +843,21 @@ void CISA_IR_Builder::LinkTimeOptimization(
843
843
{
844
844
// the dst is updating SP
845
845
if (dst->getTopDcl () == callerBuilder->getFE_SP ())
846
- return beginIt;
846
+ {
847
+ auto prevIt = beginIt;
848
+ prevIt --;
849
+ G4_INST *prevInst = *prevIt;
850
+ // It reaches the begining of function where it pushes a new frame.
851
+ // It is not where we are looking for.
852
+ if (prevInst->getDst ()->getTopDcl () == callerBuilder->getFE_FP ())
853
+ {
854
+ return it;
855
+ }
856
+ else
857
+ {
858
+ return beginIt;
859
+ }
860
+ }
847
861
}
848
862
}
849
863
}
@@ -854,6 +868,7 @@ void CISA_IR_Builder::LinkTimeOptimization(
854
868
std::list<std::list<vISA::G4_INST*>::iterator> storeList;
855
869
856
870
auto beginIt = getBeginIt (it);
871
+ bool noArgOnStack = (beginIt == it);
857
872
for (auto callerIt = beginIt; callerIt != it; callerIt ++)
858
873
{
859
874
G4_INST *inst = *callerIt;
@@ -1002,7 +1017,7 @@ void CISA_IR_Builder::LinkTimeOptimization(
1002
1017
1003
1018
// All args has been removed on the stack
1004
1019
// Remove SP updating instruction
1005
- if (storeList.empty ())
1020
+ if (storeList.empty () && !noArgOnStack )
1006
1021
{
1007
1022
DEBUG_PRINT (" removed:" );
1008
1023
DEBUG_UTIL ((*defInst[callerBuilder->getFE_SP ()])->dump ());
0 commit comments