Skip to content

Commit

Permalink
Fix fgOptimizeAddition opt for AOT (#94350)
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo authored Nov 6, 2023
1 parent 6066de1 commit 9fe2228
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11019,16 +11019,15 @@ GenTree* Compiler::fgOptimizeAddition(GenTreeOp* add)
GenTreeOp* addOne = op1->AsOp();
GenTreeOp* addTwo = op2->AsOp();
GenTreeIntCon* constOne = addOne->gtGetOp2()->AsIntCon();
GenTreeIntCon* constTwo = addTwo->gtGetOp2()->AsIntCon();

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

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

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

0 comments on commit 9fe2228

Please sign in to comment.