File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -15006,6 +15006,23 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree)
1500615006 {
1500715007 GenTree* op2 = tree->AsOp()->gtOp2;
1500815008
15009+ if ((tree->gtOper == GT_SUB) && !tree->gtOverflow() && !op2->TypeIs(TYP_BYREF) && !op2->IsIconHandle())
15010+ {
15011+ // Canonicalize the tree from `x - y` to `x + (-y)`
15012+ // as this allows various other optimizations to kick in
15013+
15014+ tree->ChangeOper(GT_ADD, GenTree::PRESERVE_VN);
15015+ op2 = gtNewOperNode(GT_NEG, genActualType(op2->gtType), op2);
15016+
15017+ if (fgGlobalMorph)
15018+ {
15019+ fgMorphTreeDone(op2);
15020+ }
15021+ op2 = gtFoldExpr(op2);
15022+
15023+ tree->AsOp()->gtOp2 = op2;
15024+ }
15025+
1500915026 // The atomic operations are exempted here because they are never computable statically;
1501015027 // one of their arguments is an address.
1501115028 if (op1->OperIsConst() && op2->OperIsConst() && !tree->OperIsAtomicOp())
You can’t perform that action at this time.
0 commit comments