@@ -1305,7 +1305,7 @@ class SROA : public FunctionPass {
13051305private:
13061306 friend class PHIOrSelectSpeculator ;
13071307 friend class AllocaSliceRewriter ;
1308-
1308+ bool runOnFunctionImp (Function &F);
13091309 bool presplitLoadsAndStores (AllocaInst &AI, AllocaSlices &AS);
13101310 AllocaInst *rewritePartition (AllocaInst &AI, AllocaSlices &AS,
13111311 AllocaSlices::Partition &P);
@@ -4613,8 +4613,8 @@ bool SROA::promoteAllocas(Function &F) {
46134613 PromotableAllocas.clear ();
46144614 return true ;
46154615}
4616-
4617- bool SROA::runOnFunction (Function &F) {
4616+ // HLSL Change - run SROA more than once if updated.
4617+ bool SROA::runOnFunctionImp (Function &F) {
46184618 if (skipOptnoneFunction (F))
46194619 return false ;
46204620
@@ -4664,6 +4664,19 @@ bool SROA::runOnFunction(Function &F) {
46644664
46654665 return Changed;
46664666}
4667+ // HLSL Change Begin.
4668+ // In some case, alloca fail to optimized early will be ready to optimize after
4669+ // other alloca is optimized.
4670+ bool SROA::runOnFunction (Function &F) {
4671+ unsigned count = 0 ;
4672+ const unsigned kMaxCount = 3 ;
4673+ while ((count++) < kMaxCount ) {
4674+ if (!runOnFunctionImp (F))
4675+ break ;
4676+ }
4677+ return count > 1 ;
4678+ }
4679+ // HLSL Change End.
46674680
46684681void SROA::getAnalysisUsage (AnalysisUsage &AU) const {
46694682 AU.addRequired <AssumptionCacheTracker>();
0 commit comments