Skip to content

Commit 9fe2228

Browse files
authored
Fix fgOptimizeAddition opt for AOT (#94350)
1 parent 6066de1 commit 9fe2228

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/coreclr/jit/morph.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11019,16 +11019,15 @@ GenTree* Compiler::fgOptimizeAddition(GenTreeOp* add)
1101911019
GenTreeOp* addOne = op1->AsOp();
1102011020
GenTreeOp* addTwo = op2->AsOp();
1102111021
GenTreeIntCon* constOne = addOne->gtGetOp2()->AsIntCon();
11022-
GenTreeIntCon* constTwo = addTwo->gtGetOp2()->AsIntCon();
1102311022

11023+
// addOne is now "x + y"
1102411024
addOne->gtOp2 = addTwo->gtGetOp1();
1102511025
addOne->SetAllEffectsFlags(addOne->gtGetOp1(), addOne->gtGetOp2());
11026-
DEBUG_DESTROY_NODE(addTwo);
1102711026

11028-
constOne->SetValueTruncating(constOne->IconValue() + constTwo->IconValue());
11029-
op2 = constOne;
11030-
add->gtOp2 = constOne;
11031-
DEBUG_DESTROY_NODE(constTwo);
11027+
// addTwo is now "icon1 + icon2" so we can fold it using gtFoldExprConst
11028+
addTwo->gtOp1 = constOne;
11029+
add->gtOp2 = gtFoldExprConst(add->gtOp2);
11030+
op2 = add->gtGetOp2();
1103211031
}
1103311032

1103411033
// Fold (x + 0) - given it won't change the tree type.

0 commit comments

Comments
 (0)