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

Do not CSE constant operands for GT_SIMD vector constructors #71174

Merged
merged 9 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
47 changes: 47 additions & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,7 @@ struct GenTree
inline bool IsIntegralConst(ssize_t constVal) const;
inline bool IsFloatPositiveZero() const;
inline bool IsVectorZero() const;
inline bool IsVectorCreate() const;
inline bool IsVectorAllBitsSet() const;
inline bool IsVectorConst();

Expand Down Expand Up @@ -8313,6 +8314,52 @@ inline bool GenTree::IsVectorZero() const
return IsCnsVec() && AsVecCon()->IsZero();
}

//-------------------------------------------------------------------
// IsVectorCreate: returns true if this node is the creation of a vector.
// Does not include "Unsafe" method calls.
//
// Returns:
// True if this node is the creation of a vector
//
inline bool GenTree::IsVectorCreate() const
{
#ifdef FEATURE_HW_INTRINSICS
if (OperIs(GT_HWINTRINSIC))
{
switch (AsHWIntrinsic()->GetHWIntrinsicId())
{
case NI_Vector128_Create:
#if defined(TARGET_XARCH)
case NI_Vector256_Create:
#elif defined(TARGET_ARMARCH)
case NI_Vector64_Create:
#endif
return true;

default:
return false;
}
}
#endif // FEATURE_HW_INTRINSICS

#ifdef FEATURE_SIMD
if (OperIs(GT_SIMD))
{
switch (AsSIMD()->GetSIMDIntrinsicId())
{
case SIMDIntrinsicInit:
case SIMDIntrinsicInitN:
return true;

default:
return false;
}
}
#endif // FEATURE_SIMD

return false;
}

//-------------------------------------------------------------------
// IsVectorAllBitsSet: returns true if this node is a vector constant with all bits set.
//
Expand Down
52 changes: 23 additions & 29 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13870,41 +13870,35 @@ GenTree* Compiler::fgMorphMultiOp(GenTreeMultiOp* multiOp)
}
#endif

case NI_Vector128_Create:
#if defined(TARGET_XARCH)
case NI_Vector256_Create:
#elif defined(TARGET_ARMARCH)
case NI_Vector64_Create:
#endif
{
bool hwAllArgsAreConst = true;
for (GenTree** use : multiOp->UseEdges())
{
if (!(*use)->OperIsConst())
{
hwAllArgsAreConst = false;
break;
}
}

// Avoid unexpected CSE for constant arguments for Vector_.Create
// but only if all arguments are constants.
if (hwAllArgsAreConst)
{
for (GenTree** use : multiOp->UseEdges())
{
(*use)->SetDoNotCSE();
}
}
}
break;

default:
break;
}
}
#endif // defined(FEATURE_HW_INTRINSICS) && defined(TARGET_XARCH)

if (opts.OptimizationEnabled() && multiOp->IsVectorCreate())
{
bool allArgsAreConst = true;
for (GenTree* arg : multiOp->Operands())
{
if (!arg->OperIsConst())
TIHan marked this conversation as resolved.
Show resolved Hide resolved
{
allArgsAreConst = false;
break;
}
}

// Avoid unexpected CSE for constant arguments for Vector_.Create
// but only if all arguments are constants.
if (allArgsAreConst)
{
for (GenTree* arg : multiOp->Operands())
{
arg->SetDoNotCSE();
}
}
}

#ifdef FEATURE_HW_INTRINSICS
if (multiOp->OperIsHWIntrinsic() && !optValnumCSE_phase)
{
Expand Down