@@ -3102,18 +3102,7 @@ GenTree* Compiler::optVNBasedFoldConstExpr(BasicBlock* block, GenTree* parent, G
31023102
31033103 // Were able to optimize.
31043104 conValTree->gtVNPair = vnPair;
3105- GenTree* sideEffList = optExtractSideEffListFromConst (tree);
3106- if (sideEffList != nullptr )
3107- {
3108- // Replace as COMMA(side_effects, const value tree);
3109- assert ((sideEffList->gtFlags & GTF_SIDE_EFFECT ) != 0 );
3110- return gtNewOperNode (GT_COMMA , conValTree->TypeGet (), sideEffList, conValTree);
3111- }
3112- else
3113- {
3114- // No side effects, replace as const value tree.
3115- return conValTree;
3116- }
3105+ return gtWrapWithSideEffects (conValTree, tree, GTF_SIDE_EFFECT , true );
31173106 }
31183107 else
31193108 {
@@ -6228,52 +6217,6 @@ struct VNAssertionPropVisitorInfo
62286217 }
62296218};
62306219
6231- // ------------------------------------------------------------------------------
6232- // optExtractSideEffListFromConst
6233- // Extracts side effects from a tree so it can be replaced with a comma
6234- // separated list of side effects + a const tree.
6235- //
6236- // Note:
6237- // The caller expects that the root of the tree has no side effects and it
6238- // won't be extracted. Otherwise the resulting comma tree would be bigger
6239- // than the tree before optimization.
6240- //
6241- // Arguments:
6242- // tree - The tree node with constant value to extrace side-effects from.
6243- //
6244- // Return Value:
6245- // 1. Returns the extracted side-effects from "tree"
6246- // 2. When no side-effects are present, returns null.
6247- //
6248- //
6249- GenTree* Compiler::optExtractSideEffListFromConst (GenTree* tree)
6250- {
6251- assert (vnStore->IsVNConstant (vnStore->VNConservativeNormalValue (tree->gtVNPair )));
6252-
6253- GenTree* sideEffList = nullptr ;
6254-
6255- // If we have side effects, extract them.
6256- if ((tree->gtFlags & GTF_SIDE_EFFECT ) != 0 )
6257- {
6258- // Do a sanity check to ensure persistent side effects aren't discarded and
6259- // tell gtExtractSideEffList to ignore the root of the tree.
6260- // We are relying here on an invariant that VN will only fold non-throwing expressions.
6261- assert (!gtNodeHasSideEffects (tree, GTF_PERSISTENT_SIDE_EFFECTS ));
6262-
6263- // Exception side effects may be ignored because the root is known to be a constant
6264- // (e.g. VN may evaluate a DIV/MOD node to a constant and the node may still
6265- // have GTF_EXCEPT set, even if it does not actually throw any exceptions).
6266- bool ignoreRoot = true ;
6267-
6268- gtExtractSideEffList (tree, &sideEffList, GTF_SIDE_EFFECT , ignoreRoot);
6269-
6270- JITDUMP (" Extracted side effects from a constant tree [%06u]:\n " , tree->gtTreeID );
6271- DISPTREE (sideEffList);
6272- }
6273-
6274- return sideEffList;
6275- }
6276-
62776220// ------------------------------------------------------------------------------
62786221// optVNConstantPropOnJTrue
62796222// Constant propagate on the JTrue node by extracting side effects and moving
@@ -6330,7 +6273,8 @@ GenTree* Compiler::optVNConstantPropOnJTrue(BasicBlock* block, GenTree* test)
63306273 }
63316274
63326275 // Prepare the tree for replacement so any side effects can be extracted.
6333- GenTree* sideEffList = optExtractSideEffListFromConst (relop);
6276+ GenTree* sideEffList = nullptr ;
6277+ gtExtractSideEffList (relop, &sideEffList, GTF_SIDE_EFFECT , true );
63346278
63356279 // Transform the relop's operands to be both zeroes.
63366280 ValueNum vnZero = vnStore->VNZeroForType (TYP_INT );
0 commit comments