We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
x - y
x + (-y)
1 parent 52090b9 commit dc6d2feCopy full SHA for dc6d2fe
1 file changed
src/coreclr/jit/gentree.cpp
@@ -15006,6 +15006,16 @@ GenTree* Compiler::gtFoldExpr(GenTree* tree)
15006
{
15007
GenTree* op2 = tree->AsOp()->gtOp2;
15008
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
15019
// The atomic operations are exempted here because they are never computable statically;
15020
// one of their arguments is an address.
15021
if (op1->OperIsConst() && op2->OperIsConst() && !tree->OperIsAtomicOp())
0 commit comments