@@ -951,33 +951,47 @@ void InlineHelper::InlineAndOptimize(CallInst* callInst)
951951 m_calledFunction = callInst->getCalledFunction ();
952952#endif
953953 auto * fn = callInst->getFunction ();
954-
955954 InlineFunctionInfo IFI;
956955 bool CanInline = IGCLLVM::InlineFunction (*callInst, IFI);
957956 IGC_ASSERT_MESSAGE (CanInline, " failed to inline?" );
958957
959- auto & perFnAllocas = m_InlinedStaticArrayAllocas[fn];
960-
961958 // Merge static array allocas to reduce the use of private
962959 // memory. This is a similar optimization that exists in
963960 // the inliner, see mergeInlinedArrayAllocas().
964961 llvm::erase_if (
965962 IFI.StaticAllocas ,
966963 [](AllocaInst* I)
967964 {
968- return I->isArrayAllocation () || !I-> getAllocatedType ()-> isArrayTy ( );
965+ return I->getAllocatedType ()-> isArrayTy () || !isa<ConstantInt>(I-> getArraySize () );
969966 }
970967 );
971968
972- auto staticAlloca = IFI. StaticAllocas . begin () ;
973- for (auto * fnAlloca : perFnAllocas )
969+ AllocaMap localAllocas ;
970+ for (auto * I : IFI. StaticAllocas )
974971 {
975- if ((*staticAlloca)->getAllocatedType () == fnAlloca->getAllocatedType ())
976- (*staticAlloca)->replaceAllUsesWith (fnAlloca);
977-
978- if (++staticAlloca == IFI.StaticAllocas .end ())
979- return ;
972+ localAllocas[
973+ std::make_tuple (
974+ I->getType (),
975+ cast<ConstantInt>(I->getArraySize ())->getZExtValue (),
976+ I->getAddressSpace ())
977+ ].push_back (I);
980978 }
981979
982- perFnAllocas.append (staticAlloca, IFI.StaticAllocas .end ());
980+ for (auto & [key, perTypeAllocas] :localAllocas)
981+ {
982+ auto localAlloca = perTypeAllocas.begin ();
983+ auto & globalAllocas = m_InlinedStaticArrayAllocas[fn][key];
984+ for (auto globalAlloca : globalAllocas)
985+ {
986+ (*localAlloca)->replaceAllUsesWith (globalAlloca);
987+ (*localAlloca)->eraseFromParent ();
988+
989+ localAlloca++;
990+
991+ if (localAlloca == perTypeAllocas.end ())
992+ break ;
993+ }
994+
995+ globalAllocas.append (localAlloca, perTypeAllocas.end ());
996+ }
983997}
0 commit comments