Skip to content

Commit dc6d2fe

Browse files
committed
Try canonicalizing the tree from x - y to x + (-y)
1 parent 52090b9 commit dc6d2fe

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/coreclr/jit/gentree.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15006,6 +15006,16 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree)
1500615006
{
1500715007
GenTree* op2 = tree->AsOp()->gtOp2;
1500815008

15009+
if (tree->gtOper == GT_SUB)
15010+
{
15011+
// Canonicalize the tree from `x - y` to `x + (-y)`
15012+
// as this allows various other optimizations to kick in
15013+
15014+
tree->gtOper == GT_ADD;
15015+
op2 = gtNewOperNode(GT_NEG, genActualType(op2->gtType), op2);
15016+
tree->AsOp()->gtOp2 = op2;
15017+
}
15018+
1500915019
// The atomic operations are exempted here because they are never computable statically;
1501015020
// one of their arguments is an address.
1501115021
if (op1->OperIsConst() && op2->OperIsConst() && !tree->OperIsAtomicOp())

0 commit comments

Comments
 (0)