From 0ea7869e1685ec80904463bcd4c93ebce5d5c59c Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 12 Feb 2025 01:03:51 +0100 Subject: [PATCH] Merge store/loads for return buffers --- src/coreclr/jit/lower.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 34c8bd16b310c0..75365be8385399 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -9439,9 +9439,16 @@ void Lowering::LowerStoreIndirCoalescing(GenTreeIndir* ind) // // IND is always fine (and all IND created here from such) // IND is not required to be atomic per our Memory Model - const bool allowsNonAtomic = + bool allowsNonAtomic = ((ind->gtFlags & GTF_IND_ALLOW_NON_ATOMIC) != 0) && ((prevInd->gtFlags & GTF_IND_ALLOW_NON_ATOMIC) != 0); + if (!allowsNonAtomic && currData.baseAddr->OperIs(GT_LCL_VAR) && + (currData.baseAddr->AsLclVar()->GetLclNum() == comp->info.compRetBuffArg)) + { + // RetBuf is a private stack memory, so we don't need to worry about atomicity. + allowsNonAtomic = true; + } + if (!allowsNonAtomic && (genTypeSize(ind) > 1) && !varTypeIsSIMD(ind)) { // TODO-CQ: if we see that the target is a local memory (non address exposed)