Skip to content

Commit

Permalink
Have Unsafe.Subtract and Unsafe.SubtractByteOffset be intrinsic
Browse files Browse the repository at this point in the history
  • Loading branch information
tannergooding committed May 1, 2022
1 parent 6963037 commit 2301adc
Showing 1 changed file with 35 additions and 4 deletions.
39 changes: 35 additions & 4 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4834,8 +4834,8 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic,
tmp = op2;
}

type = impGetByRefResultType(GT_ADD, /* uns */ false, &tmp, &op1);
return gtNewOperNode(GT_ADD, type, tmp, op1);
type = impGetByRefResultType(GT_ADD, /* uns */ false, &op1, &tmp);
return gtNewOperNode(GT_ADD, type, op1, tmp);
}

case NI_SRCS_UNSAFE_AddByteOffset:
Expand Down Expand Up @@ -5136,7 +5136,33 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic,
// sub
// ret

return nullptr;
GenTree* op2 = impPopStack().val;
GenTree* op1 = impPopStack().val;
impBashVarAddrsToI(op1, op2);

GenTree* tmp = nullptr;
var_types type = TYP_UNKNOWN;

unsigned classSize = info.compCompHnd->getClassSize(sig->sigInst.methInst[0]);

if (classSize != 1)
{
GenTree* size = gtNewIconNode(classSize, TYP_INT);

#ifdef TARGET_64BIT
size = gtNewCastNode(TYP_I_IMPL, size, /* uns */ false, TYP_I_IMPL);
#endif

type = impGetByRefResultType(GT_MUL, /* uns */ false, &op2, &size);
tmp = new (this, GT_CALL) GenTreeOp(GT_MUL, type, op2, size DEBUGARG(/* largeNode */ true));
}
else
{
tmp = op2;
}

type = impGetByRefResultType(GT_SUB, /* uns */ false, &op1, &tmp);
return gtNewOperNode(GT_SUB, type, op1, tmp);
}

case NI_SRCS_UNSAFE_SubtractByteOffset:
Expand All @@ -5148,7 +5174,12 @@ GenTree* Compiler::impSRCSUnsafeIntrinsic(NamedIntrinsic intrinsic,
// sub
// ret

return nullptr;
GenTree* op2 = impPopStack().val;
GenTree* op1 = impPopStack().val;
impBashVarAddrsToI(op1, op2);

var_types type = impGetByRefResultType(GT_SUB, /* uns */ false, &op1, &op2);
return gtNewOperNode(GT_SUB, type, op1, op2);
}

case NI_SRCS_UNSAFE_Unbox:
Expand Down

0 comments on commit 2301adc

Please sign in to comment.