Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

JIT: Enable downwards optimization for multi-exit loops #103181

Merged
merged 7 commits into from
Jun 24, 2024

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented Jun 7, 2024

As long as an exiting block dominates all backedges it should be ok to consider it to be converted to a downwards test, provided that the normal heuristics pass (i.e. it should be on a primary IV that is unused in other places in the loop).
Previously we required there to be only one exiting block.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 7, 2024
Copy link
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

@jakobbotsch
Copy link
Member Author

TP regressions are primarily from building the dominator tree:

Base: 107740839374, Diff: 107888602620, +0.1371%

99984104 : +58.06%  : 63.88% : +0.0928% : public: static class FlowGraphDominatorTree * __cdecl FlowGraphDominatorTree::Build(class FlowGraphDfsTree const *)                                                                                                                                               
17781491 : +58.33%  : 11.36% : +0.0165% : public: struct FlowEdge * __cdecl Compiler::BlockDominancePreds(struct BasicBlock *)                                                                                                                                                                              
8835005  : +410.30% : 5.64%  : +0.0082% : public: bool __cdecl Compiler::optMakeLoopDownwardsCounted(class ScalarEvolutionContext &, class FlowGraphNaturalLoop *, class LoopLocalOccurrences *)                                                                                                            
5369197  : +15.18%  : 3.43%  : +0.0050% : `LoopLocalOccurrences::GetOrCreateMap'::`2'::<lambda_1>::operator()                                                                                                                                                                                               
5311505  : NA       : 3.39%  : +0.0049% : public: bool __cdecl Compiler::optMakeExitTestDownwardsCounted(class ScalarEvolutionContext &, class FlowGraphNaturalLoop *, struct BasicBlock *, class LoopLocalOccurrences *)                                                                                   
4466220  : NA       : 2.85%  : +0.0041% : FlowGraphNaturalLoop::VisitRegularExitBlocks<`Compiler::optMakeExitTestDownwardsCounted'::`12'::<lambda_1> >                                                                                                                                                      
3003344  : +0.13%   : 1.92%  : +0.0028% : public: void * __cdecl ArenaAllocator::allocateMemory(unsigned __int64)                                                                                                                                                                                           
1699355  : NA       : 1.09%  : +0.0016% : LoopLocalOccurrences::VisitLoopNestMaps<`LoopLocalOccurrences::VisitStatementsWithOccurrences<`Compiler::optMakeExitTestDownwardsCounted'::`12'::<lambda_2> >'::`2'::<lambda_1> >                                                                                 
733913   : +20.34%  : 0.47%  : +0.0007% : private: class JitHashTable<unsigned int, struct JitSmallPrimitiveKeyFuncs<unsigned int>, struct LoopLocalOccurrences::Occurrence *, class CompAllocator, class JitHashTableBehavior> * __cdecl LoopLocalOccurrences::GetOrCreateMap(class FlowGraphNaturalLoop *)
692476   : +0.48%   : 0.44%  : +0.0006% : private: void __cdecl JitHashTable<struct CORINFO_FIELD_STRUCT_*, struct JitPtrKeyFuncs<struct CORINFO_FIELD_STRUCT_>, class FieldSeq, class CompAllocator, class JitHashTableBehavior>::Grow(void)                                                               
219375   : +63.40%  : 0.14%  : +0.0002% : public: struct Scev * __cdecl ScalarEvolutionContext::Simplify(struct Scev *)                                                                                                                                                                                     
188647   : +0.03%   : 0.12%  : +0.0002% : public: void __cdecl Compiler::fgPerBlockLocalVarLiveness(void)                                                                                                                                                                                                   
167822   : +82.61%  : 0.11%  : +0.0002% : private: enum RelopEvaluationResult __cdecl ScalarEvolutionContext::EvaluateRelop(unsigned int)                                                                                                                                                                   
159678   : +0.04%   : 0.10%  : +0.0001% : __security_check_cookie                                                                                                                                                                                                                                           
-708868  : -100.00% : 0.45%  : -0.0007% : FlowGraphNaturalLoop::VisitRegularExitBlocks<`Compiler::optMakeLoopDownwardsCounted'::`18'::<lambda_1> >                                                                                                                                                          
-765363  : -100.00% : 0.49%  : -0.0007% : LoopLocalOccurrences::VisitLoopNestMaps<`LoopLocalOccurrences::VisitStatementsWithOccurrences<`Compiler::optMakeLoopDownwardsCounted'::`18'::<lambda_2> >'::`2'::<lambda_1> >                                                                                     
-2242217 : -0.24%   : 1.43%  : -0.0021% : memset                                                                                                                                                                                                                                                            

I think we are going to need the dominator tree for strength reduction as well, so I don't see a good reason to try to avoid building it in this PR.

@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @AndyAyersMS

Diffs. TP impact primarily because of computing the dominator tree; I think I'm going to need it for strength reduction as well, so don't see a good reason to try avoid computing it. Cost should be a (tiny) bit less now that #103803 is merged.

@jakobbotsch jakobbotsch requested a review from AndyAyersMS June 21, 2024 18:33
@jakobbotsch jakobbotsch merged commit e1efa6b into dotnet:main Jun 24, 2024
107 checks passed
@jakobbotsch jakobbotsch deleted the trip-count-multiple-exits branch June 24, 2024 16:35
@github-actions github-actions bot locked and limited conversation to collaborators Jul 25, 2024
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants