Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #14018 from sdmaclea/PR-ARM-Remove-extra-cast
Browse files Browse the repository at this point in the history
[Arm/Arm64] LowerCast remove small int widen cast
  • Loading branch information
briansull authored Sep 19, 2017
2 parents cc7e7dd + 09c7c43 commit d8ad7fa
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
5 changes: 1 addition & 4 deletions src/jit/codegenarm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,7 +1555,7 @@ void CodeGen::genIntToFloatCast(GenTreePtr treeNode)
assert(genIsValidIntReg(op1->gtRegNum)); // Must be a valid int reg.

var_types dstType = treeNode->CastToType();
var_types srcType = op1->TypeGet();
var_types srcType = genActualType(op1->TypeGet());
assert(!varTypeIsFloating(srcType) && varTypeIsFloating(dstType));

// force the srcType to unsigned if GT_UNSIGNED flag is set
Expand All @@ -1565,9 +1565,6 @@ void CodeGen::genIntToFloatCast(GenTreePtr treeNode)
}

// We only expect a srcType whose size is EA_4BYTE.
// For conversions from small types (byte/sbyte/int16/uint16) to float/double,
// we expect the front-end or lowering phase to have generated two levels of cast.
//
emitAttr srcSize = EA_ATTR(genTypeSize(srcType));
noway_assert(srcSize == EA_4BYTE);

Expand Down
5 changes: 1 addition & 4 deletions src/jit/codegenarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3232,7 +3232,7 @@ void CodeGen::genIntToFloatCast(GenTreePtr treeNode)
assert(genIsValidIntReg(op1->gtRegNum)); // Must be a valid int reg.

var_types dstType = treeNode->CastToType();
var_types srcType = op1->TypeGet();
var_types srcType = genActualType(op1->TypeGet());
assert(!varTypeIsFloating(srcType) && varTypeIsFloating(dstType));

// force the srcType to unsigned if GT_UNSIGNED flag is set
Expand All @@ -3242,9 +3242,6 @@ void CodeGen::genIntToFloatCast(GenTreePtr treeNode)
}

// We should never see a srcType whose size is neither EA_4BYTE or EA_8BYTE
// For conversions from small types (byte/sbyte/int16/uint16) to float/double,
// we expect the front-end or lowering phase to have generated two levels of cast.
//
emitAttr srcSize = EA_ATTR(genTypeSize(srcType));
noway_assert((srcSize == EA_4BYTE) || (srcSize == EA_8BYTE));

Expand Down
21 changes: 5 additions & 16 deletions src/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,7 @@ void Lowering::LowerBlockStore(GenTreeBlk* blkNode)
// None.
//
// Notes:
// Casts from small int type to float/double are transformed as follows:
// GT_CAST(byte, float/double) = GT_CAST(GT_CAST(byte, int32), float/double)
// GT_CAST(sbyte, float/double) = GT_CAST(GT_CAST(sbyte, int32), float/double)
// GT_CAST(int16, float/double) = GT_CAST(GT_CAST(int16, int32), float/double)
// GT_CAST(uint16, float/double) = GT_CAST(GT_CAST(uint16, int32), float/double)
//
// Similarly casts from float/double to a smaller int type are transformed as follows:
// Casts from float/double to a smaller int type are transformed as follows:
// GT_CAST(float/double, byte) = GT_CAST(GT_CAST(float/double, int32), byte)
// GT_CAST(float/double, sbyte) = GT_CAST(GT_CAST(float/double, int32), sbyte)
// GT_CAST(float/double, int16) = GT_CAST(GT_CAST(double/double, int32), int16)
Expand All @@ -419,23 +413,18 @@ void Lowering::LowerCast(GenTree* tree)

GenTreePtr op1 = tree->gtOp.gtOp1;
var_types dstType = tree->CastToType();
var_types srcType = op1->TypeGet();
var_types srcType = genActualType(op1->TypeGet());
var_types tmpType = TYP_UNDEF;

if (varTypeIsFloating(srcType))
{
noway_assert(!tree->gtOverflow());
}

// Case of src is a small type and dst is a floating point type.
if (varTypeIsSmall(srcType) && varTypeIsFloating(dstType))
{
// These conversions can never be overflow detecting ones.
noway_assert(!tree->gtOverflow());
tmpType = TYP_INT;
}
assert(!varTypeIsSmall(srcType));

// case of src is a floating point type and dst is a small type.
else if (varTypeIsFloating(srcType) && varTypeIsSmall(dstType))
if (varTypeIsFloating(srcType) && varTypeIsSmall(dstType))
{
NYI_ARM("Lowering for cast from float to small type"); // Not tested yet.
tmpType = TYP_INT;
Expand Down
12 changes: 1 addition & 11 deletions src/jit/lsraarm64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,17 +302,7 @@ void LinearScan::TreeNodeInfoInit(GenTree* tree)
{
castOpType = genUnsignedType(castOpType);
}
#ifdef DEBUG
if (!tree->gtOverflow() && (varTypeIsFloating(castToType) || varTypeIsFloating(castOpType)))
{
// If converting to float/double, the operand must be 4 or 8 byte in size.
if (varTypeIsFloating(castToType))
{
unsigned opSize = genTypeSize(castOpType);
assert(opSize == 4 || opSize == 8);
}
}
#endif // DEBUG

// Some overflow checks need a temp reg

Lowering::CastInfo castInfo;
Expand Down

0 comments on commit d8ad7fa

Please sign in to comment.