Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Optimize if range check to replace jumps to bit operation #87656

Merged
merged 33 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4ff8215
Optimize if range check to bit operation by changing if tree to switc…
ewhapdx Jun 15, 2023
dd7a34e
[if range check opt] handle unsorted patterns.
ewhapdx Jun 16, 2023
6defaf2
[if range check opt] Handle appending a statement for side effects.
ewhapdx Jun 20, 2023
b9dd068
[if range check opt] Code clean-up.
ewhapdx Jun 21, 2023
2740251
[if range check opt] Use gtUpdateStmtSideEffects to update flags afte…
ewhapdx Jun 21, 2023
f6de9c7
[if range check opt] Handle MIN and MAX limits for pattern values.
ewhapdx Jun 22, 2023
63a2d5a
[if range check opt] Skip optimization for a tree with side effects.
ewhapdx Jun 29, 2023
0fb697f
[if range check opt] Don't optimize if block is marked with BBF_DONT_…
ewhapdx Jun 29, 2023
abad4b4
[if range check opt] Optimize GT_CNS_INT patterns only.
ewhapdx Jun 30, 2023
cbe75c9
[if range check opt] Skip cases that Lowering does not convert to a b…
ewhapdx Jul 3, 2023
eb0bed6
[if range check opt] Skip if switch cases or default don't jump to sw…
ewhapdx Jul 4, 2023
aa779d5
Change Switch conversion to happen after Optimize Layout to avoid Swi…
ewhapdx Jul 12, 2023
c4272fa
Refactored the code for Switch Recognition. Match pattern for >=3 con…
ewhapdx Jul 18, 2023
fbf975e
Refactored Switch recognition.
ewhapdx Jul 18, 2023
eb3f68e
Switch conversion build error fix.
ewhapdx Jul 18, 2023
f2db6fc
Switch conversion optimization: build error fix for an unused variable.
ewhapdx Jul 18, 2023
55b86e1
Switch conversion optimization: fortmat fix.
ewhapdx Jul 18, 2023
8f5cb4a
Switch recognition: change phase text name.
JulieLeeMSFT Jul 21, 2023
459137a
Add test cases for Switch recognition.
JulieLeeMSFT Aug 2, 2023
b25fe62
Merge branch 'main' of github.com:dotnet/runtime into 8418
EgorBo Aug 28, 2023
9d7d124
Merge branch 'main' of github.com:dotnet/runtime into 8418
EgorBo Sep 6, 2023
0b4e652
Move to a separate file
EgorBo Sep 6, 2023
cc00c06
Code clean up
EgorBo Sep 6, 2023
a034b9d
More clean up
EgorBo Sep 6, 2023
c1a3256
Merge branch 'main' of github.com:dotnet/runtime into 8418
EgorBo Sep 10, 2023
8dc353d
Refactoring
EgorBo Sep 10, 2023
03573dc
Update switchrecognition.cpp
EgorBo Sep 11, 2023
b28bc6a
Update switchrecognition.cpp
EgorBo Sep 11, 2023
cbbb591
Optimization
EgorBo Sep 11, 2023
8a3d5a5
Clean up
EgorBo Sep 11, 2023
0e06dc9
Ignore cold blocks
EgorBo Sep 11, 2023
62ad104
Disable for arm, no meaningful diffs anyway
EgorBo Sep 11, 2023
f661aac
Merge branch 'main' of https://github.com/dotnet/runtime into 8418
Sep 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ set( JIT_SOURCES
objectalloc.cpp
optcse.cpp
optimizebools.cpp
switchrecognition.cpp
optimizer.cpp
patchpoint.cpp
phase.cpp
Expand Down
17 changes: 11 additions & 6 deletions src/coreclr/jit/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -792,9 +792,6 @@ bool BasicBlock::IsLIR() const
//------------------------------------------------------------------------
// firstStmt: Returns the first statement in the block
//
// Arguments:
// None.
//
// Return Value:
// The first statement in the block's bbStmtList.
//
Expand All @@ -804,10 +801,18 @@ Statement* BasicBlock::firstStmt() const
}

//------------------------------------------------------------------------
// lastStmt: Returns the last statement in the block
// hasSingleStmt: Returns true if block has a single statement
//
// Arguments:
// None.
// Return Value:
// true if block has a single statement, false otherwise
//
bool BasicBlock::hasSingleStmt() const
{
return (firstStmt() != nullptr) && (firstStmt() == lastStmt());
}

//------------------------------------------------------------------------
// lastStmt: Returns the last statement in the block
//
// Return Value:
// The last statement in the block's bbStmtList.
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/block.h
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,7 @@ struct BasicBlock : private LIR::Range

Statement* firstStmt() const;
Statement* lastStmt() const;
bool hasSingleStmt() const;

// Statements: convenience method for enabling range-based `for` iteration over the statement list, e.g.:
// for (Statement* const stmt : block->Statements())
Expand Down
4 changes: 4 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5053,6 +5053,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
// Optimize block order
//
DoPhase(this, PHASE_OPTIMIZE_LAYOUT, &Compiler::optOptimizeLayout);

// Conditional to Switch conversion
//
DoPhase(this, PHASE_SWITCH_RECOGNITION, &Compiler::optSwitchRecognition);
}

// Determine start of cold region if we are hot/cold splitting
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6325,8 +6325,10 @@ class Compiler

public:
PhaseStatus optOptimizeBools();
PhaseStatus optSwitchRecognition();
bool optSwitchConvert(BasicBlock* firstBlock, int testsCount, ssize_t* testValues, GenTree* nodeToTest);
bool optSwitchDetectAndConvert(BasicBlock* firstBlock);

public:
PhaseStatus optInvertLoops(); // Invert loops so they're entered at top and tested at bottom.
PhaseStatus optOptimizeFlow(); // Simplify flow graph and do tail duplication
PhaseStatus optOptimizeLayout(); // Optimize the BasicBlock layout of the method
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/compphases.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ CompPhaseNameMacro(PHASE_MORPH_MDARR, "Morph array ops",
CompPhaseNameMacro(PHASE_HOIST_LOOP_CODE, "Hoist loop code", false, -1, false)
CompPhaseNameMacro(PHASE_MARK_LOCAL_VARS, "Mark local vars", false, -1, false)
CompPhaseNameMacro(PHASE_OPTIMIZE_BOOLS, "Optimize bools", false, -1, false)
CompPhaseNameMacro(PHASE_SWITCH_RECOGNITION, "Recognize Switch", false, -1, false)
CompPhaseNameMacro(PHASE_FIND_OPER_ORDER, "Find oper order", false, -1, false)
CompPhaseNameMacro(PHASE_SET_BLOCK_ORDER, "Set block order", false, -1, true)
CompPhaseNameMacro(PHASE_BUILD_SSA, "Build SSA representation", true, -1, false)
Expand Down
Loading