Skip to content

Commit 13d9927

Browse files
authored
Fix ARM64 unsigned div by const perf regression (#57400)
1 parent d6ea158 commit 13d9927

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/coreclr/jit/codegenarm64.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1853,8 +1853,16 @@ void CodeGen::genCodeForBinary(GenTreeOp* treeNode)
18531853

18541854
// The arithmetic node must be sitting in a register (since it's not contained)
18551855
assert(targetReg != REG_NA);
1856+
emitAttr attr = emitActualTypeSize(treeNode);
18561857

1857-
regNumber r = emit->emitInsTernary(ins, emitActualTypeSize(treeNode), treeNode, op1, op2);
1858+
// UMULL/SMULL is twice as fast for 32*32->64bit MUL
1859+
if ((oper == GT_MUL) && (targetType == TYP_LONG) && genActualTypeIsInt(op1) && genActualTypeIsInt(op2))
1860+
{
1861+
ins = treeNode->IsUnsigned() ? INS_umull : INS_smull;
1862+
attr = EA_4BYTE;
1863+
}
1864+
1865+
regNumber r = emit->emitInsTernary(ins, attr, treeNode, op1, op2);
18581866
assert(r == targetReg);
18591867

18601868
genProduceReg(treeNode);

src/coreclr/jit/lower.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5254,7 +5254,11 @@ bool Lowering::LowerUnsignedDivOrMod(GenTreeOp* divMod)
52545254
BlockRange().InsertBefore(divMod, preShiftBy, adjustedDividend);
52555255
firstNode = preShiftBy;
52565256
}
5257-
else if (type != TYP_I_IMPL)
5257+
else if (type != TYP_I_IMPL
5258+
#ifdef TARGET_ARM64
5259+
&& !simpleMul // On ARM64 we will use a 32x32->64 bit multiply as that's faster.
5260+
#endif
5261+
)
52585262
{
52595263
adjustedDividend = comp->gtNewCastNode(TYP_I_IMPL, adjustedDividend, true, TYP_U_IMPL);
52605264
BlockRange().InsertBefore(divMod, adjustedDividend);
@@ -5269,6 +5273,14 @@ bool Lowering::LowerUnsignedDivOrMod(GenTreeOp* divMod)
52695273
#endif
52705274

52715275
divisor->gtType = TYP_I_IMPL;
5276+
5277+
#ifdef TARGET_ARM64
5278+
if (simpleMul)
5279+
{
5280+
divisor->gtType = TYP_INT;
5281+
}
5282+
#endif
5283+
52725284
divisor->AsIntCon()->SetIconValue(magic);
52735285

52745286
if (isDiv && !postShift && type == TYP_I_IMPL)

0 commit comments

Comments
 (0)