Skip to content

Commit

Permalink
Clean up in LowerFusedMultiplyAdd
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Nov 23, 2024
1 parent b5bdce2 commit 5b16cd1
Showing 1 changed file with 14 additions and 34 deletions.
48 changes: 14 additions & 34 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1330,49 +1330,29 @@ void Lowering::LowerHWIntrinsicCC(GenTreeHWIntrinsic* node, NamedIntrinsic newIn
void Lowering::LowerFusedMultiplyAdd(GenTreeHWIntrinsic* node)
{
assert(node->GetHWIntrinsicId() == NI_FMA_MultiplyAddScalar);
GenTreeHWIntrinsic* createScalarOps[3];
assert(node->GetOperandCount() == 3);

bool negatedArgs[3] = {};
for (size_t i = 1; i <= 3; i++)
{
GenTree* arg = node->Op(i);

if (!arg->OperIsHWIntrinsic() || (arg->AsHWIntrinsic()->GetHWIntrinsicId() != NI_Vector128_CreateScalarUnsafe))
if (arg->OperIsHWIntrinsic() && (arg->AsHWIntrinsic()->GetHWIntrinsicId() == NI_Vector128_CreateScalarUnsafe))
{
return;
GenTree*& argOp = arg->AsHWIntrinsic()->Op(1);
if (argOp->OperIs(GT_NEG))
{
BlockRange().Remove(argOp);
argOp = argOp->gtGetOp1();
argOp->ClearContained();
ContainCheckHWIntrinsic(arg->AsHWIntrinsic());
negatedArgs[i - 1] = true;
}
}

createScalarOps[i - 1] = arg->AsHWIntrinsic();
}

GenTree* argX = createScalarOps[0]->Op(1);
GenTree* argY = createScalarOps[1]->Op(1);
GenTree* argZ = createScalarOps[2]->Op(1);

const bool negMul = argX->OperIs(GT_NEG) != argY->OperIs(GT_NEG);
if (argX->OperIs(GT_NEG))
{
createScalarOps[0]->Op(1) = argX->gtGetOp1();
BlockRange().Remove(argX);

createScalarOps[0]->Op(1)->ClearContained();
ContainCheckHWIntrinsic(createScalarOps[0]);
}
if (argY->OperIs(GT_NEG))
{
createScalarOps[1]->Op(1) = argY->gtGetOp1();
BlockRange().Remove(argY);

createScalarOps[1]->Op(1)->ClearContained();
ContainCheckHWIntrinsic(createScalarOps[1]);
}
if (argZ->OperIs(GT_NEG))
bool negMul = negatedArgs[0] ^ negatedArgs[1];
if (negatedArgs[2])
{
createScalarOps[2]->Op(1) = argZ->gtGetOp1();
BlockRange().Remove(argZ);

createScalarOps[2]->Op(1)->ClearContained();
ContainCheckHWIntrinsic(createScalarOps[2]);

node->ChangeHWIntrinsicId(negMul ? NI_FMA_MultiplySubtractNegatedScalar : NI_FMA_MultiplySubtractScalar);
}
else
Expand Down

0 comments on commit 5b16cd1

Please sign in to comment.