Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
pentp committed Oct 4, 2021
1 parent 1debfb0 commit 2a7d9e2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
11 changes: 5 additions & 6 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5217,13 +5217,10 @@ bool Lowering::LowerUnsignedDivOrMod(GenTreeOp* divMod)

unsigned bits = type == TYP_INT ? 32 : 64;
// if the dividend operand is AND or RSZ with a constant then the number of input bits can be reduced
if (dividend->OperIs(GT_AND))
if (dividend->OperIs(GT_AND) && dividend->gtGetOp2()->IsCnsIntOrI())
{
size_t maskCns = static_cast<size_t>(
dividend->gtGetOp1()->IsCnsIntOrI()
? dividend->gtGetOp1()->AsIntCon()->IconValue()
: dividend->gtGetOp2()->IsCnsIntOrI() ? dividend->gtGetOp2()->AsIntCon()->IconValue() : 0);
if (maskCns)
size_t maskCns = static_cast<size_t>(dividend->gtGetOp2()->AsIntCon()->IconValue());
if (maskCns != 0)
{
unsigned maskBits = 1;
while (maskCns >>= 1)
Expand All @@ -5236,7 +5233,9 @@ bool Lowering::LowerUnsignedDivOrMod(GenTreeOp* divMod)
{
size_t shiftCns = static_cast<size_t>(dividend->gtGetOp2()->AsIntCon()->IconValue());
if (shiftCns < bits)
{
bits -= static_cast<unsigned>(shiftCns);
}
}

if (type == TYP_INT)
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2417,13 +2417,15 @@ T GetUnsignedMagic(T d, bool* increment /*out*/, int* preShift /*out*/, int* pos
uint32_t GetUnsigned32Magic(
uint32_t d, bool* increment /*out*/, int* preShift /*out*/, int* postShift /*out*/, unsigned bits)
{
assert(bits <= 32);
return GetUnsignedMagic<uint32_t>(d, increment, preShift, postShift, bits);
}

#ifdef TARGET_64BIT
uint64_t GetUnsigned64Magic(
uint64_t d, bool* increment /*out*/, int* preShift /*out*/, int* postShift /*out*/, unsigned bits)
{
assert(bits <= 64);
return GetUnsignedMagic<uint64_t>(d, increment, preShift, postShift, bits);
}
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -762,10 +762,10 @@ class CritSecHolder
namespace MagicDivide
{
uint32_t GetUnsigned32Magic(
uint32_t d, bool* increment /*out*/, int* preShift /*out*/, int* postShift /*out*/, unsigned bits = 32);
uint32_t d, bool* increment /*out*/, int* preShift /*out*/, int* postShift /*out*/, unsigned bits);
#ifdef TARGET_64BIT
uint64_t GetUnsigned64Magic(
uint64_t d, bool* increment /*out*/, int* preShift /*out*/, int* postShift /*out*/, unsigned bits = 64);
uint64_t d, bool* increment /*out*/, int* preShift /*out*/, int* postShift /*out*/, unsigned bits);
#endif
int32_t GetSigned32Magic(int32_t d, int* shift /*out*/);
#ifdef TARGET_64BIT
Expand Down

0 comments on commit 2a7d9e2

Please sign in to comment.