@@ -669,9 +669,9 @@ void CISA_IR_Builder::LinkTimeOptimization(
669669 for (auto & it : sgInvokeList)
670670 {
671671 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) );
675675 G4_INST* fcall = *it;
676676 assert (fcall->opcode () == G4_pseudo_fcall);
677677
@@ -843,7 +843,21 @@ void CISA_IR_Builder::LinkTimeOptimization(
843843 {
844844 // the dst is updating SP
845845 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+ }
847861 }
848862 }
849863 }
@@ -854,6 +868,7 @@ void CISA_IR_Builder::LinkTimeOptimization(
854868 std::list<std::list<vISA::G4_INST*>::iterator> storeList;
855869
856870 auto beginIt = getBeginIt (it);
871+ bool noArgOnStack = (beginIt == it);
857872 for (auto callerIt = beginIt; callerIt != it; callerIt ++)
858873 {
859874 G4_INST *inst = *callerIt;
@@ -1002,7 +1017,7 @@ void CISA_IR_Builder::LinkTimeOptimization(
10021017
10031018 // All args has been removed on the stack
10041019 // Remove SP updating instruction
1005- if (storeList.empty ())
1020+ if (storeList.empty () && !noArgOnStack )
10061021 {
10071022 DEBUG_PRINT (" removed:" );
10081023 DEBUG_UTIL ((*defInst[callerBuilder->getFE_SP ()])->dump ());
0 commit comments