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

Add support for folding core SIMD operations that produce TYP_MASK on newer hardware #104875

Merged
merged 11 commits into from
Jul 15, 2024
Next Next commit
Allow pushing constants to the right for simd comparisons
  • Loading branch information
tannergooding committed Jul 13, 2024
commit fb650ef97332b3d4cb30690991065923d8657a6d
28 changes: 28 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11442,6 +11442,34 @@ GenTree* Compiler::fgMorphHWIntrinsic(GenTreeHWIntrinsic* tree)
std::swap(op1, tree->Op(2));
}
}
else if (!optValnumCSE_phase)
{
bool isScalar = false;
genTreeOps oper = tree->GetOperForHWIntrinsicId(&isScalar);

// We can't handle scalar operations since they can copy upper bits from op1
if (GenTree::OperIsCompare(oper) && !isScalar)
{
assert(tree->GetOperandCount() == 2);

GenTree* op1 = tree->Op(1);
GenTree* op2 = tree->Op(2);

if (op1->IsVectorConst())
{
// Move constant vectors from op1 to op2 for comparison operations

var_types simdBaseType = tree->GetSimdBaseType();
unsigned simdSize = tree->GetSimdSize();

genTreeOps newOper = GenTree::SwapRelop(oper);
NamedIntrinsic newId = GenTreeHWIntrinsic::GetHWIntrinsicIdForCmpOp(this, newOper, op2, op1,
simdBaseType, simdSize, false);

tree->ResetHWIntrinsicId(newId, op2, op1);
}
}
}

// Try to fold it, maybe we get lucky,
GenTree* foldedTree = gtFoldExpr(tree);
Expand Down