Skip to content

Commit d1d5aea

Browse files
Fix the CAST<float <-> integer> bug
10 diffs across CLR and libraries tests, all correctness fixes.
1 parent 0c6af71 commit d1d5aea

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/coreclr/jit/valuenum.cpp

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4319,9 +4319,6 @@ ValueNum ValueNumStore::VNForLoadStoreBitCast(ValueNum value, var_types indType,
43194319
if ((typeOfValue == TYP_STRUCT) || (indType == TYP_STRUCT))
43204320
{
43214321
value = VNForBitCast(value, indType);
4322-
JITDUMP(" VNForLoadStoreBitcast returns ");
4323-
JITDUMPEXEC(m_pComp->vnPrint(value, 1));
4324-
JITDUMP("\n");
43254322
}
43264323
else
43274324
{
@@ -4333,14 +4330,20 @@ ValueNum ValueNumStore::VNForLoadStoreBitCast(ValueNum value, var_types indType,
43334330
JITDUMP(" *** Mismatched types in VNForLoadStoreBitcast (indType is SIMD)\n");
43344331
value = VNForExpr(m_pComp->compCurBB, indType);
43354332
}
4333+
else if (!varTypeIsFloating(typeOfValue) && !varTypeIsFloating(indType))
4334+
{
4335+
// TODO-PhysicalVN: implement constant folding for bitcasts and remove this special case.
4336+
value = VNForCast(value, indType, TypeOfVN(value));
4337+
}
43364338
else
43374339
{
4338-
// We are trying to read "value" of type "typeOfValue" using "indType" read.
4339-
// Insert a cast - this handles small types, i. e. "IND(byte ADDR(int))".
4340-
// TODO-Bug: this does not not handle "IND(float ADDR(int))" correctly.
4341-
value = VNForCast(value, indType, typeOfValue);
4340+
value = VNForBitCast(value, indType);
43424341
}
43434342
}
4343+
4344+
JITDUMP(" VNForLoadStoreBitcast returns ");
4345+
JITDUMPEXEC(m_pComp->vnPrint(value, 1));
4346+
JITDUMP("\n");
43444347
}
43454348

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

9661-
if (TypeOfVN(srcVN) == castToType)
9664+
var_types srcType = TypeOfVN(srcVN);
9665+
9666+
if (srcType == castToType)
96629667
{
96639668
return srcVN;
96649669
}
96659670

9666-
assert((castToType != TYP_STRUCT) || (TypeOfVN(srcVN) != TYP_STRUCT));
9671+
assert((castToType != TYP_STRUCT) || (srcType != TYP_STRUCT));
96679672

9668-
// TODO-CQ: implement constant folding for BitCast.
9669-
if (srcVNFunc.m_func == VNF_ZeroObj)
9673+
// TODO-PhysicalVN: implement proper constant folding for BitCast.
9674+
if ((srcVNFunc.m_func == VNF_ZeroObj) ||
9675+
((castToType != TYP_STRUCT) && (srcType != TYP_STRUCT) && (srcVN == VNZeroForType(srcType))))
96709676
{
96719677
return VNZeroForType(castToType);
96729678
}

0 commit comments

Comments
 (0)