Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Recognize MUL_LONG in lowering for ARM64
  • Loading branch information
SingleAccretion committed Oct 1, 2021
commit 5336b7249a6bdacfd1a91ccd56a5fbc313b38884
5 changes: 2 additions & 3 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,10 @@ GenTree* Lowering::LowerNode(GenTree* node)

case GT_MUL:
case GT_MULHI:
#if defined(TARGET_X86)
#if defined(TARGET_X86) || defined(TARGET_ARM64)
case GT_MUL_LONG:
#endif
ContainCheckMul(node->AsOp());
break;
return LowerMul(node->AsOp());

case GT_UDIV:
case GT_UMOD:
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ class Lowering final : public Phase
void LowerIndir(GenTreeIndir* ind);
void LowerStoreIndir(GenTreeStoreInd* node);
GenTree* LowerAdd(GenTreeOp* node);
GenTree* LowerMul(GenTreeOp* mul);
bool LowerUnsignedDivOrMod(GenTreeOp* divMod);
GenTree* LowerConstIntDivOrMod(GenTree* node);
GenTree* LowerSignedDivOrMod(GenTree* node);
Expand Down
54 changes: 54 additions & 0 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,60 @@ void Lowering::LowerStoreIndir(GenTreeStoreInd* node)
ContainCheckStoreIndir(node);
}

//------------------------------------------------------------------------
// LowerMul: Lower a GT_MUL/GT_MULHI/GT_MUL_LONG node.
//
// For ARM64 recognized GT_MULs that can be turned into GT_MUL_LONGs, as
// those are cheaper. Performs contaiment checks.
//
// Arguments:
// mul - The node to lower
//
// Return Value:
// The next node to lower.
//
GenTree* Lowering::LowerMul(GenTreeOp* mul)
{
assert(mul->OperIsMul());

#ifdef TARGET_ARM64
if (comp->opts.OptimizationEnabled() && mul->OperIs(GT_MUL) && mul->IsValidLongMul())
{
GenTreeCast* op1 = mul->gtGetOp1()->AsCast();
GenTree* op2 = mul->gtGetOp2();

mul->ClearOverflow();
mul->ClearUnsigned();
if (op1->IsUnsigned())
{
mul->SetUnsigned();
}

mul->gtOp1 = op1->CastOp();
BlockRange().Remove(op1);

if (op2->OperIs(GT_CAST))
{
mul->gtOp2 = op2->AsCast()->CastOp();
BlockRange().Remove(op2);
}
else
{
assert(op2->IsIntegralConst());
assert(FitsIn<int32_t>(op2->AsIntConCommon()->IntegralValue()));

op2->ChangeType(TYP_INT);
}

mul->ChangeOper(GT_MUL_LONG);
}
#endif // TARGET_ARM64

ContainCheckMul(mul);

return mul->gtNext;
}

//------------------------------------------------------------------------
// LowerBlockStore: Lower a block store node
//
Expand Down
20 changes: 20 additions & 0 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,26 @@ void Lowering::LowerStoreIndir(GenTreeStoreInd* node)
ContainCheckStoreIndir(node);
}

//------------------------------------------------------------------------
// LowerMul: Lower a GT_MUL/GT_MULHI/GT_MUL_LONG node.
//
// Currently only performs containment checks.
//
// Arguments:
// mul - The node to lower
//
// Return Value:
// The next node to lower.
//
GenTree* Lowering::LowerMul(GenTreeOp* mul)
{
assert(mul->OperIsMul());

ContainCheckMul(mul);

return mul->gtNext;
}

//------------------------------------------------------------------------
// LowerBlockStore: Lower a block store node
//
Expand Down