Skip to content

Commit 6f7c6fb

Browse files
authored
JIT: Fix cross crossgen comparison failures (#112078)
Fix a couple of issues that were causing cross-crossgen tests to fail * address mode formation was sensitive to the size of a constant handle * value histogram processing was always using 64 bit value sizes * transformation for down-counted loops was using host-sized -1. Fixes the jit-related issues in #111972
1 parent 05d94d9 commit 6f7c6fb

File tree

4 files changed

+43
-21
lines changed

4 files changed

+43
-21
lines changed

src/coreclr/jit/codegencommon.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,15 +1195,9 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,
11951195

11961196
/* Check for an addition of a constant */
11971197

1198-
if (op2->IsIntCnsFitsInI32() && (op2->gtType != TYP_REF) && FitsIn<INT32>(cns + op2->AsIntConCommon()->IconValue()))
1198+
if (op2->IsIntCnsFitsInI32() && op2->AsIntConCommon()->ImmedValCanBeFolded(compiler, addr->OperGet()) &&
1199+
(op2->gtType != TYP_REF) && FitsIn<INT32>(cns + op2->AsIntConCommon()->IconValue()))
11991200
{
1200-
// We should not be building address modes out of non-foldable constants
1201-
if (!op2->AsIntConCommon()->ImmedValCanBeFolded(compiler, addr->OperGet()))
1202-
{
1203-
assert(compiler->opts.compReloc);
1204-
return false;
1205-
}
1206-
12071201
/* We're adding a constant */
12081202

12091203
cns += op2->AsIntConCommon()->IconValue();

src/coreclr/jit/likelyclass.cpp

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ struct LikelyClassMethodHistogramEntry
3838
//
3939
struct LikelyClassMethodHistogram
4040
{
41-
LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount);
41+
LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount, bool int32Data = false);
42+
43+
template <typename ElemType>
44+
void LikelyClassMethodHistogramInner(ElemType* histogramEntries, unsigned entryCount);
4245

4346
// Sum of counts from all entries in the histogram. This includes "unknown" entries which are not captured in
4447
// m_histogram
@@ -61,8 +64,22 @@ struct LikelyClassMethodHistogram
6164
// Arguments:
6265
// histogramEntries - pointer to the table portion of a ClassProfile* object (see corjit.h)
6366
// entryCount - number of entries in the table to examine
67+
// int32Data - true if table entries are 32 bits
6468
//
65-
LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount)
69+
LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount, bool int32Data)
70+
{
71+
if (int32Data)
72+
{
73+
LikelyClassMethodHistogramInner<int>((int*)histogramEntries, entryCount);
74+
}
75+
else
76+
{
77+
LikelyClassMethodHistogramInner<INT_PTR>(histogramEntries, entryCount);
78+
}
79+
}
80+
81+
template <typename ElemType>
82+
void LikelyClassMethodHistogram::LikelyClassMethodHistogramInner(ElemType* histogramEntries, unsigned entryCount)
6683
{
6784
m_unknownHandles = 0;
6885
m_totalCount = 0;
@@ -76,8 +93,7 @@ LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries
7693
}
7794

7895
m_totalCount++;
79-
80-
INT_PTR currentEntry = histogramEntries[k];
96+
INT_PTR currentEntry = (INT_PTR)histogramEntries[k];
8197

8298
bool found = false;
8399
unsigned h = 0;
@@ -385,15 +401,18 @@ extern "C" DLLEXPORT UINT32 WINAPI getLikelyValues(LikelyValueRecord*
385401
continue;
386402

387403
// We currently re-use existing infrastructure for type handles for simplicity.
388-
389-
const bool isHistogramCount =
390-
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramIntCount) ||
404+
//
405+
const bool isIntHistogramCount =
406+
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramIntCount);
407+
const bool isLongHistogramCount =
391408
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramLongCount);
409+
const bool isHistogramCount = isIntHistogramCount || isLongHistogramCount;
392410

393411
if (isHistogramCount && (schema[i].Count == 1) && ((i + 1) < countSchemaItems) &&
394412
(schema[i + 1].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogram))
395413
{
396-
LikelyClassMethodHistogram h((INT_PTR*)(pInstrumentationData + schema[i + 1].Offset), schema[i + 1].Count);
414+
LikelyClassMethodHistogram h((INT_PTR*)(pInstrumentationData + schema[i + 1].Offset), schema[i + 1].Count,
415+
isIntHistogramCount);
397416
LikelyClassMethodHistogramEntry sortedEntries[HISTOGRAM_MAX_SIZE_COUNT];
398417

399418
if (h.countHistogramElements == 0)

src/coreclr/jit/scev.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,19 @@
6060

6161
#include "jitpch.h"
6262

63+
ScevConstant::ScevConstant(var_types type, int64_t value)
64+
: Scev(ScevOper::Constant, type)
65+
{
66+
if (genTypeSize(type) == 4)
67+
{
68+
Value = (int32_t)value;
69+
}
70+
else
71+
{
72+
Value = value;
73+
}
74+
}
75+
6376
//------------------------------------------------------------------------
6477
// GetConstantValue: If this SSA use refers to a constant, then fetch that
6578
// constant.

src/coreclr/jit/scev.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ struct Scev
8282

8383
struct ScevConstant : Scev
8484
{
85-
ScevConstant(var_types type, int64_t value)
86-
: Scev(ScevOper::Constant, type)
87-
, Value(value)
88-
{
89-
}
85+
ScevConstant(var_types type, int64_t value);
9086

9187
int64_t Value;
9288
};

0 commit comments

Comments
 (0)