Skip to content

Commit

Permalink
Add simple Else conditions to If Conversion (#77728)
Browse files Browse the repository at this point in the history
* Add simple Else conditions to If Conversion

For example:
if (x < 7) { a = 5; } else { a = 9; }
a = (cond) ? b : c;

The else condition must write to the same variable as the then
statement.

* Move phase and stop updating ssa

* Wrap JitConfig access

* Add GT_RETURN else cases

* Add test cases with verification checks

* Ensure single only operation condition checks are used

* Remove empty line

* Use DOTNET_ instead of COMPlus_

* Move JitDoIfConversion check

* Move if conversion into it's own file

* Always invert condition

* Rename IfConvertMergeBlocks

* Use gtGetOp1()

* Expand tests

* Add operation type assert

* Allow nested SELECT nodes

* Fix condition directions
  • Loading branch information
a74nh authored Nov 30, 2022
1 parent becfc23 commit 5356857
Show file tree
Hide file tree
Showing 5 changed files with 998 additions and 373 deletions.
1 change: 1 addition & 0 deletions src/coreclr/jit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ set( JIT_SOURCES
hashbv.cpp
hwintrinsic.cpp
hostallocator.cpp
ifconversion.cpp
indirectcalltransformer.cpp
importercalls.cpp
importer.cpp
Expand Down
13 changes: 4 additions & 9 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4755,7 +4755,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
bool doCse = true;
bool doAssertionProp = true;
bool doRangeAnalysis = true;
bool doIfConversion = true;
bool doVNBasedDeadStoreRemoval = true;
int iterations = 1;

Expand All @@ -4769,7 +4768,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
doCse = doValueNum;
doAssertionProp = doValueNum && (JitConfig.JitDoAssertionProp() != 0);
doRangeAnalysis = doAssertionProp && (JitConfig.JitDoRangeAnalysis() != 0);
doIfConversion = doIfConversion && (JitConfig.JitDoIfConversion() != 0);
doVNBasedDeadStoreRemoval = doValueNum && (JitConfig.JitDoVNBasedDeadStoreRemoval() != 0);

if (opts.optRepeat)
Expand Down Expand Up @@ -4852,13 +4850,6 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
DoPhase(this, PHASE_ASSERTION_PROP_MAIN, &Compiler::optAssertionPropMain);
}

if (doIfConversion)
{
// If conversion
//
DoPhase(this, PHASE_IF_CONVERSION, &Compiler::optIfConversion);
}

if (doRangeAnalysis)
{
// Bounds check elimination via range analysis
Expand Down Expand Up @@ -4910,6 +4901,10 @@ void Compiler::compCompile(void** methodCodePtr, uint32_t* methodCodeSize, JitFl
//
DoPhase(this, PHASE_OPTIMIZE_BOOLS, &Compiler::optOptimizeBools);

// If conversion
//
DoPhase(this, PHASE_IF_CONVERSION, &Compiler::optIfConversion);

// Optimize block order
//
DoPhase(this, PHASE_OPTIMIZE_LAYOUT, &Compiler::optOptimizeLayout);
Expand Down
Loading

0 comments on commit 5356857

Please sign in to comment.