diff --git a/src/coreclr/jit/codegenarmarch.cpp b/src/coreclr/jit/codegenarmarch.cpp index c671f04579f6b..b653017225142 100644 --- a/src/coreclr/jit/codegenarmarch.cpp +++ b/src/coreclr/jit/codegenarmarch.cpp @@ -473,8 +473,10 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode) case GT_PINVOKE_PROLOG: noway_assert(((gcInfo.gcRegGCrefSetCur | gcInfo.gcRegByrefSetCur) & ~fullIntArgRegMask()) == 0); +#ifdef PSEUDORANDOM_NOP_INSERTION // the runtime side requires the codegen here to be consistent emit->emitDisableRandomNops(); +#endif // PSEUDORANDOM_NOP_INSERTION break; case GT_LABEL: diff --git a/src/coreclr/jit/codegenxarch.cpp b/src/coreclr/jit/codegenxarch.cpp index 79b1384e8d24e..60bfd6b615da7 100644 --- a/src/coreclr/jit/codegenxarch.cpp +++ b/src/coreclr/jit/codegenxarch.cpp @@ -1793,8 +1793,10 @@ void CodeGen::genCodeForTreeNode(GenTree* treeNode) case GT_PINVOKE_PROLOG: noway_assert(((gcInfo.gcRegGCrefSetCur | gcInfo.gcRegByrefSetCur) & ~fullIntArgRegMask()) == 0); +#ifdef PSEUDORANDOM_NOP_INSERTION // the runtime side requires the codegen here to be consistent emit->emitDisableRandomNops(); +#endif // PSEUDORANDOM_NOP_INSERTION break; case GT_LABEL: diff --git a/src/coreclr/jit/emit.h b/src/coreclr/jit/emit.h index 8030cc4b0fb16..a6000e2e498f6 100644 --- a/src/coreclr/jit/emit.h +++ b/src/coreclr/jit/emit.h @@ -1846,10 +1846,13 @@ class emitter unsigned emitNxtIGnum; +#ifdef PSEUDORANDOM_NOP_INSERTION + // random nop insertion to break up nop sleds unsigned emitNextNop; bool emitRandomNops; - void emitEnableRandomNops() + + void emitEnableRandomNops() { emitRandomNops = true; } @@ -1858,6 +1861,8 @@ class emitter emitRandomNops = false; } +#endif // PSEUDORANDOM_NOP_INSERTION + insGroup* emitAllocAndLinkIG(); insGroup* emitAllocIG(); void emitInitIG(insGroup* ig); diff --git a/src/coreclr/jit/flowgraph.cpp b/src/coreclr/jit/flowgraph.cpp index 9314d48f4a063..950988adca193 100644 --- a/src/coreclr/jit/flowgraph.cpp +++ b/src/coreclr/jit/flowgraph.cpp @@ -9237,18 +9237,19 @@ class MergedReturns // Need to check both for matching const val and for genReturnBB // because genReturnBB is used for non-constant returns and its // corresponding entry in the returnConstants array is garbage. - if (returnConstants[i] == constVal) - { - BasicBlock* returnBlock = returnBlocks[i]; + // Check the returnBlocks[] first, so we don't access an uninitialized + // returnConstants[] value (which some tools like valgrind will + // complain about). - if (returnBlock == comp->genReturnBB) - { - // This is the block used for non-constant returns, so - // its returnConstants entry is just garbage; don't be - // fooled. - continue; - } + BasicBlock* returnBlock = returnBlocks[i]; + if (returnBlock == comp->genReturnBB) + { + continue; + } + + if (returnConstants[i] == constVal) + { *index = i; return returnBlock; } diff --git a/src/coreclr/jit/instr.cpp b/src/coreclr/jit/instr.cpp index b78adf8681ad9..06ef501a5220a 100644 --- a/src/coreclr/jit/instr.cpp +++ b/src/coreclr/jit/instr.cpp @@ -193,6 +193,7 @@ void CodeGen::instGen(instruction ins) GetEmitter()->emitIns(ins); #ifdef TARGET_XARCH +#ifdef PSEUDORANDOM_NOP_INSERTION // A workaround necessitated by limitations of emitter // if we are scheduled to insert a nop here, we have to delay it // hopefully we have not missed any other prefix instructions or places @@ -201,6 +202,7 @@ void CodeGen::instGen(instruction ins) { GetEmitter()->emitNextNop = 1; } +#endif // PSEUDORANDOM_NOP_INSERTION #endif } diff --git a/src/coreclr/jit/lsra.cpp b/src/coreclr/jit/lsra.cpp index 5add9f563e527..652b99e60ba82 100644 --- a/src/coreclr/jit/lsra.cpp +++ b/src/coreclr/jit/lsra.cpp @@ -716,9 +716,10 @@ LinearScan::LinearScan(Compiler* theCompiler) , refPositions(theCompiler->getAllocator(CMK_LSRA_RefPosition)) , listNodePool(theCompiler) { + firstColdLoc = MaxLocation; + #ifdef DEBUG maxNodeLocation = 0; - firstColdLoc = MaxLocation; activeRefPosition = nullptr; // Get the value of the environment variable that controls stress for register allocation