Skip to content
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
8 changes: 2 additions & 6 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,13 +550,9 @@ GenTree* Lowering::LowerNode(GenTree* node)
return nextNode;
}

nextNode = LowerCast(node);
if (nextNode != nullptr)
{
return nextNode;
}
Comment on lines -553 to -557
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is reverting a change from #97529. The new implementation always preserves the original cast node and does all IR manipulation ahead of it.

LowerCast(node);
break;
}
break;

case GT_BITCAST:
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lower.h
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ class Lowering final : public Phase
GenTree* switchValue,
weight_t defaultLikelihood);

GenTree* LowerCast(GenTree* node);
void LowerCast(GenTree* node);

#if !CPU_LOAD_STORE_ARCH
bool IsRMWIndirCandidate(GenTree* operand, GenTree* storeInd);
Expand Down
24 changes: 6 additions & 18 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -968,22 +968,11 @@ void Lowering::LowerPutArgStkOrSplit(GenTreePutArgStk* putArgNode)
// tree - GT_CAST node to be lowered
//
// Return Value:
// nextNode to be lowered if tree is modified else returns nullptr
//
// Notes:
// 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)
// GT_CAST(float/double, uint16) = GT_CAST(GT_CAST(double/double, int32), uint16)
//
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was copied from xarch, where lowering used to handle the intermediate int cast. That never applied here, and it no longer applies on xarch. I've removed the notes from all the headers and commented the asserts that check the assumptions instead.

// Note that for the overflow conversions we still depend on helper calls and
// don't expect to see them here.
// i) GT_CAST(float/double, int type with overflow detection)
// None.
//
GenTree* Lowering::LowerCast(GenTree* tree)
void Lowering::LowerCast(GenTree* tree)
{
assert(tree->OperGet() == GT_CAST);
assert(tree->OperIs(GT_CAST));

JITDUMP("LowerCast for: ");
DISPNODE(tree);
Expand All @@ -995,17 +984,16 @@ GenTree* Lowering::LowerCast(GenTree* tree)

if (varTypeIsFloating(srcType))
{
// Overflow casts should have been converted to helper call in morph.
noway_assert(!tree->gtOverflow());
assert(!varTypeIsSmall(dstType)); // fgMorphCast creates intermediate casts when converting from float to small
// int.
// Small types should have had an intermediate int cast inserted in morph.
assert(!varTypeIsSmall(dstType));
}

assert(!varTypeIsSmall(srcType));

// Now determine if we have operands that should be contained.
ContainCheckCast(tree->AsCast());

return nullptr;
}

//------------------------------------------------------------------------
Expand Down
23 changes: 5 additions & 18 deletions src/coreclr/jit/lowerloongarch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,21 +514,9 @@ void Lowering::LowerPutArgStkOrSplit(GenTreePutArgStk* putArgNode)
// Return Value:
// None.
//
// Notes:
// 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)
// GT_CAST(float/double, uint16) = GT_CAST(GT_CAST(double/double, int32), uint16)
//
// Note that for the overflow conversions we still depend on helper calls and
// don't expect to see them here.
// i) GT_CAST(float/double, int type with overflow detection)
//

GenTree* Lowering::LowerCast(GenTree* tree)
void Lowering::LowerCast(GenTree* tree)
{
assert(tree->OperGet() == GT_CAST);
assert(tree->OperIs(GT_CAST));

JITDUMP("LowerCast for: ");
DISPNODE(tree);
Expand All @@ -540,17 +528,16 @@ GenTree* Lowering::LowerCast(GenTree* tree)

if (varTypeIsFloating(srcType))
{
// Overflow casts should have been converted to helper call in morph.
noway_assert(!tree->gtOverflow());
assert(!varTypeIsSmall(dstType)); // fgMorphCast creates intermediate casts when converting from float to small
// int.
// Small types should have had an intermediate int cast inserted in morph.
assert(!varTypeIsSmall(dstType));
}

assert(!varTypeIsSmall(srcType));

// Now determine if we have operands that should be contained.
ContainCheckCast(tree->AsCast());

return nullptr;
}

//------------------------------------------------------------------------
Expand Down
23 changes: 5 additions & 18 deletions src/coreclr/jit/lowerriscv64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,21 +437,9 @@ void Lowering::LowerPutArgStkOrSplit(GenTreePutArgStk* putArgNode)
// Return Value:
// None.
//
// Notes:
// 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)
// GT_CAST(float/double, uint16) = GT_CAST(GT_CAST(double/double, int32), uint16)
//
// Note that for the overflow conversions we still depend on helper calls and
// don't expect to see them here.
// i) GT_CAST(float/double, int type with overflow detection)
//

GenTree* Lowering::LowerCast(GenTree* tree)
void Lowering::LowerCast(GenTree* tree)
{
assert(tree->OperGet() == GT_CAST);
assert(tree->OperIs(GT_CAST));

JITDUMP("LowerCast for: ");
DISPNODE(tree);
Expand All @@ -463,17 +451,16 @@ GenTree* Lowering::LowerCast(GenTree* tree)

if (varTypeIsFloating(srcType))
{
// Overflow casts should have been converted to helper call in morph.
noway_assert(!tree->gtOverflow());
assert(!varTypeIsSmall(dstType)); // fgMorphCast creates intermediate casts when converting from float to small
// int.
// Small types should have had an intermediate int cast inserted in morph.
assert(!varTypeIsSmall(dstType));
}

assert(!varTypeIsSmall(srcType));

// Now determine if we have operands that should be contained.
ContainCheckCast(tree->AsCast());

return nullptr;
}

//------------------------------------------------------------------------
Expand Down
Loading
Loading