Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ARM64 unsigned div by const perf regression #57400

Merged
merged 2 commits into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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