// If op2 is smaller then it cannot be in memory, we're probably missing a cast
assert((genTypeSize(op2Type) >= genTypeSize(type)) || !op2->isUsedFromMemory());
// If op2 is a constant then it should fit in the common type
- assert(!op2->IsCnsIntOrI() || genTypeValueFitsIn(op2->AsIntCon()->IconValue(), type));
+ assert(!op2->IsCnsIntOrI() || genTypeCanRepresentValue(type, op2->AsIntCon()->IconValue()));
getEmitter()->emitInsBinary(ins, emitTypeSize(type), op1, op2);
}
//------------------------------------------------------------------------------
-// genTypeValueFitsIn : Checks if a value can be represented by a given type.
+// genTypeCanRepresentValue: Checks if a value can be represented by a given type.
//
// Arguments:
// value - the value to check
// always returned.
template <typename TValue>
-inline bool genTypeValueFitsIn(TValue value, var_types type)
+inline bool genTypeCanRepresentValue(var_types type, TValue value)
{
switch (type)
{
// below is only necessary to prevent worse code generation for switches and loop cloning.
//
- GenTree*& longOp = op1Is64Bit ? cmp->gtOp.gtOp1 : cmp->gtOp.gtOp2;
- GenTree*& smallerOp = op2Is64Bit ? cmp->gtOp.gtOp1 : cmp->gtOp.gtOp2;
+ GenTree* longOp = op1Is64Bit ? cmp->gtOp.gtOp1 : cmp->gtOp.gtOp2;
+ GenTree** smallerOpUse = op2Is64Bit ? &cmp->gtOp.gtOp1 : &cmp->gtOp.gtOp2;
+ var_types smallerType = (*smallerOpUse)->TypeGet();
- assert(genTypeSize(smallerOp) < 8);
+ assert(genTypeSize(smallerType) < 8);
- if (longOp->IsCnsIntOrI() && genTypeValueFitsIn(longOp->AsIntCon()->IconValue(), smallerOp->TypeGet()))
+ if (longOp->IsCnsIntOrI() && genTypeCanRepresentValue(smallerType, longOp->AsIntCon()->IconValue()))
{
- longOp->gtType = smallerOp->TypeGet();
+ longOp->gtType = smallerType;
}
- else if (smallerOp->IsCnsIntOrI())
+ else if ((*smallerOpUse)->IsCnsIntOrI())
{
- smallerOp->gtType = TYP_LONG;
+ (*smallerOpUse)->gtType = TYP_LONG;
}
else
{
- GenTree* cast = comp->gtNewCastNode(TYP_LONG, smallerOp, TYP_LONG);
- smallerOp = cast;
+ GenTree* cast = comp->gtNewCastNode(TYP_LONG, *smallerOpUse, TYP_LONG);
+ *smallerOpUse = cast;
BlockRange().InsertAfter(cast->gtGetOp1(), cast);
}
}
GenTreeIntCon* op2 = cmp->gtGetOp2()->AsIntCon();
ssize_t op2Value = op2->IconValue();
- if (op1->isMemoryOp() && varTypeIsSmall(op1Type) && genTypeValueFitsIn(op2Value, op1Type))
+ if (op1->isMemoryOp() && varTypeIsSmall(op1Type) && genTypeCanRepresentValue(op1Type, op2Value))
{
//
// If op1's type is small then try to narrow op2 so it has the same type as op1.