Skip to content

Commit

Permalink
Do not CSE constant operands for GT_SIMD vector constructors (dotne…
Browse files Browse the repository at this point in the history
…t#71174)

* Do not CSE constant operands for GT_SIMD

* Re-arrange logic

* Feedback

* Fixing build

* Feedback

* Feedback

* Feedback

* Feedback

* Feedback
  • Loading branch information
TIHan committed Jun 23, 2022
1 parent 1ea7466 commit 831f778
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 29 deletions.
47 changes: 47 additions & 0 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1774,6 +1774,7 @@ struct GenTree
inline bool IsFloatPositiveZero() const;
inline bool IsFloatNegativeZero() const;
inline bool IsVectorZero() const;
inline bool IsVectorCreate() const;
inline bool IsVectorAllBitsSet() const;
inline bool IsVectorConst();

Expand Down Expand Up @@ -8396,6 +8397,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 @@ -13925,41 +13925,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())
{
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

0 comments on commit 831f778

Please sign in to comment.