From 91e14094811f14a9c1597bfda5f8419535ce228f Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Wed, 12 Aug 2026 19:17:20 +0200 Subject: [PATCH] JIT: allow containing shift/mul/cast into byref ADD/SUB on arm64 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0d35d524-d3e6-4da0-85a3-75a5d07d9143 --- src/coreclr/jit/codegenarm64.cpp | 7 ++++--- src/coreclr/jit/lowerarmarch.cpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/codegenarm64.cpp b/src/coreclr/jit/codegenarm64.cpp index b1dfa28f51720f..161173f80ec507 100644 --- a/src/coreclr/jit/codegenarm64.cpp +++ b/src/coreclr/jit/codegenarm64.cpp @@ -2702,7 +2702,7 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree) if (op2->OperIs(GT_MUL) && op2->isContained()) { // In the future, we might consider enabling this for floating-point "unsafe" math. - assert(varTypeIsIntegral(tree)); + assert(varTypeIsIntegral(tree) || tree->TypeIs(TYP_BYREF)); // These operations cannot set flags assert((tree->gtFlags & GTF_SET_FLAGS) == 0); @@ -2740,7 +2740,7 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree) } else if (op2->OperIs(GT_LSH, GT_RSH, GT_RSZ) && op2->isContained()) { - assert(varTypeIsIntegral(tree)); + assert(varTypeIsIntegral(tree) || tree->TypeIs(TYP_BYREF)); GenTree* a = op1; GenTree* b = op2->gtGetOp1(); @@ -2799,6 +2799,7 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree) } else if (op2->OperIs(GT_ROR) && op2->isContained()) { + // ROR is only contained under AND/OR/XOR parents, which are never TYP_BYREF. assert(varTypeIsIntegral(tree)); GenTree* a = op1; @@ -2841,7 +2842,7 @@ void CodeGen::genCodeForBinary(GenTreeOp* tree) } else if (op2->OperIs(GT_CAST) && op2->isContained()) { - assert(varTypeIsIntegral(tree)); + assert(varTypeIsIntegral(tree) || tree->TypeIs(TYP_BYREF)); GenTree* a = op1; GenTree* b = op2->AsCast()->CastOp(); diff --git a/src/coreclr/jit/lowerarmarch.cpp b/src/coreclr/jit/lowerarmarch.cpp index d3955c7861ae1d..d4c691af0a033f 100644 --- a/src/coreclr/jit/lowerarmarch.cpp +++ b/src/coreclr/jit/lowerarmarch.cpp @@ -196,7 +196,7 @@ bool Lowering::IsContainableUnaryOrBinaryOp(GenTree* parentNode, GenTree* childN if (parentNode->isContained()) return false; - if (!varTypeIsIntegral(parentNode)) + if (!varTypeIsIntegral(parentNode) && !parentNode->TypeIs(TYP_BYREF)) return false; if (parentNode->gtGetOp1()->isContained() || (parentNode->OperIsBinary() && parentNode->gtGetOp2()->isContained()))