From 28957018f19d30f18a3994aaef53f8063c581221 Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Thu, 27 Apr 2023 18:28:20 +0300 Subject: [PATCH 1/2] Fix volatile check in loop side effects code --- src/coreclr/jit/optimizer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 58f5c549a8b505..695d0057df0c11 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -8611,7 +8611,7 @@ bool Compiler::optComputeLoopSideEffectsOfBlock(BasicBlock* blk) { GenTree* arg = lhs->AsIndir()->Addr()->gtEffectiveVal(/*commaOnly*/ true); - if ((tree->gtFlags & GTF_IND_VOLATILE) != 0) + if ((lhs->gtFlags & GTF_IND_VOLATILE) != 0) { memoryHavoc |= memoryKindSet(GcHeap, ByrefExposed); continue; From 72c691ab62df3a5455216e604c21f43c1d04b1ed Mon Sep 17 00:00:00 2001 From: SingleAccretion Date: Thu, 27 Apr 2023 20:34:07 +0300 Subject: [PATCH 2/2] Restore the volatility logic in VN Volatile stores should be processed at the point of ASG. --- src/coreclr/jit/valuenum.cpp | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/coreclr/jit/valuenum.cpp b/src/coreclr/jit/valuenum.cpp index 18c4d946c2736f..01c07a49e92dbf 100644 --- a/src/coreclr/jit/valuenum.cpp +++ b/src/coreclr/jit/valuenum.cpp @@ -10633,8 +10633,13 @@ void Compiler::fgValueNumberTree(GenTree* tree) ValueNumPair addrXvnp; vnStore->VNPUnpackExc(addr->gtVNPair, &addrNvnp, &addrXvnp); + // To be able to propagate exception sets, we give location nodes the "Void" VN. + if ((tree->gtFlags & GTF_IND_ASG_LHS) != 0) + { + tree->gtVNPair = vnStore->VNPWithExc(vnStore->VNPForVoid(), addrXvnp); + } // Is the dereference immutable? If so, model it as referencing the read-only heap. - if (tree->gtFlags & GTF_IND_INVARIANT) + else if (tree->gtFlags & GTF_IND_INVARIANT) { assert(!isVolatile); // We don't expect both volatile and invariant @@ -10709,9 +10714,7 @@ void Compiler::fgValueNumberTree(GenTree* tree) ValueNum newUniq = vnStore->VNForExpr(compCurBB, tree->TypeGet()); tree->gtVNPair = vnStore->VNPWithExc(ValueNumPair(newUniq, newUniq), addrXvnp); } - // In general we skip GT_IND nodes on that are the LHS of an assignment. (We labeled these earlier.) - // We will "evaluate" this as part of the assignment. - else if ((tree->gtFlags & GTF_IND_ASG_LHS) == 0) + else { var_types loadType = tree->TypeGet(); ssize_t offset = 0; @@ -10754,12 +10757,6 @@ void Compiler::fgValueNumberTree(GenTree* tree) tree->gtVNPair = vnStore->VNPWithExc(tree->gtVNPair, addrXvnp); } - - // To be able to propagate exception sets, we give location nodes the "Void" VN. - if ((tree->gtFlags & GTF_IND_ASG_LHS) != 0) - { - tree->gtVNPair = vnStore->VNPWithExc(vnStore->VNPForVoid(), addrXvnp); - } } else if (tree->OperGet() == GT_CAST) {