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

ARM64 - Emitting msub instruction #66621

Merged
merged 7 commits into from
Apr 12, 2022
Merged
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
Combining some logic for GT_MADD and GT_MSUB
  • Loading branch information
TIHan committed Mar 15, 2022
commit f006f8e37e763f0117453c79a4733039f1888a68
86 changes: 43 additions & 43 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1633,59 +1633,59 @@ void Lowering::ContainCheckBinary(GenTreeOp* node)
CheckImmedAndMakeContained(node, op2);

#ifdef TARGET_ARM64
// Find "a * b + c" or "c + a * b" in order to emit MADD/MSUB
if (comp->opts.OptimizationEnabled() && varTypeIsIntegral(node) && !node->isContained() && node->OperIs(GT_ADD) &&
!node->gtOverflow() && (op1->OperIs(GT_MUL) || op2->OperIs(GT_MUL)))
if (comp->opts.OptimizationEnabled() && varTypeIsIntegral(node) && !node->isContained() && !node->gtOverflow())
{
GenTree* mul;
GenTree* c;
if (op1->OperIs(GT_MUL))
// Find "a * b + c" or "c + a * b" in order to emit MADD/MSUB
if (node->OperIs(GT_ADD) && (op1->OperIs(GT_MUL) || op2->OperIs(GT_MUL)))
{
mul = op1;
c = op2;
}
else
{
mul = op2;
c = op1;
}

GenTree* a = mul->gtGetOp1();
GenTree* b = mul->gtGetOp2();

if (!mul->isContained() && !mul->gtOverflow() && !a->isContained() && !b->isContained() && !c->isContained() &&
varTypeIsIntegral(mul))
{
if (a->OperIs(GT_NEG) && !a->gtGetOp1()->isContained() && !a->gtGetOp1()->IsRegOptional())
GenTree* mul;
GenTree* c;
if (op1->OperIs(GT_MUL))
{
// "-a * b + c" to MSUB
MakeSrcContained(mul, a);
mul = op1;
c = op2;
}
if (b->OperIs(GT_NEG) && !b->gtGetOp1()->isContained())
else
{
// "a * -b + c" to MSUB
MakeSrcContained(mul, b);
mul = op2;
c = op1;
}
// If both 'a' and 'b' are GT_NEG - MADD will be emitted.

node->ChangeOper(GT_MADD);
MakeSrcContained(node, mul);
}
}
GenTree* a = mul->gtGetOp1();
GenTree* b = mul->gtGetOp2();

// Find "a - b * c" in order to emit MSUB
if (comp->opts.OptimizationEnabled() && varTypeIsIntegral(node) && !node->isContained() && node->OperIs(GT_SUB) &&
!node->gtOverflow() && op2->OperIs(GT_MUL) && !op2->isContained() && !op2->gtOverflow() &&
varTypeIsIntegral(op2))
{
GenTree* a = op1;
GenTree* b = op2->gtGetOp1();
GenTree* c = op2->gtGetOp2();
if (!mul->isContained() && !mul->gtOverflow() && !a->isContained() && !b->isContained() &&
!c->isContained() && varTypeIsIntegral(mul))
{
if (a->OperIs(GT_NEG) && !a->gtGetOp1()->isContained() && !a->gtGetOp1()->IsRegOptional())
{
// "-a * b + c" to MSUB
MakeSrcContained(mul, a);
}
if (b->OperIs(GT_NEG) && !b->gtGetOp1()->isContained())
{
// "a * -b + c" to MSUB
MakeSrcContained(mul, b);
}
// If both 'a' and 'b' are GT_NEG - MADD will be emitted.

if (!a->isContained() && !b->isContained() && !c->isContained())
node->ChangeOper(GT_MADD);
MakeSrcContained(node, mul);
}
}
// Find "a - b * c" in order to emit MSUB
else if (node->OperIs(GT_SUB) && op2->OperIs(GT_MUL) && !op2->isContained() && !op2->gtOverflow() &&
varTypeIsIntegral(op2))
{
node->ChangeOper(GT_MSUB);
MakeSrcContained(node, op2);
GenTree* a = op1;
GenTree* b = op2->gtGetOp1();
GenTree* c = op2->gtGetOp2();

if (!a->isContained() && !b->isContained() && !c->isContained())
{
node->ChangeOper(GT_MSUB);
MakeSrcContained(node, op2);
}
}
}

Expand Down