Skip to content

Commit 4c6a706

Browse files
Fix test failure from #113051 (#113128)
* Fix test failure from #113051 Ensures GT_NEG -> GT_CAST contained by a comparison node forces the node being casted into a register during lowering, to avoid trying to generate code for an incompatible memory operation. * add curley brace --------- Co-authored-by: Kunal Pathak <[email protected]>
1 parent 4eff254 commit 4c6a706

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/coreclr/jit/lowerarmarch.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3095,11 +3095,32 @@ void Lowering::ContainCheckCompare(GenTreeOp* cmp)
30953095
#ifdef TARGET_ARM64
30963096
if (comp->opts.OptimizationEnabled() && (cmp->OperIsCompare() || cmp->OperIs(GT_CMP)))
30973097
{
3098+
auto forceCastOpInRegister = [](GenTree* op) {
3099+
// If the compare contains a cast, make sure that cast node definitely does not become
3100+
// a memory operation, as we won't be able to contain it in CodeGen if this happens.
3101+
// The node being cast must have a register assigned.
3102+
GenTree* cast = nullptr;
3103+
if (op->OperIs(GT_CAST))
3104+
{
3105+
// cmp (extended-register): GT_EQ -> GT_CAST -> ...
3106+
cast = op;
3107+
}
3108+
else if (op->OperIs(GT_NEG) && op->gtGetOp1()->OperIs(GT_CAST))
3109+
{
3110+
// cmn (extended-register): GT_EQ -> GT_NEG -> GT_CAST -> ...
3111+
cast = op->gtGetOp1();
3112+
}
3113+
if (cast)
3114+
{
3115+
cast->AsCast()->CastOp()->ClearRegOptional();
3116+
}
3117+
};
3118+
30983119
if (IsContainableUnaryOrBinaryOp(cmp, op2))
30993120
{
3100-
if (cmp->OperIsCmpCompare() && op2->OperIs(GT_CAST))
3121+
if (cmp->OperIsCmpCompare())
31013122
{
3102-
op2->AsCast()->CastOp()->ClearRegOptional();
3123+
forceCastOpInRegister(op2);
31033124
}
31043125

31053126
MakeSrcContained(cmp, op2);
@@ -3108,9 +3129,9 @@ void Lowering::ContainCheckCompare(GenTreeOp* cmp)
31083129

31093130
if (IsContainableUnaryOrBinaryOp(cmp, op1))
31103131
{
3111-
if (cmp->OperIsCmpCompare() && op1->OperIs(GT_CAST))
3132+
if (cmp->OperIsCmpCompare())
31123133
{
3113-
op1->AsCast()->CastOp()->ClearRegOptional();
3134+
forceCastOpInRegister(op1);
31143135
}
31153136

31163137
MakeSrcContained(cmp, op1);

0 commit comments

Comments
 (0)