Skip to content

Commit

Permalink
Moved XOR related code from "fgMorphSmpOpOptional" to "fgOptimizeBitw…
Browse files Browse the repository at this point in the history
…iseXor" (#65071)
  • Loading branch information
SkiFoD committed Mar 15, 2022
1 parent 1568ee7 commit c7cdc5c
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14163,6 +14163,24 @@ GenTree* Compiler::fgOptimizeBitwiseXor(GenTreeOp* xorOp)
DEBUG_DESTROY_NODE(op2);
return op1;
}
else if (op2->IsIntegralConst(-1))
{
/* "x ^ -1" is "~x" */
xorOp->ChangeOper(GT_NOT);
xorOp->gtOp2 = nullptr;
DEBUG_DESTROY_NODE(op2);

return xorOp;
}
else if (op2->IsIntegralConst(1) && op1->OperIsCompare())
{
/* "binaryVal ^ 1" is "!binaryVal" */
gtReverseCond(op1);
DEBUG_DESTROY_NODE(op2);
DEBUG_DESTROY_NODE(xorOp);

return op1;
}

return nullptr;
}
Expand Down Expand Up @@ -14559,30 +14577,6 @@ GenTree* Compiler::fgMorphSmpOpOptional(GenTreeOp* tree)

break;

case GT_XOR:

if (!optValnumCSE_phase)
{
/* "x ^ -1" is "~x" */

if (op2->IsIntegralConst(-1))
{
tree->ChangeOper(GT_NOT);
tree->gtOp2 = nullptr;
DEBUG_DESTROY_NODE(op2);
}
else if (op2->IsIntegralConst(1) && op1->OperIsCompare())
{
/* "binaryVal ^ 1" is "!binaryVal" */
gtReverseCond(op1);
DEBUG_DESTROY_NODE(op2);
DEBUG_DESTROY_NODE(tree);
return op1;
}
}

break;

case GT_INIT_VAL:
// Initialization values for initBlk have special semantics - their lower
// byte is used to fill the struct. However, we allow 0 as a "bare" value,
Expand Down

0 comments on commit c7cdc5c

Please sign in to comment.