@@ -1242,22 +1242,19 @@ void LowerGPCallArg::FixAddressSpaceInAllUses(Value* ptr, uint newAS, uint oldAS
12421242// Loops over the argument list transferring uses from old function to new one.
12431243void LowerGPCallArg::updateFunctionArgs (Function* oldFunc, Function* newFunc, GenericPointerArgs& newArgs)
12441244{
1245-
12461245 Function::arg_iterator currArg = newFunc->arg_begin ();
12471246 unsigned currentArgIdx = 0 , newArgIdx = 0 ;
12481247
1249-
1250-
12511248 for (Function::arg_iterator I = oldFunc->arg_begin (), E = oldFunc->arg_end ();
12521249 I != E; ++I, ++currArg, ++currentArgIdx)
12531250 {
12541251 Value* newArg = &(*currArg);
1255- if ((*I).getType () != currArg->getType ())
1252+ // Check if the next entry in newArgs is for currentArgIdx arg
1253+ if (newArgIdx < newArgs.size () && currentArgIdx == newArgs[newArgIdx].first )
12561254 {
1257- if (currentArgIdx == newArgs[newArgIdx]. first )
1255+ if ((*I). getType () != currArg-> getType () )
12581256 {
12591257 PointerType* originalPointerTy = dyn_cast<PointerType>(I->getType ());
1260-
12611258 PointerType* newPointerTy = PointerType::get (I->getType ()->getPointerElementType (),
12621259 newArgs[newArgIdx].second );
12631260 I->mutateType (newPointerTy);
@@ -1273,16 +1270,14 @@ void LowerGPCallArg::updateFunctionArgs(Function* oldFunc, Function* newFunc, Ge
12731270 {
12741271 recoverASC->eraseFromParent ();
12751272 }
1276- newArgIdx++;
12771273 }
1274+ newArgIdx++;
12781275 }
12791276 I->replaceAllUsesWith (newArg);
12801277 currArg->takeName (&(*I));
12811278 }
12821279}
12831280
1284-
1285-
12861281void LowerGPCallArg::updateAllUsesWithNewFunction (FuncToUpdate& f)
12871282{
12881283 IGC_ASSERT (!f.oldFunc ->use_empty ());
0 commit comments