From 5b16cd1479213fdc13cc00a28b243318c893b147 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Sun, 24 Nov 2024 00:24:45 +0100 Subject: [PATCH] Clean up in LowerFusedMultiplyAdd --- src/coreclr/jit/lowerxarch.cpp | 48 ++++++++++------------------------ 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 41ae0a9fc6d3b..6968eca0a0a90 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -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