Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
egorbot committed Nov 2, 2024
1 parent 5f4f3d3 commit 1131e42
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/coreclr/jit/rangecheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1050,7 +1050,8 @@ Range RangeCheck::ComputeRangeForBinOp(BasicBlock* block, GenTreeOp* binop, bool
return Range(Limit::keUnknown);
}

int icon = -1;
int op1op2Cns = 0;
int icon = -1;
if (binop->OperIs(GT_AND))
{
// x & cns -> [0..cns]
Expand All @@ -1062,11 +1063,10 @@ Range RangeCheck::ComputeRangeForBinOp(BasicBlock* block, GenTreeOp* binop, bool
icon = static_cast<int>(op2Cns) - 1;
}
else if (binop->OperIs(GT_RSH, GT_LSH) && op1->OperIs(GT_AND) &&
vnStore->IsVNConstantFittingIn<int32_t>(op1->AsOp()->gtGetOp2()->gtVNPair.GetConservative()))
vnStore->IsVNIntegralConstant<int>(op1->AsOp()->gtGetOp2()->gtVNPair.GetConservative(), &op1op2Cns))
{
// (x & cns1) >> cns2 -> [0..cns1>>cns2]
int icon1 = static_cast<int>(
vnStore->CoercedConstantValue<ssize_t>(op1->AsOp()->gtGetOp2()->gtVNPair.GetConservative()));
int icon1 = op1op2Cns;
int icon2 = static_cast<int>(op2Cns);
if ((icon1 >= 0) && (icon2 >= 0) && (icon2 < 32))
{
Expand Down
11 changes: 9 additions & 2 deletions src/coreclr/jit/valuenum.h
Original file line number Diff line number Diff line change
Expand Up @@ -1343,14 +1343,21 @@ class ValueNumStore
}

template <typename T>
bool IsVNConstantFittingIn(ValueNum vn)
bool IsVNIntegralConstant(ValueNum vn, T* value)
{
if (!IsVNConstant(vn) || !varTypeIsIntegral(TypeOfVN(vn)))
{
*value = 0;
return false;
}
ssize_t val = CoercedConstantValue<ssize_t>(vn);
return FitsIn<T>(val);
if (FitsIn<T>(val))
{
*value = static_cast<T>(val);
return true;
}
*value = 0;
return false;
}

CORINFO_OBJECT_HANDLE ConstantObjHandle(ValueNum vn)
Expand Down

0 comments on commit 1131e42

Please sign in to comment.