Skip to content

Commit 1840916

Browse files
committed
Fix instruction order, remove pointless diffs
1 parent 6c2df8e commit 1840916

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/coreclr/jit/codegenriscv64.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,17 +1571,19 @@ void CodeGen::genLclHeap(GenTree* tree)
15711571
if (compiler->compOpportunisticallyDependsOn(InstructionSet_Zbb))
15721572
{
15731573
emit->emitIns_R_R_R(INS_maxu, EA_PTRSIZE, tempReg, REG_SPBASE, regCnt);
1574-
emit->emitIns_R_R_R(INS_sub, EA_PTRSIZE, regCnt, tempReg, regCnt);
1574+
emit->emitIns_R_R_R(INS_sub, EA_PTRSIZE, regCnt, tempReg, regCnt); // regCnt now holds ultimate SP
15751575
}
15761576
else
15771577
{
1578-
emit->emitIns_R_R_R(INS_sub, EA_PTRSIZE, regCnt, REG_SPBASE, regCnt); // cnt = sp - cnt; // ultimate SP
1579-
// If the subtraction above overflowed (i.e. sp < ultimateSP), set regCnt to lowest possible value (i.e. 0)
15801578
emit->emitIns_R_R_R(INS_sltu, EA_PTRSIZE, tempReg, REG_SPBASE, regCnt); // temp = overflow ? 1 : 0;
1581-
emit->emitIns_R_R_I(INS_addi, EA_PTRSIZE, tempReg, tempReg, -1); // temp = overflow ? 0 : full_mask;
1582-
emit->emitIns_R_R_R(INS_and, EA_PTRSIZE, regCnt, regCnt, tempReg); // cnt = overflow ? 0 : cnt;
1579+
1580+
// sub regCnt, SP, regCnt // regCnt now holds ultimate SP
1581+
emit->emitIns_R_R_R(INS_sub, EA_PTRSIZE, regCnt, REG_SPBASE, regCnt);
1582+
1583+
// If overflow, set regCnt to lowest possible value
1584+
emit->emitIns_R_R_I(INS_addi, EA_PTRSIZE, tempReg, tempReg, -1); // temp = overflow ? 0 : full_mask;
1585+
emit->emitIns_R_R_R(INS_and, EA_PTRSIZE, regCnt, regCnt, tempReg); // cnt = overflow ? 0 : cnt;
15831586
}
1584-
// At this point 'regCnt' is set to the ultimate SP.
15851587

15861588
regNumber rPageSize = internalRegisters.GetSingle(tree);
15871589
noway_assert(rPageSize != tempReg);

0 commit comments

Comments
 (0)