From ff24db57de07d3b70543fba4df1a1a5ba921b27f Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 12 Aug 2025 15:19:27 +0200 Subject: [PATCH] JIT: Do not remove type changing casts in lowering optimization --- src/coreclr/jit/lower.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/lower.cpp b/src/coreclr/jit/lower.cpp index 81d7e9133dea84..9b1889e1673b8e 100644 --- a/src/coreclr/jit/lower.cpp +++ b/src/coreclr/jit/lower.cpp @@ -5316,11 +5316,12 @@ void Lowering::LowerFieldListToFieldListOfRegisters(GenTreeFieldList* fieldLis if ((i == numRegs - 1) && varTypeUsesIntReg(regType)) { GenTree* node = regEntry->GetNode(); - // If this is a cast that affects only bits after the return size - // then it can be removed. Those bits are undefined in all our ABIs - // for structs. - while (node->OperIs(GT_CAST) && !node->gtOverflow() && varTypeUsesIntReg(node->CastToType()) && - varTypeUsesIntReg(node->CastFromType()) && (genTypeSize(regType) <= genTypeSize(node->CastToType()))) + // If this is a truncation that affects only bits after the return + // size then it can be removed. Those bits are undefined in all our + // ABIs for structs. + while (node->OperIs(GT_CAST) && !node->gtOverflow() && (genActualType(node->CastFromType()) == TYP_INT) && + (genActualType(node->CastToType()) == TYP_INT) && + (genTypeSize(regType) <= genTypeSize(node->CastToType()))) { GenTree* op = node->AsCast()->CastOp(); regEntry->SetNode(op);