@@ -2522,6 +2522,12 @@ void CodeGen::genCodeForInitBlkUnroll(GenTreeBlk* initBlkNode)
25222522
25232523 genConsumeOperands (initBlkNode);
25242524
2525+ if (initBlkNode->gtFlags & GTF_BLK_VOLATILE)
2526+ {
2527+ // issue a full memory barrier before volatile an initBlockUnroll operation
2528+ instGen_MemoryBarrier ();
2529+ }
2530+
25252531 regNumber valReg = initVal->IsIntegralConst (0 ) ? REG_ZR : initVal->gtRegNum ;
25262532
25272533 assert (!initVal->IsIntegralConst (0 ) || (valReg == REG_ZR));
@@ -2664,8 +2670,9 @@ void CodeGen::genCodeForCpBlkUnroll(GenTreeBlk* cpBlkNode)
26642670
26652671 emitter* emit = getEmitter ();
26662672
2667- if (cpBlkNode->gtFlags & GTF_IND_VOLATILE )
2673+ if (cpBlkNode->gtFlags & GTF_BLK_VOLATILE )
26682674 {
2675+ // issue a full memory barrier before & after a volatile CpBlkUnroll operation
26692676 instGen_MemoryBarrier ();
26702677 }
26712678
@@ -2748,8 +2755,9 @@ void CodeGen::genCodeForCpBlkUnroll(GenTreeBlk* cpBlkNode)
27482755 }
27492756 }
27502757
2751- if (cpBlkNode->gtFlags & GTF_IND_VOLATILE )
2758+ if (cpBlkNode->gtFlags & GTF_BLK_VOLATILE )
27522759 {
2760+ // issue a full memory barrier before & after a volatile CpBlkUnroll operation
27532761 instGen_MemoryBarrier ();
27542762 }
27552763}
@@ -2830,8 +2838,9 @@ void CodeGen::genCodeForCpObj(GenTreeObj* cpObjNode)
28302838 assert (tmpReg2 != REG_WRITE_BARRIER_SRC_BYREF);
28312839 }
28322840
2833- if (cpObjNode->gtFlags & GTF_IND_VOLATILE )
2841+ if (cpObjNode->gtFlags & GTF_BLK_VOLATILE )
28342842 {
2843+ // issue a full memory barrier before & after a volatile CpObj operation
28352844 instGen_MemoryBarrier ();
28362845 }
28372846
@@ -2907,15 +2916,16 @@ void CodeGen::genCodeForCpObj(GenTreeObj* cpObjNode)
29072916 assert (gcPtrCount == 0 );
29082917 }
29092918
2919+ if (cpObjNode->gtFlags & GTF_BLK_VOLATILE)
2920+ {
2921+ // issue a full memory barrier before & after a volatile CpObj operation
2922+ instGen_MemoryBarrier ();
2923+ }
2924+
29102925 // Clear the gcInfo for REG_WRITE_BARRIER_SRC_BYREF and REG_WRITE_BARRIER_DST_BYREF.
29112926 // While we normally update GC info prior to the last instruction that uses them,
29122927 // these actually live into the helper call.
29132928 gcInfo.gcMarkRegSetNpt (RBM_WRITE_BARRIER_SRC_BYREF | RBM_WRITE_BARRIER_DST_BYREF);
2914-
2915- if (cpObjNode->gtFlags & GTF_IND_VOLATILE)
2916- {
2917- instGen_MemoryBarrier ();
2918- }
29192929}
29202930
29212931// generate code do a switch statement based on a table of ip-relative offsets
@@ -3586,6 +3596,7 @@ void CodeGen::genCodeForStoreInd(GenTreeStoreInd* tree)
35863596
35873597 if (tree->gtFlags & GTF_IND_VOLATILE)
35883598 {
3599+ // issue a full memory barrier a before volatile StInd
35893600 instGen_MemoryBarrier ();
35903601 }
35913602
0 commit comments