Skip to content

Commit

Permalink
Fix ARM64 unsigned div by const perf regression (#57400)
Browse files Browse the repository at this point in the history
  • Loading branch information
pentp committed Aug 17, 2021
1 parent d6ea158 commit 13d9927
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/coreclr/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1853,8 +1853,16 @@ void CodeGen::genCodeForBinary(GenTreeOp* treeNode)

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

regNumber r = emit->emitInsTernary(ins, emitActualTypeSize(treeNode), treeNode, op1, op2);
// UMULL/SMULL is twice as fast for 32*32->64bit MUL
if ((oper == GT_MUL) && (targetType == TYP_LONG) && genActualTypeIsInt(op1) && genActualTypeIsInt(op2))
{
ins = treeNode->IsUnsigned() ? INS_umull : INS_smull;
attr = EA_4BYTE;
}

regNumber r = emit->emitInsTernary(ins, attr, treeNode, op1, op2);
assert(r == targetReg);

genProduceReg(treeNode);
Expand Down
14 changes: 13 additions & 1 deletion src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5254,7 +5254,11 @@ bool Lowering::LowerUnsignedDivOrMod(GenTreeOp* divMod)
BlockRange().InsertBefore(divMod, preShiftBy, adjustedDividend);
firstNode = preShiftBy;
}
else if (type != TYP_I_IMPL)
else if (type != TYP_I_IMPL
#ifdef TARGET_ARM64
&& !simpleMul // On ARM64 we will use a 32x32->64 bit multiply as that's faster.
#endif
)
{
adjustedDividend = comp->gtNewCastNode(TYP_I_IMPL, adjustedDividend, true, TYP_U_IMPL);
BlockRange().InsertBefore(divMod, adjustedDividend);
Expand All @@ -5269,6 +5273,14 @@ bool Lowering::LowerUnsignedDivOrMod(GenTreeOp* divMod)
#endif

divisor->gtType = TYP_I_IMPL;

#ifdef TARGET_ARM64
if (simpleMul)
{
divisor->gtType = TYP_INT;
}
#endif

divisor->AsIntCon()->SetIconValue(magic);

if (isDiv && !postShift && type == TYP_I_IMPL)
Expand Down

0 comments on commit 13d9927

Please sign in to comment.