Skip to content

Commit

Permalink
Optimization for "~x + 1" to "-x" (#69003) (#69600)
Browse files Browse the repository at this point in the history
  • Loading branch information
SkiFoD authored Jun 7, 2022
1 parent 7bccc67 commit 8b894ea
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12895,6 +12895,16 @@ GenTree* Compiler::fgOptimizeAddition(GenTreeOp* add)

return add;
}

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

return nullptr;
Expand Down

0 comments on commit 8b894ea

Please sign in to comment.