Skip to content

Commit

Permalink
JIT: Fix cross crossgen comparison failures (#112078)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AndyAyersMS authored Feb 3, 2025
1 parent 05d94d9 commit 6f7c6fb
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 21 deletions.
10 changes: 2 additions & 8 deletions src/coreclr/jit/codegencommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1195,15 +1195,9 @@ bool CodeGen::genCreateAddrMode(GenTree* addr,

/* Check for an addition of a constant */

if (op2->IsIntCnsFitsInI32() && (op2->gtType != TYP_REF) && FitsIn<INT32>(cns + op2->AsIntConCommon()->IconValue()))
if (op2->IsIntCnsFitsInI32() && op2->AsIntConCommon()->ImmedValCanBeFolded(compiler, addr->OperGet()) &&
(op2->gtType != TYP_REF) && FitsIn<INT32>(cns + op2->AsIntConCommon()->IconValue()))
{
// We should not be building address modes out of non-foldable constants
if (!op2->AsIntConCommon()->ImmedValCanBeFolded(compiler, addr->OperGet()))
{
assert(compiler->opts.compReloc);
return false;
}

/* We're adding a constant */

cns += op2->AsIntConCommon()->IconValue();
Expand Down
35 changes: 27 additions & 8 deletions src/coreclr/jit/likelyclass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ struct LikelyClassMethodHistogramEntry
//
struct LikelyClassMethodHistogram
{
LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount);
LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount, bool int32Data = false);

template <typename ElemType>
void LikelyClassMethodHistogramInner(ElemType* histogramEntries, unsigned entryCount);

// Sum of counts from all entries in the histogram. This includes "unknown" entries which are not captured in
// m_histogram
Expand All @@ -61,8 +64,22 @@ struct LikelyClassMethodHistogram
// Arguments:
// histogramEntries - pointer to the table portion of a ClassProfile* object (see corjit.h)
// entryCount - number of entries in the table to examine
// int32Data - true if table entries are 32 bits
//
LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount)
LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries, unsigned entryCount, bool int32Data)
{
if (int32Data)
{
LikelyClassMethodHistogramInner<int>((int*)histogramEntries, entryCount);
}
else
{
LikelyClassMethodHistogramInner<INT_PTR>(histogramEntries, entryCount);
}
}

template <typename ElemType>
void LikelyClassMethodHistogram::LikelyClassMethodHistogramInner(ElemType* histogramEntries, unsigned entryCount)
{
m_unknownHandles = 0;
m_totalCount = 0;
Expand All @@ -76,8 +93,7 @@ LikelyClassMethodHistogram::LikelyClassMethodHistogram(INT_PTR* histogramEntries
}

m_totalCount++;

INT_PTR currentEntry = histogramEntries[k];
INT_PTR currentEntry = (INT_PTR)histogramEntries[k];

bool found = false;
unsigned h = 0;
Expand Down Expand Up @@ -385,15 +401,18 @@ extern "C" DLLEXPORT UINT32 WINAPI getLikelyValues(LikelyValueRecord*
continue;

// We currently re-use existing infrastructure for type handles for simplicity.

const bool isHistogramCount =
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramIntCount) ||
//
const bool isIntHistogramCount =
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramIntCount);
const bool isLongHistogramCount =
(schema[i].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogramLongCount);
const bool isHistogramCount = isIntHistogramCount || isLongHistogramCount;

if (isHistogramCount && (schema[i].Count == 1) && ((i + 1) < countSchemaItems) &&
(schema[i + 1].InstrumentationKind == ICorJitInfo::PgoInstrumentationKind::ValueHistogram))
{
LikelyClassMethodHistogram h((INT_PTR*)(pInstrumentationData + schema[i + 1].Offset), schema[i + 1].Count);
LikelyClassMethodHistogram h((INT_PTR*)(pInstrumentationData + schema[i + 1].Offset), schema[i + 1].Count,
isIntHistogramCount);
LikelyClassMethodHistogramEntry sortedEntries[HISTOGRAM_MAX_SIZE_COUNT];

if (h.countHistogramElements == 0)
Expand Down
13 changes: 13 additions & 0 deletions src/coreclr/jit/scev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@

#include "jitpch.h"

ScevConstant::ScevConstant(var_types type, int64_t value)
: Scev(ScevOper::Constant, type)
{
if (genTypeSize(type) == 4)
{
Value = (int32_t)value;
}
else
{
Value = value;
}
}

//------------------------------------------------------------------------
// GetConstantValue: If this SSA use refers to a constant, then fetch that
// constant.
Expand Down
6 changes: 1 addition & 5 deletions src/coreclr/jit/scev.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,7 @@ struct Scev

struct ScevConstant : Scev
{
ScevConstant(var_types type, int64_t value)
: Scev(ScevOper::Constant, type)
, Value(value)
{
}
ScevConstant(var_types type, int64_t value);

int64_t Value;
};
Expand Down

0 comments on commit 6f7c6fb

Please sign in to comment.