Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
5b16f0a
Equals to 0 optimization in Boolean logic
JulieLeeMSFT Feb 17, 2021
bac5938
Limit bool optimization to Integral return type only
JulieLeeMSFT Mar 10, 2021
8d9484c
Use the updated flowList:setEdgeWeights method with the 3rd parameter
JulieLeeMSFT Mar 11, 2021
635e605
Skip bool optimization for cases that require NOT transformation
JulieLeeMSFT Mar 11, 2021
b8858fc
Skip bool optimization when the third block GT_RETURN is not CNT_INT int
JulieLeeMSFT Mar 17, 2021
afbd075
format patch
JulieLeeMSFT Mar 17, 2021
a437514
Added more bool optimization cases
JulieLeeMSFT Mar 22, 2021
3b51938
format patch
JulieLeeMSFT Mar 23, 2021
854b011
Refactored setting fold type and comparison type to fix jitstress error
JulieLeeMSFT Mar 26, 2021
f28e0d6
format patch
JulieLeeMSFT Mar 26, 2021
ef65ee3
Refactored common codes for conditional block and return block boolea…
JulieLeeMSFT Mar 27, 2021
5746b61
format patch
JulieLeeMSFT Mar 27, 2021
7740064
Unit test changed to remove EH handling and add return value checks
ewhapdx Apr 2, 2021
d0c47e8
Unit test: add back test cases for ANDing and NE cases
ewhapdx Apr 3, 2021
f0adde5
Made OptBoolsDsc struct to pass it off to the helper methods.
ewhapdx Apr 23, 2021
29dc719
format patch
ewhapdx Apr 23, 2021
d02d18e
Changed to substructure OptTestInfo within OptBoolsDisc
JulieLeeMSFT Jun 19, 2021
ebf2010
Cleaned up tree variables in OptBoolsDsc struct
JulieLeeMSFT Jun 21, 2021
a7cdf1c
Moved some methods for Boolean Optimization to OptBoolsDsc struct
JulieLeeMSFT Jun 24, 2021
e3a6520
Moved all private methods for Boolean Optimization to OptBoolsDsc struct
JulieLeeMSFT Jun 24, 2021
5f02965
Boolean Optimization: Handled code review feedback
JulieLeeMSFT Jul 2, 2021
d14053e
Optimize bools: hoisted jump destination check to optOptimizeBools() …
JulieLeeMSFT Jul 9, 2021
12c7a8a
format patch
JulieLeeMSFT Jul 9, 2021
0e96608
Moved initialization to OptBoolsDsc constructor
JulieLeeMSFT Jul 13, 2021
1cdcdb8
format patch
JulieLeeMSFT Jul 13, 2021
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
Prev Previous commit
Next Next commit
Skip bool optimization for cases that require NOT transformation
  • Loading branch information
JulieLeeMSFT committed Jun 24, 2021
commit 635e60567bc534cd39dc0a10a45a23133118aad0
35 changes: 17 additions & 18 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7940,14 +7940,12 @@ void Compiler::optOptimizeBoolsBbjReturn(BasicBlock* b1, BasicBlock* b2, BasicBl
}

/* Does b1 jump to b3? */
/* Given the following sequence of blocks :
/* One example: Given the following sequence of blocks :
B1: brtrue(!t1, B3)
B2: return(t2)
B3: return(false)
B4:
we will try to fold it to :
B1: return(t1|t2)
B4:
*/
if (b1->bbJumpDest != b2->bbNext) /*b1->bbJumpDest->bbNum == n1+2*/
{
Expand Down Expand Up @@ -8059,22 +8057,27 @@ void Compiler::optOptimizeBoolsBbjReturn(BasicBlock* b1, BasicBlock* b2, BasicBl
return;
}

if (t1->gtOper == GT_EQ)
{
/* t1:c1==0 t2:c2!=0 ==> Branch to BX if both values are non-0
So we will branch to BX if (c1&c2)!=0 */
ssize_t it3val = t3->AsOp()->gtOp1->AsIntCon()->gtIconVal;

if (t1->gtOper == GT_EQ && it3val == 0)
{
/* t1:c1==0 t2:c2!=0 t3:c3==0 ==> Return true if (c1&c2)!=0 */
foldOp = GT_AND;
cmpOp = GT_NE;
}
else
else if (t1->gtOper == GT_NE && it3val == 0)
{
/* t1:c1!=0 t2:c2==0 ==> Branch to BX if both values are 0
So we will branch to BX if (c1|c2)==0 */

/* t1:c1!=0 t2:c2==0 t3:c3==0 ==> Return true if (c1|c2)==0 */
foldOp = GT_OR;
cmpOp = GT_EQ;
}
else
{
/* Both cases requires NOT operation for operand. Do Not fold.
t1:c1==0 t2:c2!=0 t3:c3==1 ==> true if (c1&!c2)==0
t1:c1!=0 t2:c2==0 t3:c3==1 ==> true if (!c1&c2)==0 */
return;
}

// Anding requires both values to be 0 or 1

Expand Down Expand Up @@ -8122,7 +8125,6 @@ void Compiler::optOptimizeBoolsBbjReturn(BasicBlock* b1, BasicBlock* b2, BasicBl
//
cmpOp1->gtRequestSetFlags();
#endif

/* Modify the target of the conditional jump and update bbRefs and bbPreds */

fgRemoveRefPred(b1->bbJumpDest, b1);
Expand Down Expand Up @@ -8154,14 +8156,11 @@ void Compiler::optOptimizeBoolsBbjReturn(BasicBlock* b1, BasicBlock* b2, BasicBl

ehUpdateForDeletedBlock(b3);

///* Update bbRefs and bbPreds */

//fgReplacePred(b2->bbNext, b2, b1); // TODO-Julie: b2 is null, so this does not work.

*change = true;

//// Update loop table
//fgUpdateLoopsAfterCompacting(b1, b2); // TODO-Julie: b2 is null, so this does not work.
fgUpdateLoopsAfterCompacting(b1, b2);
fgUpdateLoopsAfterCompacting(b1, b3);

#ifdef DEBUG
if (verbose)
Expand Down Expand Up @@ -8226,7 +8225,7 @@ void Compiler::optOptimizeBoolsGcStress(BasicBlock* condBlock)

/******************************************************************************
* Function used by folding of boolean conditionals
* Given a GT_JTRUE node, checks that it is a boolean comparison of the form
* Given a GT_JTRUE or GT_RETURN node, checks that it is a boolean comparison of the form
* "if (boolVal ==/!= 0/1)". This is translated into a GT_EQ node with "op1"
* being a boolean lclVar and "op2" the const 0/1.
* On success, the comparand (ie. boolVal) is returned. Else NULL.
Expand Down