Skip to content

Commit

Permalink
Fix the CAST<float <-> integer> bug
Browse files Browse the repository at this point in the history
10 diffs across CLR and libraries tests, all correctness fixes.
  • Loading branch information
SingleAccretion committed May 2, 2022
1 parent 0c6af71 commit d1d5aea
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4319,9 +4319,6 @@ ValueNum ValueNumStore::VNForLoadStoreBitCast(ValueNum value, var_types indType,
if ((typeOfValue == TYP_STRUCT) || (indType == TYP_STRUCT))
{
value = VNForBitCast(value, indType);
JITDUMP(" VNForLoadStoreBitcast returns ");
JITDUMPEXEC(m_pComp->vnPrint(value, 1));
JITDUMP("\n");
}
else
{
Expand All @@ -4333,14 +4330,20 @@ ValueNum ValueNumStore::VNForLoadStoreBitCast(ValueNum value, var_types indType,
JITDUMP(" *** Mismatched types in VNForLoadStoreBitcast (indType is SIMD)\n");
value = VNForExpr(m_pComp->compCurBB, indType);
}
else if (!varTypeIsFloating(typeOfValue) && !varTypeIsFloating(indType))
{
// TODO-PhysicalVN: implement constant folding for bitcasts and remove this special case.
value = VNForCast(value, indType, TypeOfVN(value));
}
else
{
// We are trying to read "value" of type "typeOfValue" using "indType" read.
// Insert a cast - this handles small types, i. e. "IND(byte ADDR(int))".
// TODO-Bug: this does not not handle "IND(float ADDR(int))" correctly.
value = VNForCast(value, indType, typeOfValue);
value = VNForBitCast(value, indType);
}
}

JITDUMP(" VNForLoadStoreBitcast returns ");
JITDUMPEXEC(m_pComp->vnPrint(value, 1));
JITDUMP("\n");
}

assert(genActualType(TypeOfVN(value)) == genActualType(indType));
Expand Down Expand Up @@ -9658,15 +9661,18 @@ ValueNum ValueNumStore::VNForBitCast(ValueNum srcVN, var_types castToType)
srcVN = srcVNFunc.m_args[0];
}

if (TypeOfVN(srcVN) == castToType)
var_types srcType = TypeOfVN(srcVN);

if (srcType == castToType)
{
return srcVN;
}

assert((castToType != TYP_STRUCT) || (TypeOfVN(srcVN) != TYP_STRUCT));
assert((castToType != TYP_STRUCT) || (srcType != TYP_STRUCT));

// TODO-CQ: implement constant folding for BitCast.
if (srcVNFunc.m_func == VNF_ZeroObj)
// TODO-PhysicalVN: implement proper constant folding for BitCast.
if ((srcVNFunc.m_func == VNF_ZeroObj) ||
((castToType != TYP_STRUCT) && (srcType != TYP_STRUCT) && (srcVN == VNZeroForType(srcType))))
{
return VNZeroForType(castToType);
}
Expand Down

0 comments on commit d1d5aea

Please sign in to comment.