Skip to content

Commit

Permalink
Optimization for "~x + 1" to "-x" (dotnet#69003)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFoD committed May 20, 2022
1 parent 3914bcc commit c40ab69
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12874,6 +12874,15 @@ GenTree* Compiler::fgOptimizeAddition(GenTreeOp* add)
return op1;
}

// Fold (~x + 1) to -x.
if (op1->OperIs(GT_NOT) && op2->IsIntegralConst(1))
{
op1->SetOper(GT_NEG);
DEBUG_DESTROY_NODE(op2);
DEBUG_DESTROY_NODE(add);
return op1;
}

// Note that these transformations are legal for floating-point ADDs as well.
if (opts.OptimizationEnabled())
{
Expand Down

0 comments on commit c40ab69

Please sign in to comment.